Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (GH-603) Get-FileName should set proxy if required
  (GH-611) Fix - Verbose shows up on Debug
  (GH-8) Always set Debug/Verbose for host
  • Loading branch information
ferventcoder committed Feb 4, 2016
2 parents 5ff288a + 6dffaff commit 41741e2
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 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
41 changes: 41 additions & 0 deletions src/chocolatey.resources/helpers/functions/Get-FileName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,47 @@ param(
return $originalFileName
}

$defaultCreds = [System.Net.CredentialCache]::DefaultCredentials
if ($defaultCreds -ne $null) {
$request.Credentials = $defaultCreds
}

$client = New-Object System.Net.WebClient
if ($defaultCreds -ne $null) {
$client.Credentials = $defaultCreds
}

# check if a proxy is required
$explicitProxy = $env:chocolateyProxyLocation
$explicitProxyUser = $env:chocolateyProxyUser
$explicitProxyPassword = $env:chocolateyProxyPassword
if ($explicitProxy -ne $null) {
# explicit proxy
$proxy = New-Object System.Net.WebProxy($explicitProxy, $true)
if ($explicitProxyPassword -ne $null) {
$passwd = ConvertTo-SecureString $explicitProxyPassword -AsPlainText -Force
$proxy.Credentials = New-Object System.Management.Automation.PSCredential ($explicitProxyUser, $passwd)
}

Write-Debug "Using explicit proxy server '$explicitProxy'."
$request.Proxy = $proxy

} elseif (!$client.Proxy.IsBypassed($url))
{
# system proxy (pass through)
$creds = [Net.CredentialCache]::DefaultCredentials
if ($creds -eq $null) {
Write-Debug "Default credentials were null. Attempting backup method"
$cred = Get-Credential
$creds = $cred.GetNetworkCredential();
}
$proxyAddress = $client.Proxy.GetProxy($url).Authority
Write-Debug "Using system proxy server '$proxyaddress'."
$proxy = New-Object System.Net.WebProxy($proxyAddress)
$proxy.Credentials = $creds
$request.Proxy = $proxy
}

$request.Method = "GET"
$request.Accept = '*/*'
$request.AllowAutoRedirect = $true
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 @@ -407,11 +407,15 @@ private void remove_assembly_resolver()

private PowerShellExecutionResults run_host(ChocolateyConfiguration config, string chocoPowerShellScript)
{
// since we control output in the host, always set these true
Environment.SetEnvironmentVariable("ChocolateyEnvironmentDebug", "true");
Environment.SetEnvironmentVariable("ChocolateyEnvironmentVerbose", "true");

var result = new PowerShellExecutionResults();
string commandToRun = wrap_script_with_module(chocoPowerShellScript, config);
var host = new PoshHost(config);
this.Log().Debug(() => "Calling built-in PowerShell host with ['{0}']".format_with(commandToRun.escape_curly_braces()));

var initialSessionState = InitialSessionState.CreateDefault();
// override system execution policy without accidentally setting it
initialSessionState.AuthorizationManager = new AuthorizationManager("choco");
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 41741e2

Please sign in to comment.