Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (GH-1131) logging: better defaults for ERROR
  (GH-1131) logging: better defaults for WARN
  (GH-1131) logging: better defaults for INFO
  (GH-1665) sign init.ps1 file
  (doc) More info on license next steps
  (GH-1503) Warn on incorrectly named license file
  (GH-1292) add note on manifest caching
  • Loading branch information
ferventcoder committed Dec 16, 2018
2 parents ea4b155 + b0f1424 commit 8daccd4
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 8 deletions.
1 change: 0 additions & 1 deletion .build.custom/codeSign.step
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ Set-AuthenticodeSignature -Filepath @("C:\ProgramData\chocolatey\helpers\chocola
<in>
<items>
<!--exclude name="${dirs.drop.nuget}/chocolatey/tools/chocolateyInstall.ps1" /-->
<exclude name="${dirs.drop.nuget}/chocolatey/tools/init.ps1" />
<include name="${dirs.drop.nuget}/**/*.ps1" />
<include name="${dirs.drop.nuget}/**/*.psm1" />
</items>
Expand Down
7 changes: 7 additions & 0 deletions src/chocolatey.console/choco.exe.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
The following is an unsupported use case: If you want to utilize File
and Registry Virtualization for backward compatibility then delete
the requestedExecutionLevel node.
NOTE: If you do change this file, make sure that you change the
modification date on choco.exe that this sits next to. Windows
caches manifests based on path and last modified date. So you'll
need to change the modification date on choco.exe for the manifest
change to take effect.
Details: https://github.com/chocolatey/choco/issues/1292#issuecomment-304068121
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
Expand Down
12 changes: 10 additions & 2 deletions src/chocolatey/infrastructure/licensing/License.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace chocolatey.infrastructure.licensing
using adapters;
using app;
using information;
using logging;
using registration;
using Environment = System.Environment;

Expand All @@ -45,12 +46,19 @@ public static ChocolateyLicense validate_license()
@"Error when attempting to load chocolatey licensed assembly. Ensure
that chocolatey.licensed.dll exists at
'{0}'.
Install with `choco install chocolatey.extension`.
The error message itself may be helpful as well:{1} {2}".format_with(
The error message itself may be helpful:{1} {2}".format_with(
ApplicationParameters.LicensedAssemblyLocation,
Environment.NewLine,
ex.Message
));
"chocolatey".Log().Warn(ChocolateyLoggers.Important,@" Install the Chocolatey Licensed Extension package with
`choco install chocolatey.extension` to remove this license warning.
TRIALS: If you have a trial license, you cannot use the above command
as is and be successful. You need to download nupkgs from the links in
the trial email as your license will not be registered on the licensed
repository. Please reference
https://chocolatey.org/docs/installation-licensed#how-do-i-install-the-trial-edition
for specific instructions.");
}
}

Expand Down
31 changes: 30 additions & 1 deletion src/chocolatey/infrastructure/licensing/LicenseValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace chocolatey.infrastructure.licensing
using System;
using System.IO;
using app;
using logging;
using Rhino.Licensing;

public sealed class LicenseValidation
Expand All @@ -37,7 +38,35 @@ public static ChocolateyLicense validate()
var userLicenseFile = ApplicationParameters.UserLicenseFileLocation;
if (File.Exists(userLicenseFile)) licenseFile = userLicenseFile;

//no IFileSystem at this point
// no IFileSystem at this point
if (!File.Exists(licenseFile))
{
var licenseFileName = Path.GetFileName(ApplicationParameters.LicenseFileLocation);
var licenseDirectory = Path.GetDirectoryName(ApplicationParameters.LicenseFileLocation);

// look for misnamed files and locations
// - look in the license directory for misnamed files
if (Directory.Exists(licenseDirectory))
{
if (Directory.GetFiles(licenseDirectory).Length != 0)
{
"chocolatey".Log().Error(@"Files found in directory '{0}' but not a
valid license file. License should be named '{1}'.".format_with(licenseDirectory, licenseFileName));
"chocolatey".Log().Warn(ChocolateyLoggers.Important,@" Rename license file to '{0}' to allow commercial features.".format_with(licenseFileName));
}
}


// - user put the license file in the top level location and/or forgot to rename it
if (File.Exists(Path.Combine(ApplicationParameters.InstallLocation, licenseFileName)) || File.Exists(Path.Combine(ApplicationParameters.InstallLocation, licenseFileName + ".txt")))
{
"chocolatey".Log().Error(@"Chocolatey license found in the wrong location. File must be located at
'{0}'.".format_with(ApplicationParameters.LicenseFileLocation));
"chocolatey".Log().Warn(ChocolateyLoggers.Important, @" Move license file to '{0}' to allow commercial features.".format_with(ApplicationParameters.LicenseFileLocation));
}
}

// no IFileSystem at this point
if (File.Exists(licenseFile))
{
"chocolatey".Log().Debug("Evaluating license file found at '{0}'".format_with(licenseFile));
Expand Down
125 changes: 125 additions & 0 deletions src/chocolatey/infrastructure/logging/Log4NetAppenderConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

namespace chocolatey.infrastructure.logging
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using adapters;
Expand All @@ -30,13 +32,27 @@ namespace chocolatey.infrastructure.logging
using log4net.Repository;
using log4net.Repository.Hierarchy;
using platforms;
using Console = adapters.Console;

public sealed class Log4NetAppenderConfiguration
{
private static readonly log4net.ILog _logger = LogManager.GetLogger(typeof(Log4NetAppenderConfiguration));
private static Lazy<IConsole> _console = new Lazy<IConsole>(() => new Console());
[EditorBrowsable(EditorBrowsableState.Never)]
public static void initialize_with(Lazy<IConsole> console)
{
_console = console;
}

private static IConsole Console
{
get { return _console.Value; }
}

private static bool _alreadyConfiguredFileAppender;
private static readonly string _summaryLogAppenderName = "{0}.summary.log.appender".format_with(ApplicationParameters.Name);
private const string NORMAL_LOGGING_COLORED_APPENDER = "NormalLoggingColoredConsoleAppender";
private const string IMPORTANT_LOGGING_COLORED_APPENDER = "ImportantLoggingColoredConsoleAppender";

/// <summary>
/// Pulls xml configuration from embedded location and applies it.
Expand Down Expand Up @@ -69,13 +85,122 @@ public static void configure(string outputDirectory = null, params string[] excl

_logger.DebugFormat("Configured Log4Net configuration ('{0}') from assembly {1}", resource, assembly.FullName);
}

configure_info_logging_colors();

if (!string.IsNullOrWhiteSpace(outputDirectory))
{
set_file_appender(outputDirectory, excludeLoggerNames);
}
}

private static void configure_info_logging_colors()
{
try
{
// configure INFO on same as current background color and foreground colors
var bgColor = Console.BackgroundColor;
var fgColor = Console.ForegroundColor;
ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetCallingAssembly().UnderlyingType);
foreach (var append in logRepository.GetAppenders().Where(a => a.Name.is_equal_to(NORMAL_LOGGING_COLORED_APPENDER)).or_empty_list_if_null())
{
var appender = append as ManagedColoredConsoleAppender;
if (appender != null)
{
var infoMapping = new ManagedColoredConsoleAppender.LevelColors
{
Level = Level.Info,
BackColor = bgColor,
ForeColor = fgColor,
};
appender.AddMapping(infoMapping);

// make sure warnings can be clearly seen
if (bgColor == ConsoleColor.White
|| bgColor == ConsoleColor.Gray
|| bgColor == ConsoleColor.Yellow
|| bgColor == ConsoleColor.DarkYellow
|| bgColor == ConsoleColor.DarkCyan
)
{
var warnMapping = new ManagedColoredConsoleAppender.LevelColors
{
Level = Level.Warn,
BackColor = ConsoleColor.Black,
ForeColor = ConsoleColor.Yellow,
};
appender.AddMapping(warnMapping);
}

// make sure errors can be clearly seen
if (bgColor == ConsoleColor.Red
|| bgColor == ConsoleColor.DarkRed
|| bgColor == ConsoleColor.Yellow
|| bgColor == ConsoleColor.DarkYellow
|| bgColor == ConsoleColor.DarkCyan
|| bgColor == ConsoleColor.DarkGray
|| bgColor == ConsoleColor.DarkGreen
|| bgColor == ConsoleColor.Blue
)
{
var errorMapping = new ManagedColoredConsoleAppender.LevelColors
{
Level = Level.Error,
BackColor = ConsoleColor.Black,
ForeColor = ConsoleColor.Red,
};
appender.AddMapping(errorMapping);
}

appender.ActivateOptions();
}
}

foreach (var append in logRepository.GetAppenders().Where(a => a.Name.is_equal_to(IMPORTANT_LOGGING_COLORED_APPENDER)).or_empty_list_if_null())
{
var appender = append as ManagedColoredConsoleAppender;
if (appender != null)
{
// add black based on current background color
if (bgColor == ConsoleColor.White
|| bgColor == ConsoleColor.Gray
|| bgColor == ConsoleColor.Yellow
|| bgColor == ConsoleColor.DarkYellow
|| bgColor == ConsoleColor.DarkCyan
|| bgColor == ConsoleColor.DarkGray
|| bgColor == ConsoleColor.DarkGreen
|| bgColor == ConsoleColor.Green
|| bgColor == ConsoleColor.Cyan
|| bgColor == ConsoleColor.Magenta
)
{
var infoMapping = new ManagedColoredConsoleAppender.LevelColors
{
Level = Level.Info,
BackColor = ConsoleColor.Black,
ForeColor = ConsoleColor.Green,
};
appender.AddMapping(infoMapping);

var warnMapping = new ManagedColoredConsoleAppender.LevelColors
{
Level = Level.Warn,
BackColor = ConsoleColor.Black,
ForeColor = ConsoleColor.Magenta,
};
appender.AddMapping(warnMapping);

appender.ActivateOptions();
}
}
}
}
catch (Exception)
{
// ignore this and move on
}
}

/// <summary>
/// Adds a file appender to all current loggers. Only runs one time.
/// </summary>
Expand Down
4 changes: 0 additions & 4 deletions src/chocolatey/infrastructure/logging/log4net.config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
<mapping>
<level value="ERROR" />
<foreColor value="Red" />
<backColor value="Black" />
</mapping>
<mapping>
<level value="WARN" />
<foreColor value="Yellow" />
<backColor value="Black" />
</mapping>
<mapping>
<level value="INFO" />
Expand Down Expand Up @@ -52,12 +50,10 @@
<mapping>
<level value="WARN" />
<foreColor value="Magenta" />
<backColor value="Black" />
</mapping>
<mapping>
<level value="INFO" />
<foreColor value="Green" />
<backColor value="Black" />
</mapping>
<mapping>
<level value="DEBUG" />
Expand Down

0 comments on commit 8daccd4

Please sign in to comment.