Skip to content

Commit

Permalink
(chocolateyGH-611) Fix - Verbose shows up on Debug
Browse files Browse the repository at this point in the history
Verbose output should only be shown in output when a user uses the
verbose switch. The naive implementation of the debug filter was
clearing the filter levels for Verbose. Exclude the verbose logger from
the filter clear.
  • Loading branch information
ferventcoder committed Feb 4, 2016
1 parent ff48645 commit 08909a6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/chocolatey.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace chocolatey.console
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using infrastructure.adapters;
Expand Down Expand Up @@ -131,8 +132,8 @@ that chocolatey.licensed.dll exists at
Environment.Exit(-1);
}

Log4NetAppenderConfiguration.set_verbose_logger_when_verbose(config.Verbose, "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Verbose.to_string()));
Log4NetAppenderConfiguration.set_logging_level_debug_when_debug(config.Debug);
Log4NetAppenderConfiguration.set_logging_level_debug_when_debug(config.Debug, excludeLoggerName: "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Verbose.to_string()));
Log4NetAppenderConfiguration.set_verbose_logger_when_verbose(config.Verbose, config.Debug, "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Verbose.to_string()));
"chocolatey".Log().Debug(() => "{0} is running on {1} v {2}".format_with(ApplicationParameters.Name, config.Information.PlatformType, config.Information.PlatformVersion.to_string()));
//"chocolatey".Log().Debug(() => "Command Line: {0}".format_with(Environment.CommandLine));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void run(string[] args, ChocolateyConfiguration config, Container contain
// if debug is bundled with local options, it may not get picked up when global
// options are parsed. Attempt to set it again once local options are set.
// This does mean some output from debug will be missed (but not much)
if (config.Debug) Log4NetAppenderConfiguration.set_logging_level_debug_when_debug(config.Debug);
if (config.Debug) Log4NetAppenderConfiguration.set_logging_level_debug_when_debug(config.Debug, excludeLoggerName: "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Verbose.to_string()));

command.handle_additional_argument_parsing(unparsedArgs, config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace chocolatey.infrastructure.logging
{
using System.IO;
using System.Linq;
using adapters;
using app;
using log4net;
Expand Down Expand Up @@ -108,7 +109,8 @@ private static void set_file_appender(string outputDirectory)
/// <param name="enableDebug">
/// if set to <c>true</c> [enable debug].
/// </param>
public static void set_logging_level_debug_when_debug(bool enableDebug)
/// <param name="excludeLoggerName">Logger, such as a verbose logger, to exclude from this.</param>
public static void set_logging_level_debug_when_debug(bool enableDebug, string excludeLoggerName)
{
if (enableDebug)
{
Expand All @@ -121,8 +123,9 @@ public static void set_logging_level_debug_when_debug(bool enableDebug)
{
logger.Level = Level.Debug;
}
}
foreach (var append in logRepository.GetAppenders())
}

foreach (var append in logRepository.GetAppenders().Where(a => !a.Name.is_equal_to(excludeLoggerName.to_string())).or_empty_list_if_null())
{
var appender = append as AppenderSkeleton;
if (appender != null)
Expand All @@ -140,8 +143,9 @@ public static void set_logging_level_debug_when_debug(bool enableDebug)
/// <param name="enableVerbose">
/// if set to <c>true</c> [enable verbose].
/// </param>
/// <param name="enableDebug">If debug is also enabled</param>
/// <param name="verboseLoggerName">Name of the verbose logger.</param>
public static void set_verbose_logger_when_verbose(bool enableVerbose, string verboseLoggerName)
public static void set_verbose_logger_when_verbose(bool enableVerbose,bool enableDebug, string verboseLoggerName)
{
if (enableVerbose)
{
Expand All @@ -153,7 +157,8 @@ public static void set_verbose_logger_when_verbose(bool enableVerbose, string ve
if (appender != null && appender.Name.is_equal_to(verboseLoggerName))
{
appender.ClearFilters();
appender.AddFilter( new log4net.Filter.LevelRangeFilter {LevelMin = Level.Info, LevelMax = Level.Fatal});
var minLevel = enableDebug ? Level.Debug : Level.Info;
appender.AddFilter(new log4net.Filter.LevelRangeFilter { LevelMin = minLevel, LevelMax = Level.Fatal });
}
}

Expand Down

0 comments on commit 08909a6

Please sign in to comment.