Skip to content

Commit

Permalink
Merge branch 'karpikpl-master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
normj committed Feb 21, 2019
2 parents 6e51d45 + fd64a79 commit 23059f8
Show file tree
Hide file tree
Showing 7 changed files with 414 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Description>Amazon Lambda .NET Core support - Logging ASP.NET Core package.</Description>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyTitle>Amazon.Lambda.Logging.AspNetCore</AssemblyTitle>
<VersionPrefix>2.1.0</VersionPrefix>
<VersionPrefix>2.2.0</VersionPrefix>
<AssemblyName>Amazon.Lambda.Logging.AspNetCore</AssemblyName>
<PackageId>Amazon.Lambda.Logging.AspNetCore</PackageId>
<PackageTags>AWS;Amazon;Lambda;Logging</PackageTags>
Expand Down
14 changes: 11 additions & 3 deletions Libraries/src/Amazon.Lambda.Logging.AspNetCore/LambdaILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
}

// Format of the logged text, optional components are in {}
// {[LogLevel] }{Category: }MessageText{\n}
// {[LogLevel] }{Category: }{EventId: }MessageText {Exception}{\n}

var components = new List<string>(4);
if (_options.IncludeLogLevel)
Expand All @@ -56,11 +56,19 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
{
components.Add($"{_categoryName}:");
}
if (_options.IncludeEventId)
{
components.Add($"{eventId}:");
}

var text = formatter.Invoke(state, exception);
var text = formatter.Invoke(state, exception);
components.Add(text);

if (_options.IncludeNewline)
if(_options.IncludeException)
{
components.Add($"{exception}");
}
if (_options.IncludeNewline)
{
components.Add(Environment.NewLine);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class LambdaLoggerOptions
private const string INCLUDE_LOG_LEVEL_KEY = "IncludeLogLevel";
private const string INCLUDE_CATEGORY_KEY = "IncludeCategory";
private const string INCLUDE_NEWLINE_KEY = "IncludeNewline";
private const string INCLUDE_EXCEPTION_KEY = "IncludeException";
private const string INCLUDE_EVENT_ID_KEY = "IncludeEventId";
private const string LOG_LEVEL_KEY = "LogLevel";

/// <summary>
Expand All @@ -37,6 +39,18 @@ public class LambdaLoggerOptions
/// Default is true.
/// </summary>
public bool IncludeNewline { get; set; }

/// <summary>
/// Flag to indicate if Exception should be part of logged message.
/// Default is false.
/// </summary>
public bool IncludeException { get; set; }

/// <summary>
/// Flag to indicate if EventId should be part of logged message.
/// Default is false.
/// </summary>
public bool IncludeEventId { get; set; }

/// <summary>
/// Function used to filter events based on the log level.
Expand All @@ -54,6 +68,8 @@ public LambdaLoggerOptions()
IncludeCategory = true;
IncludeLogLevel = true;
IncludeNewline = true;
IncludeException = false;
IncludeEventId = false;
Filter = null;
}

Expand Down Expand Up @@ -102,26 +118,32 @@ public LambdaLoggerOptions(IConfiguration configuration, string loggingSectionNa

// Parse settings

string includeCategoryString;
if (TryGetString(loggerConfiguration, INCLUDE_CATEGORY_KEY, out includeCategoryString))
if (TryGetString(loggerConfiguration, INCLUDE_CATEGORY_KEY, out string includeCategoryString))
{
IncludeCategory = bool.Parse(includeCategoryString);
}

string includeLogLevelString;
if (TryGetString(loggerConfiguration, INCLUDE_LOG_LEVEL_KEY, out includeLogLevelString))
if (TryGetString(loggerConfiguration, INCLUDE_LOG_LEVEL_KEY, out string includeLogLevelString))
{
IncludeLogLevel = bool.Parse(includeLogLevelString);
}

if (TryGetString(loggerConfiguration, INCLUDE_EXCEPTION_KEY, out string includeExceptionString))
{
IncludeException = bool.Parse(includeExceptionString);
}

if (TryGetString(loggerConfiguration, INCLUDE_EVENT_ID_KEY, out string includeEventIdString))
{
IncludeEventId = bool.Parse(includeEventIdString);
}

string includeNewlineString;
if (TryGetString(loggerConfiguration, INCLUDE_NEWLINE_KEY, out includeNewlineString))
if (TryGetString(loggerConfiguration, INCLUDE_NEWLINE_KEY, out string includeNewlineString))
{
IncludeNewline = bool.Parse(includeNewlineString);
}

IConfiguration logLevelsSection;
if (TryGetSection(loggerConfiguration, LOG_LEVEL_KEY, out logLevelsSection))
if (TryGetSection(loggerConfiguration, LOG_LEVEL_KEY, out IConfiguration logLevelsSection))
{
Filter = CreateFilter(logLevelsSection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
</PropertyGroup>

<ItemGroup>
<None Update="appsettings.exceptions.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="appsettings.wildcard.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down

0 comments on commit 23059f8

Please sign in to comment.