Skip to content

Commit

Permalink
Changing default log level to information
Browse files Browse the repository at this point in the history
  • Loading branch information
emgarten committed Jul 31, 2016
1 parent 7858aea commit 31c9594
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 30 deletions.
49 changes: 32 additions & 17 deletions src/Sleet/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@ public class ConsoleLogger : ILogger
{
private static readonly Object _lockObj = new object();

public LogLevel VerbosityLevel { get; set; }

public ConsoleLogger()
: this(LogLevel.Debug)
{
}

public ConsoleLogger(LogLevel level)
{
VerbosityLevel = level;
}

public void LogDebug(string data)
{
Log(data);
Log(LogLevel.Debug, data);
}

public void LogError(string data)
{
Log(data, ConsoleColor.Red);
Log(LogLevel.Error, data, ConsoleColor.Red);
}

public void LogErrorSummary(string data)
Expand All @@ -24,50 +36,53 @@ public void LogErrorSummary(string data)

public void LogInformation(string data)
{
Log(data);
Log(LogLevel.Information, data);
}

public void LogInformationSummary(string data)
{
Log(data);
Log(LogLevel.Information, data);
}

public void LogMinimal(string data)
{
Log(data);
Log(LogLevel.Minimal, data);
}

public void LogSummary(string data)
{
Log(data);
Log(LogLevel.Information, data);
}

public void LogVerbose(string data)
{
Log(data);
Log(LogLevel.Verbose, data);
}

public void LogWarning(string data)
{
Log(data, ConsoleColor.Yellow);
Log(LogLevel.Warning, data, ConsoleColor.Yellow);
}

private void Log(string message)
private void Log(LogLevel level, string message)
{
Log(message, color: null);
Log(level, message, color: null);
}

private void Log(string message, ConsoleColor? color)
private void Log(LogLevel level, string message, ConsoleColor? color)
{
lock (_lockObj)
if ((int)level >= (int)VerbosityLevel)
{
if (color.HasValue)
lock (_lockObj)
{
Console.ForegroundColor = color.Value;
}
if (color.HasValue)
{
Console.ForegroundColor = color.Value;
}

Console.WriteLine(message);
Console.ResetColor();
Console.WriteLine(message);
Console.ResetColor();
}
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/Sleet/FileSystem/AzureBlobLease.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public async Task<bool> GetLease()
{
actualLease = await _blob.AcquireLeaseAsync(_leaseTime, _leaseId);
}
catch
catch (Exception ex)
{
// ignore
Debug.Fail($"GetLease failed: {ex}");
}

return StringComparer.Ordinal.Equals(_leaseId, actualLease);
Expand All @@ -52,10 +52,11 @@ public async Task Renew()
{
await _blob.RenewLeaseAsync(AccessCondition.GenerateLeaseCondition(_leaseId));
}
catch
catch (Exception ex)
{
// attempt to get the lease again
await GetLease();
Debug.Fail($"Renew failed: {ex}");
}
}

Expand All @@ -68,12 +69,12 @@ public void Release()
{
try
{
_blob.ReleaseLeaseAsync(AccessCondition.GenerateLeaseCondition(_leaseId)).RunSynchronously();
_blob.ReleaseLeaseAsync(AccessCondition.GenerateLeaseCondition(_leaseId)).Wait(TimeSpan.FromSeconds(60));
}
catch
catch (Exception ex)
{
// ignore the lease error, it will expire in time.
Debug.Fail("Lease dispose failed");
// Ignore
Debug.Fail($"Release failed: {ex}");
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/Sleet/FileSystem/AzureFileSystemLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,21 @@ private async Task KeepLock()

await Task.Delay(TimeSpan.FromSeconds(30), _cts.Token);
}
catch
catch (TaskCanceledException)
{
// Ignore exceptions, continue the inner loop
Debug.Fail("KeepLock failed");
// Ignore
}
catch (Exception ex)
{
// Ignore
Debug.Fail($"KeepLock failed: {ex}");
}
}
}
catch
catch (Exception ex)
{
// Ignore
Debug.Fail("KeepLock failed");
Debug.Fail($"KeepLock failed: {ex}");
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/Sleet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ public class Program
{
public static int Main(string[] args)
{
var log = new ConsoleLogger();
var logLevel = LogLevel.Information;

if (Environment.GetEnvironmentVariable("SLEET_DEBUG") == "1")
{
logLevel = LogLevel.Debug;
}

var log = new ConsoleLogger(logLevel);

var task = MainCore(args, log);
return task.Result;
Expand Down

0 comments on commit 31c9594

Please sign in to comment.