-
Notifications
You must be signed in to change notification settings - Fork 488
/
Copy pathILambdaLogger.cs
345 lines (311 loc) · 17 KB
/
ILambdaLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
using System;
using System.Runtime.Versioning;
namespace Amazon.Lambda.Core
{
#if NET6_0_OR_GREATER
/// <summary>
/// Log Level for logging messages
/// </summary>
public enum LogLevel
{
/// <summary>
/// Trace level logging
/// </summary>
Trace = 0,
/// <summary>
/// Debug level logging
/// </summary>
Debug = 1,
/// <summary>
/// Information level logging
/// </summary>
Information = 2,
/// <summary>
/// Warning level logging
/// </summary>
Warning = 3,
/// <summary>
/// Error level logging
/// </summary>
Error = 4,
/// <summary>
/// Critical level logging
/// </summary>
Critical = 5
}
#endif
/// <summary>
/// Lambda runtime logger.
/// </summary>
public interface ILambdaLogger
{
/// <summary>
/// Logs a message to AWS CloudWatch Logs.
///
/// Logging will not be done:
/// If the role provided to the function does not have sufficient permissions.
/// </summary>
/// <param name="message"></param>
void Log(string message);
/// <summary>
/// Logs a message, followed by the current line terminator, to AWS CloudWatch Logs.
///
/// Logging will not be done:
/// If the role provided to the function does not have sufficient permissions.
/// </summary>
/// <param name="message"></param>
void LogLine(string message);
#if NET6_0_OR_GREATER
/// <summary>
/// Log message categorized by the given log level
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="level"></param>
/// <param name="message"></param>
void Log(string level, string message) => LogLine(message);
/// <summary>
/// Log message categorized by the given log level
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="level"></param>
/// <param name="message"></param>
void Log(LogLevel level, string message) => Log(level.ToString(), message);
/// <summary>
/// Log trace message
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="message"></param>
void LogTrace(string message) => Log(LogLevel.Trace.ToString(), message);
/// <summary>
/// Log debug message
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="message"></param>
void LogDebug(string message) => Log(LogLevel.Debug.ToString(), message);
/// <summary>
/// Log information message
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="message"></param>
void LogInformation(string message) => Log(LogLevel.Information.ToString(), message);
/// <summary>
/// Log warning message
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="message"></param>
void LogWarning(string message) => Log(LogLevel.Warning.ToString(), message);
/// <summary>
/// Log error message
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="message"></param>
void LogError(string message) => Log(LogLevel.Error.ToString(), message);
/// <summary>
/// Log critical message
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="message"></param>
void LogCritical(string message) => Log(LogLevel.Critical.ToString(), message);
/// <summary>
/// Log message categorized by the given log level
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="level">Log level of the message.</param>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void Log(string level, string message, params object[] args) => Log(level, message, args);
/// <summary>
/// Log message categorized by the given log level
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="level">Log level of the message.</param>
/// <param name="exception">Exception to include with the logging.</param>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void Log(string level, Exception exception, string message, params object[] args)
{
Log(level, message, args);
Log(level, exception.ToString(), args);
}
/// <summary>
/// Log message categorized by the given log level
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="level">Log level of the message.</param>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void Log(LogLevel level, string message, params object[] args) => Log(level.ToString(), message, args);
/// <summary>
/// Log message categorized by the given log level
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="level">Log level of the message.</param>
/// <param name="exception">Exception to include with the logging.</param>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void Log(LogLevel level, Exception exception, string message, params object[] args) => Log(level.ToString(), exception, message, args);
/// <summary>
/// Log trace message.
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void LogTrace(string message, params object[] args) => Log(LogLevel.Trace.ToString(), message, args);
/// <summary>
/// Log trace message.
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="exception">Exception to include with the logging.</param>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void LogTrace(Exception exception, string message, params object[] args) => Log(LogLevel.Trace.ToString(), exception, message, args);
/// <summary>
/// Log debug message.
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void LogDebug(string message, params object[] args) => Log(LogLevel.Debug.ToString(), message, args);
/// <summary>
/// Log debug message.
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="exception">Exception to include with the logging.</param>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void LogDebug(Exception exception, string message, params object[] args) => Log(LogLevel.Debug.ToString(), exception, message, args);
/// <summary>
/// Log information message.
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void LogInformation(string message, params object[] args) => Log(LogLevel.Information.ToString(), message, args);
/// <summary>
/// Log information message.
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="exception">Exception to include with the logging.</param>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void LogInformation(Exception exception, string message, params object[] args) => Log(LogLevel.Information.ToString(), exception, message, args);
/// <summary>
/// Log warning message.
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void LogWarning(string message, params object[] args) => Log(LogLevel.Warning.ToString(), message, args);
/// <summary>
/// Log warning message.
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="exception">Exception to include with the logging.</param>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void LogWarning(Exception exception, string message, params object[] args) => Log(LogLevel.Warning.ToString(), exception, message, args);
/// <summary>
/// Log error message.
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void LogError(string message, params object[] args) => Log(LogLevel.Error.ToString(), message, args);
/// <summary>
/// Log error message.
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="exception">Exception to include with the logging.</param>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void LogError(Exception exception, string message, params object[] args) => Log(LogLevel.Error.ToString(), exception, message, args);
/// <summary>
/// Log critical message.
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void LogCritical(string message, params object[] args) => Log(LogLevel.Critical.ToString(), message, args);
/// <summary>
/// Log critical message.
/// <para>
/// To configure the minimum log level set the AWS_LAMBDA_HANDLER_LOG_LEVEL environment variable. The value should be set
/// to one of the values in the LogLevel enumeration. The default minimum log level is "Information".
/// </para>
/// </summary>
/// <param name="exception">Exception to include with the logging.</param>
/// <param name="message">Message to log.</param>
/// <param name="args">Values to be replaced in log messages that are parameterized.</param>
void LogCritical(Exception exception, string message, params object[] args) => Log(LogLevel.Critical.ToString(), exception, message, args);
#endif
}
}