Skip to content

Commit 738dbf5

Browse files
committed
sonar refactor
1 parent f093633 commit 738dbf5

File tree

3 files changed

+48
-28
lines changed

3 files changed

+48
-28
lines changed

libraries/src/AWS.Lambda.Powertools.Logging/Internal/Buffer/PowertoolsBufferingLogger.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ namespace AWS.Lambda.Powertools.Logging.Internal;
2424
/// </summary>
2525
internal class PowertoolsBufferingLogger : ILogger
2626
{
27-
private readonly ILogger _innerLogger;
27+
private readonly ILogger _logger;
2828
private readonly Func<PowertoolsLoggerConfiguration> _getCurrentConfig;
2929
private readonly LogBuffer _buffer;
3030

3131
public PowertoolsBufferingLogger(
32-
ILogger innerLogger,
32+
ILogger logger,
3333
Func<PowertoolsLoggerConfiguration> getCurrentConfig,
3434
IPowertoolsConfigurations powertoolsConfigurations)
3535
{
36-
_innerLogger = innerLogger;
36+
_logger = logger;
3737
_getCurrentConfig = getCurrentConfig;
3838
_buffer = new LogBuffer(powertoolsConfigurations);
3939
}
4040

4141
public IDisposable BeginScope<TState>(TState state)
4242
{
43-
return _innerLogger.BeginScope(state);
43+
return _logger.BeginScope(state);
4444
}
4545

4646
public bool IsEnabled(LogLevel logLevel)
@@ -66,7 +66,7 @@ public void Log<TState>(
6666
// Add to buffer instead of logging
6767
try
6868
{
69-
if (_innerLogger is PowertoolsLogger powertoolsLogger)
69+
if (_logger is PowertoolsLogger powertoolsLogger)
7070
{
7171
var logEntry = powertoolsLogger.LogEntryString(logLevel, state, exception, formatter);
7272

@@ -89,7 +89,7 @@ public void Log<TState>(
8989
// If buffering fails, try to log an error about it
9090
try
9191
{
92-
_innerLogger.LogError(ex, "Failed to buffer log entry");
92+
_logger.LogError(ex, "Failed to buffer log entry");
9393
}
9494
catch
9595
{
@@ -115,7 +115,7 @@ public void FlushBuffer()
115115
{
116116
try
117117
{
118-
if (_innerLogger is PowertoolsLogger powertoolsLogger)
118+
if (_logger is PowertoolsLogger powertoolsLogger)
119119
{
120120
if (_buffer.HasEvictions)
121121
{
@@ -137,7 +137,7 @@ public void FlushBuffer()
137137
// If the entire flush operation fails, try to log an error
138138
try
139139
{
140-
_innerLogger.LogError(ex, "Failed to flush log buffer");
140+
_logger.LogError(ex, "Failed to flush log buffer");
141141
}
142142
catch
143143
{

libraries/src/AWS.Lambda.Powertools.Logging/Internal/PowertoolsLogger.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,10 @@ private Dictionary<string, object> GetLogEntry(LogLevel logLevel, DateTime times
238238
{
239239
foreach (var (key, value) in structuredParameters)
240240
{
241-
if (!string.IsNullOrWhiteSpace(key) && key != "json")
241+
if (string.IsNullOrWhiteSpace(key) || key == "json") continue;
242+
if (!IsLogConstantKey(key))
242243
{
243-
if (!IsLogConstantKey(key))
244-
{
245-
logEntry.TryAdd(key, value);
246-
}
244+
logEntry.TryAdd(key, value);
247245
}
248246
}
249247
}
@@ -551,15 +549,15 @@ private Dictionary<string, object> ExtractStructuredParameters<TState>(TState st
551549
var statePropsArray = stateProps.ToArray();
552550

553551
// First pass - extract message template and identify format specifiers
554-
ExtractFormatSpecifiers<TState>(ref messageTemplate, statePropsArray, formatSpecifiers);
552+
ExtractFormatSpecifiers(ref messageTemplate, statePropsArray, formatSpecifiers);
555553

556554
// Second pass - process values with extracted format specifiers
557-
ProcessValuesWithSpecifiers<TState>(statePropsArray, formatSpecifiers, parameters);
555+
ProcessValuesWithSpecifiers(statePropsArray, formatSpecifiers, parameters);
558556

559557
return parameters;
560558
}
561559

562-
private void ProcessValuesWithSpecifiers<TState>(KeyValuePair<string, object>[] statePropsArray, Dictionary<string, string> formatSpecifiers,
560+
private void ProcessValuesWithSpecifiers(KeyValuePair<string, object>[] statePropsArray, Dictionary<string, string> formatSpecifiers,
563561
Dictionary<string, object> parameters)
564562
{
565563
foreach (var prop in statePropsArray)
@@ -618,7 +616,7 @@ private void ProcessValuesWithSpecifiers<TState>(KeyValuePair<string, object>[]
618616
}
619617
}
620618

621-
private static void ExtractFormatSpecifiers<TState>(ref string messageTemplate, KeyValuePair<string, object>[] statePropsArray,
619+
private static void ExtractFormatSpecifiers(ref string messageTemplate, KeyValuePair<string, object>[] statePropsArray,
622620
Dictionary<string, string> formatSpecifiers)
623621
{
624622
foreach (var prop in statePropsArray)

libraries/tests/e2e/infra-aot/CoreAotStack.cs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@
66

77
namespace InfraAot;
88

9+
public class ConstructArgs
10+
{
11+
public ConstructArgs(Construct scope, string id, Runtime runtime, Architecture architecture, string name, string sourcePath, string distPath, string handler)
12+
{
13+
Scope = scope;
14+
Id = id;
15+
Runtime = runtime;
16+
Architecture = architecture;
17+
Name = name;
18+
SourcePath = sourcePath;
19+
DistPath = distPath;
20+
Handler = handler;
21+
}
22+
23+
public Construct Scope { get; private set; }
24+
public string Id { get; private set; }
25+
public Runtime Runtime { get; private set; }
26+
public Architecture Architecture { get; private set; }
27+
public string Name { get; private set; }
28+
public string SourcePath { get; private set; }
29+
public string DistPath { get; private set; }
30+
public string Handler { get; private set; }
31+
}
32+
933
public class CoreAotStack : Stack
1034
{
1135
private readonly Architecture _architecture;
@@ -26,21 +50,19 @@ private void CreateFunctionConstructs(string utility, string function = "AOT-Fun
2650
var distAotPath = $"../functions/core/{utility}/{function}/dist/{function}";
2751
var arch = _architecture == Architecture.X86_64 ? "X64" : "ARM";
2852

29-
CreateFunctionConstruct(this, $"{utility}_{arch}_aot_net8_{function}", Runtime.DOTNET_8, _architecture,
30-
$"E2ETestLambda_{arch}_AOT_NET8_{utility}_{function}", baseAotPath, distAotPath, function);
53+
CreateFunctionConstruct(new ConstructArgs(this, $"{utility}_{arch}_aot_net8_{function}", Runtime.DOTNET_8, _architecture, $"E2ETestLambda_{arch}_AOT_NET8_{utility}_{function}", baseAotPath, distAotPath, function));
3154
}
3255

33-
private void CreateFunctionConstruct(Construct scope, string id, Runtime runtime, Architecture architecture,
34-
string name, string sourcePath, string distPath, string handler)
56+
private void CreateFunctionConstruct(ConstructArgs constructArgs)
3557
{
36-
_ = new FunctionConstruct(scope, id, new FunctionConstructProps
58+
_ = new FunctionConstruct(constructArgs.Scope, constructArgs.Id, new FunctionConstructProps
3759
{
38-
Runtime = runtime,
39-
Architecture = architecture,
40-
Name = name,
41-
Handler = handler,
42-
SourcePath = sourcePath,
43-
DistPath = distPath,
60+
Runtime = constructArgs.Runtime,
61+
Architecture = constructArgs.Architecture,
62+
Name = constructArgs.Name,
63+
Handler = constructArgs.Handler,
64+
SourcePath = constructArgs.SourcePath,
65+
DistPath = constructArgs.DistPath,
4466
IsAot = true
4567
});
4668
}

0 commit comments

Comments
 (0)