Skip to content

Commit be9bcdc

Browse files
committed
Remove LogTo method, ILog and Debug logging
1 parent 45c746a commit be9bcdc

File tree

8 files changed

+9
-137
lines changed

8 files changed

+9
-137
lines changed

libraries/src/AWS.Lambda.Powertools.Idempotency/AWS.Lambda.Powertools.Idempotency.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@
4343
<None Include="../../AWSLogo128x128.png" Pack="true" Visible="false" PackagePath="" />
4444
</ItemGroup>
4545

46+
<ItemGroup>
47+
<Folder Include="Output\" />
48+
</ItemGroup>
49+
4650
</Project>

libraries/src/AWS.Lambda.Powertools.Idempotency/IdempotencyOptions.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
using AWS.Lambda.Powertools.Idempotency.Output;
17-
1816
namespace AWS.Lambda.Powertools.Idempotency;
1917

2018
/// <summary>
@@ -59,11 +57,6 @@ public class IdempotencyOptions
5957
/// as supported by <see cref="System.Security.Cryptography.HashAlgorithm"/> (eg. SHA1, SHA-256, ...)
6058
/// </summary>
6159
public string HashFunction { get; }
62-
63-
/// <summary>
64-
/// Instance of ILog to record internal details of idempotency
65-
/// </summary>
66-
public ILog Log { get; }
6760

6861
internal IdempotencyOptions(
6962
string eventKeyJmesPath,
@@ -72,8 +65,7 @@ internal IdempotencyOptions(
7265
bool useLocalCache,
7366
int localCacheMaxItems,
7467
long expirationInSeconds,
75-
string hashFunction,
76-
ILog log)
68+
string hashFunction)
7769
{
7870
EventKeyJmesPath = eventKeyJmesPath;
7971
PayloadValidationJmesPath = payloadValidationJmesPath;
@@ -82,6 +74,5 @@ internal IdempotencyOptions(
8274
LocalCacheMaxItems = localCacheMaxItems;
8375
ExpirationInSeconds = expirationInSeconds;
8476
HashFunction = hashFunction;
85-
Log = log;
8677
}
8778
}

libraries/src/AWS.Lambda.Powertools.Idempotency/IdempotencyOptionsBuilder.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using AWS.Lambda.Powertools.Idempotency.Output;
32

43
namespace AWS.Lambda.Powertools.Idempotency;
54

@@ -15,7 +14,6 @@ public class IdempotencyOptionsBuilder
1514
private string _payloadValidationJmesPath;
1615
private bool _throwOnNoIdempotencyKey;
1716
private string _hashFunction = "MD5";
18-
private ILog _log = new NullLog();
1917

2018
/// <summary>
2119
/// Initialize and return an instance of IdempotencyConfig.
@@ -32,8 +30,7 @@ public IdempotencyOptions Build() =>
3230
_useLocalCache,
3331
_localCacheMaxItems,
3432
_expirationInSeconds,
35-
_hashFunction,
36-
_log);
33+
_hashFunction);
3734

3835
/// <summary>
3936
/// A JMESPath expression to extract the idempotency key from the event record.
@@ -103,15 +100,4 @@ public IdempotencyOptionsBuilder WithHashFunction(string hashFunction)
103100
_hashFunction = hashFunction;
104101
return this;
105102
}
106-
107-
/// <summary>
108-
/// Logs to a custom logger.
109-
/// </summary>
110-
/// <param name="log">The logger.</param>
111-
/// <returns>the instance of the builder (to chain operations)</returns>
112-
public IdempotencyOptionsBuilder LogTo(ILog log)
113-
{
114-
_log = log;
115-
return this;
116-
}
117103
}

libraries/src/AWS.Lambda.Powertools.Idempotency/Internal/IdempotencyAspectHandler.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using System.Text.Json;
1818
using System.Threading.Tasks;
1919
using AWS.Lambda.Powertools.Idempotency.Exceptions;
20-
using AWS.Lambda.Powertools.Idempotency.Output;
2120
using AWS.Lambda.Powertools.Idempotency.Persistence;
2221

2322
namespace AWS.Lambda.Powertools.Idempotency.Internal;
@@ -29,7 +28,6 @@ internal class IdempotencyAspectHandler<T>
2928
private readonly Func<Task<T>> _target;
3029
private readonly JsonDocument _data;
3130
private readonly BasePersistenceStore _persistenceStore;
32-
private readonly ILog _log;
3331

3432
public IdempotencyAspectHandler(
3533
Func<Task<T>> target,
@@ -40,7 +38,6 @@ public IdempotencyAspectHandler(
4038
_data = payload;
4139
_persistenceStore = Idempotency.Instance.PersistenceStore;
4240
_persistenceStore.Configure(Idempotency.Instance.IdempotencyOptions, functionName);
43-
_log = Idempotency.Instance.IdempotencyOptions.Log;
4441
}
4542

4643
/// <summary>
@@ -117,7 +114,7 @@ private Task<DataRecord> GetIdempotencyRecord()
117114
catch (IdempotencyItemNotFoundException e)
118115
{
119116
// This code path will only be triggered if the record is removed between saveInProgress and getRecord
120-
_log.WriteDebug("An existing idempotency record was deleted before we could fetch it");
117+
Console.WriteLine("An existing idempotency record was deleted before we could fetch it");
121118
throw new IdempotencyInconsistentStateException("saveInProgress and getRecord return inconsistent results",
122119
e);
123120
}
@@ -159,7 +156,6 @@ private Task<T> HandleForStatus(DataRecord record)
159156
default:
160157
try
161158
{
162-
_log.WriteDebug("Response for key '{0}' retrieved from idempotency store, skipping the function", record.IdempotencyKey);
163159
var result = JsonSerializer.Deserialize<T>(record.ResponseData!);
164160
if (result is null)
165161
{

libraries/src/AWS.Lambda.Powertools.Idempotency/Output/ILog.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.

libraries/src/AWS.Lambda.Powertools.Idempotency/Output/NullLog.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

libraries/src/AWS.Lambda.Powertools.Idempotency/Persistence/BasePersistenceStore.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using AWS.Lambda.Powertools.Common;
2222
using AWS.Lambda.Powertools.Idempotency.Exceptions;
2323
using AWS.Lambda.Powertools.Idempotency.Internal;
24-
using AWS.Lambda.Powertools.Idempotency.Output;
2524
using AWS.Lambda.Powertools.Idempotency.Serialization;
2625
using DevLab.JmesPath;
2726

@@ -41,10 +40,6 @@ public abstract class BasePersistenceStore : IPersistenceStore
4140
/// </summary>
4241
protected bool PayloadValidationEnabled;
4342
private LRUCache<string, DataRecord> _cache = null!;
44-
/// <summary>
45-
/// Instance of ILog to log the internal details of idempotency
46-
/// </summary>
47-
protected ILog Log = null!;
4843

4944
/// <summary>
5045
/// Initialize the base persistence layer from the configuration settings
@@ -60,7 +55,6 @@ public void Configure(IdempotencyOptions idempotencyOptions, string functionName
6055
_functionName += "." + functionName;
6156
}
6257
_idempotencyOptions = idempotencyOptions;
63-
Log = _idempotencyOptions.Log;
6458

6559
//TODO: optimize to not reconfigure
6660
if (!string.IsNullOrWhiteSpace(_idempotencyOptions.PayloadValidationJmesPath))
@@ -100,7 +94,6 @@ public virtual async Task SaveSuccess(JsonDocument data, object result, DateTime
10094
responseJson,
10195
GetHashedPayload(data)
10296
);
103-
Log.WriteDebug("Function successfully executed. Saving record to persistence store with idempotency key: {0}", record.IdempotencyKey);
10497
await UpdateRecord(record);
10598
SaveToCache(record);
10699
}
@@ -127,7 +120,6 @@ public virtual async Task SaveInProgress(JsonDocument data, DateTimeOffset now)
127120
null,
128121
GetHashedPayload(data)
129122
);
130-
Log.WriteDebug("saving in progress record for idempotency key: {0}", record.IdempotencyKey);
131123
await PutRecord(record, now);
132124
}
133125

@@ -140,7 +132,7 @@ public virtual async Task DeleteRecord(JsonDocument data, Exception throwable)
140132
{
141133
var idemPotencyKey = GetHashedIdempotencyKey(data);
142134

143-
Log.WriteDebug("Function raised an exception {0}. " +
135+
Console.WriteLine("Function raised an exception {0}. " +
144136
"Clearing in progress record in persistence store for idempotency key: {1}",
145137
throwable.GetType().Name,
146138
idemPotencyKey);
@@ -162,7 +154,6 @@ public virtual async Task<DataRecord> GetRecord(JsonDocument data, DateTimeOffse
162154
var cachedRecord = RetrieveFromCache(idempotencyKey, now);
163155
if (cachedRecord != null)
164156
{
165-
Log.WriteDebug("Idempotency record found in cache with idempotency key: {0}", idempotencyKey);
166157
ValidatePayload(data, cachedRecord);
167158
return cachedRecord;
168159
}
@@ -217,7 +208,6 @@ private DataRecord RetrieveFromCache(string idempotencyKey, DateTimeOffset now)
217208
{
218209
return record;
219210
}
220-
Log.WriteDebug("Removing expired local cache record for idempotency key: {0}", idempotencyKey);
221211
DeleteFromCache(idempotencyKey);
222212
}
223213
return null;
@@ -285,7 +275,7 @@ private string GetHashedIdempotencyKey(JsonDocument data)
285275
{
286276
throw new IdempotencyKeyException("No data found to create a hashed idempotency key");
287277
}
288-
Log.WriteWarning("No data found to create a hashed idempotency key. JMESPath: {0}", _idempotencyOptions.EventKeyJmesPath ?? string.Empty);
278+
Console.WriteLine("No data found to create a hashed idempotency key. JMESPath: {0}", _idempotencyOptions.EventKeyJmesPath ?? string.Empty);
289279
}
290280

291281
var hash = GenerateHash(node);

libraries/src/AWS.Lambda.Powertools.Idempotency/Persistence/DynamoDBPersistenceStore.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ public override async Task PutRecord(DataRecord record, DateTimeOffset now)
123123

124124
try
125125
{
126-
Log.WriteDebug("Putting record for idempotency key: {0}", record.IdempotencyKey);
127-
128126
var expressionAttributeNames = new Dictionary<string, string>
129127
{
130128
{"#id", _keyAttr},
@@ -146,7 +144,6 @@ public override async Task PutRecord(DataRecord record, DateTimeOffset now)
146144
}
147145
catch (ConditionalCheckFailedException e)
148146
{
149-
Log.WriteDebug("Failed to put record for already existing idempotency key: {0}", record.IdempotencyKey);
150147
throw new IdempotencyItemAlreadyExistsException(
151148
"Failed to put record for already existing idempotency key: " + record.IdempotencyKey, e);
152149
}
@@ -156,7 +153,6 @@ public override async Task PutRecord(DataRecord record, DateTimeOffset now)
156153
/// <inheritdoc />
157154
public override async Task UpdateRecord(DataRecord record)
158155
{
159-
Log.WriteDebug("Updating record for idempotency key: {0}", record.IdempotencyKey);
160156
var updateExpression = "SET #response_data = :response_data, #expiry = :expiry, #status = :status";
161157

162158
var expressionAttributeNames = new Dictionary<string, string>
@@ -194,7 +190,6 @@ public override async Task UpdateRecord(DataRecord record)
194190
/// <inheritdoc />
195191
public override async Task DeleteRecord(string idempotencyKey)
196192
{
197-
Log.WriteDebug("Deleting record for idempotency key: {0}", idempotencyKey);
198193
var request = new DeleteItemRequest
199194
{
200195
TableName = _tableName,

0 commit comments

Comments
 (0)