Skip to content

Commit

Permalink
(chocolateyGH-1580) Only log when RegularOutput is enabled
Browse files Browse the repository at this point in the history
- This required passing in a ChocolateyConfiguration into service
- All logging is now guarded, and only occurs when RegularOutput is true
  • Loading branch information
gep13 committed Mar 9, 2019
1 parent 7c9e440 commit dbb3629
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ namespace chocolatey.infrastructure.app.services
using System;
using System.IO;
using System.Text;
using configuration;
using NuGet;
using domain;
using infrastructure.configuration;
using tolerance;
using IFileSystem = filesystem.IFileSystem;

Expand All @@ -29,6 +31,7 @@ public class ChocolateyPackageInformationService : IChocolateyPackageInformation
private readonly IFileSystem _fileSystem;
private readonly IRegistryService _registryService;
private readonly IFilesService _filesService;
private readonly ChocolateyConfiguration _config;
private const string REGISTRY_SNAPSHOT_FILE = ".registry";
private const string REGISTRY_SNAPSHOT_BAD_FILE = ".registry.bad";
private const string FILES_SNAPSHOT_FILE = ".files";
Expand All @@ -44,14 +47,23 @@ public ChocolateyPackageInformationService(IFileSystem fileSystem, IRegistryServ
_fileSystem = fileSystem;
_registryService = registryService;
_filesService = filesService;
_config = Config.get_configuration_settings();
}

public ChocolateyPackageInformationService(IFileSystem fileSystem, IRegistryService registryService, IFilesService filesService, ChocolateyConfiguration config)
{
_fileSystem = fileSystem;
_registryService = registryService;
_filesService = filesService;
_config = config;
}

public ChocolateyPackageInformation get_package_information(IPackage package)
{
var packageInformation = new ChocolateyPackageInformation(package);
if (package == null)
{
this.Log().Debug("No package information as package is null.");
if (_config.RegularOutput) { this.Log().Debug("No package information as package is null."); }
return packageInformation;
}

Expand Down Expand Up @@ -79,7 +91,7 @@ focus exclusively in the string values not surrounded by CData. Once
{
if (_fileSystem.file_exists(_fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_BAD_FILE)))
{
this.Log().Warn(deserializationErrorMessage);
if(_config.RegularOutput) { this.Log().Warn(deserializationErrorMessage); }
}
else
{
Expand All @@ -91,7 +103,7 @@ focus exclusively in the string values not surrounded by CData. Once
FaultTolerance.try_catch_with_logging_exception(
() =>
{
this.Log().Warn(deserializationErrorMessage);
if(_config.RegularOutput) { this.Log().Warn(deserializationErrorMessage); }

// rename the bad registry file so that it isn't processed again
_fileSystem.move_file(_fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_FILE), _fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_BAD_FILE));
Expand Down Expand Up @@ -147,7 +159,7 @@ public void save_package_information(ChocolateyPackageInformation packageInforma

if (packageInformation.Package == null)
{
this.Log().Debug("No package information to save as package is null.");
if(_config.RegularOutput) { this.Log().Debug("No package information to save as package is null."); }
return;
}

Expand Down Expand Up @@ -231,6 +243,7 @@ public void save_package_information(ChocolateyPackageInformation packageInforma
public void remove_package_information(IPackage package)
{
var pkgStorePath = _fileSystem.combine_paths(ApplicationParameters.ChocolateyPackageInfoStoreLocation, "{0}.{1}".format_with(package.Id, package.Version.to_string()));
if (_config.RegularOutput) { this.Log().Info("Removing Package Information for {0}".format_with(pkgStorePath)); }
_fileSystem.delete_directory_if_exists(pkgStorePath, recursive: true);
}
}
Expand Down

0 comments on commit dbb3629

Please sign in to comment.