Skip to content

Commit

Permalink
(GH-1095) Always log Nuget.Core messages
Browse files Browse the repository at this point in the history
Some messages coming from NuGet.Core are error messages, so it is
important to show those messages without having NuGet logging only
coming through during debugging calls. Updating NuGet Core to only log
to Info on important messages and adding both a verbose and fatal level
for NuGet messages helps reduce the amount of output from NuGet.
  • Loading branch information
ferventcoder committed Feb 27, 2017
1 parent 6d6489d commit 4e43c96
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace chocolatey.infrastructure.app.nuget
{
using logging;
using NuGet;

// ReSharper disable InconsistentNaming
Expand All @@ -41,7 +42,13 @@ public void Log(MessageLevel level, string message, params object[] args)
break;
case MessageLevel.Error:
this.Log().Error("[NuGet] " + message, args);
break;
break;
//todo: case MessageLevel.Fatal:
// this.Log().Fatal("[NuGet] " + message, args);
// break;
//case MessageLevel.Verbose:
// this.Log().Info(ChocolateyLoggers.Verbose,"[NuGet] " + message, args);
// break;
}
}
}
Expand Down
42 changes: 15 additions & 27 deletions src/chocolatey/infrastructure.app/nuget/NugetCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,18 @@ public sealed class NugetCommon
{
public static IFileSystem GetNuGetFileSystem(ChocolateyConfiguration configuration, ILogger nugetLogger)
{
var fileSystem = new ChocolateyPhysicalFileSystem(ApplicationParameters.PackagesLocation);
if (configuration.Debug)
{
fileSystem.Logger = nugetLogger;
}

return fileSystem;
return new ChocolateyPhysicalFileSystem(ApplicationParameters.PackagesLocation) { Logger = nugetLogger };
}

public static IPackagePathResolver GetPathResolver(ChocolateyConfiguration configuration, IFileSystem nugetPackagesFileSystem)
{
return new ChocolateyPackagePathResolver(nugetPackagesFileSystem, configuration.AllowMultipleVersions);
}

public static IPackageRepository GetLocalRepository(IPackagePathResolver pathResolver, IFileSystem nugetPackagesFileSystem)
public static IPackageRepository GetLocalRepository(IPackagePathResolver pathResolver, IFileSystem nugetPackagesFileSystem, ILogger nugetLogger)
{
IPackageRepository localRepository = new ChocolateyLocalPackageRepository(pathResolver, nugetPackagesFileSystem);
localRepository.PackageSaveMode = PackageSaveModes.Nupkg | PackageSaveModes.Nuspec;

return localRepository;
return new ChocolateyLocalPackageRepository(pathResolver, nugetPackagesFileSystem)
{ Logger = nugetLogger, PackageSaveMode = PackageSaveModes.Nupkg | PackageSaveModes.Nuspec };
}

public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration configuration, ILogger nugetLogger, IPackageDownloader packageDownloader)
Expand Down Expand Up @@ -126,16 +118,16 @@ public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration con
var uri = new Uri(source);
if (uri.IsFile || uri.IsUnc)
{
repositories.Add(new ChocolateyLocalPackageRepository(uri.LocalPath));
repositories.Add(new ChocolateyLocalPackageRepository(uri.LocalPath){ Logger = nugetLogger });
}
else
{
repositories.Add(new DataServicePackageRepository(new RedirectedHttpClient(uri, bypassProxy), packageDownloader));
repositories.Add(new DataServicePackageRepository(new RedirectedHttpClient(uri, bypassProxy) { UserAgent = "Chocolatey Core" }, packageDownloader) { Logger = nugetLogger });
}
}
catch (Exception)
{
repositories.Add(new ChocolateyLocalPackageRepository(source));
repositories.Add(new ChocolateyLocalPackageRepository(source){ Logger = nugetLogger });
}
}

Expand All @@ -145,30 +137,26 @@ public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration con
}

//todo well that didn't work on failing repos... grrr
var repository = new AggregateRepository(repositories) {IgnoreFailingRepositories = true};
repository.ResolveDependenciesVertically = true;
if (configuration.Debug)
var repository = new AggregateRepository(repositories)
{
repository.Logger = nugetLogger;
}
IgnoreFailingRepositories = true,
Logger = nugetLogger,
ResolveDependenciesVertically = true
};

return repository;
}

public static IPackageManager GetPackageManager(ChocolateyConfiguration configuration, ILogger nugetLogger, IPackageDownloader packageDownloader, Action<PackageOperationEventArgs> installSuccessAction, Action<PackageOperationEventArgs> uninstallSuccessAction, bool addUninstallHandler)
{
IFileSystem nugetPackagesFileSystem = GetNuGetFileSystem(configuration, nugetLogger);
IPackagePathResolver pathResolver = GetPathResolver(configuration, nugetPackagesFileSystem);
var packageManager = new PackageManager(GetRemoteRepository(configuration, nugetLogger, packageDownloader), pathResolver, nugetPackagesFileSystem, GetLocalRepository(pathResolver, nugetPackagesFileSystem))
var packageManager = new PackageManager(GetRemoteRepository(configuration, nugetLogger, packageDownloader), pathResolver, nugetPackagesFileSystem, GetLocalRepository(pathResolver, nugetPackagesFileSystem, nugetLogger))
{
DependencyVersion = DependencyVersion.Highest,
Logger = nugetLogger,
};

if (configuration.Debug)
{
packageManager.Logger = nugetLogger;
}

//NOTE DO NOT EVER use this method - packageManager.PackageInstalling += (s, e) =>
packageManager.PackageInstalled += (s, e) =>
{
Expand Down

0 comments on commit 4e43c96

Please sign in to comment.