1
1
/*
2
- * Copyright 2022-2023 Vitalij Berdinskih
2
+ * Copyright 2022-2024 Vitalij Berdinskih
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
33
33
import org .slf4j .ILoggerFactory ;
34
34
import org .slf4j .Logger ;
35
35
import org .slf4j .event .Level ;
36
- import org .slf4j .helpers .Util ;
36
+ import org .slf4j .helpers .Reporter ;
37
37
38
38
/**
39
39
* Responsible for building {@link Logger} using the {@link AWSLambdaLogger} implementation.
@@ -126,6 +126,11 @@ public class AWSLambdaLoggerFactory implements ILoggerFactory {
126
126
private final boolean showThreadId ;
127
127
private final boolean showThreadName ;
128
128
129
+ /**
130
+ * AWS Lambda Logger Factory.
131
+ * <p>
132
+ * Looking for a configuration file <em>lambda-logger.properties</em>.
133
+ */
129
134
public AWSLambdaLoggerFactory () {
130
135
this (CONFIGURATION_FILE );
131
136
}
@@ -134,12 +139,11 @@ public AWSLambdaLoggerFactory() {
134
139
AWSLambdaLoggerFactory (String configurationFile ) {
135
140
loggers = new ConcurrentHashMap <>();
136
141
properties = loadProperties (configurationFile );
137
- dateTimeFormat = getDateTimeFormat (AWSLambdaLoggerConfigurationProperty . DateTimeFormat );
142
+ dateTimeFormat = getDateTimeFormat ();
138
143
// logLevelSeparator and markerSeparator should be resolved before defaultLoggerLevel
139
144
logLevelSeparator = getStringProperty (AWSLambdaLoggerConfigurationProperty .LogLevelSeparator );
140
145
markerSeparator = getStringProperty (AWSLambdaLoggerConfigurationProperty .MarkerSeparator );
141
- defaultLoggerLevel = getLoggerLevelProperty (
142
- AWSLambdaLoggerConfigurationProperty .DefaultLogLevel );
146
+ defaultLoggerLevel = getLoggerLevelProperty ();
143
147
levelInBrackets = getBooleanProperty (AWSLambdaLoggerConfigurationProperty .LevelInBrackets );
144
148
requestId = getStringProperty (AWSLambdaLoggerConfigurationProperty .RequestId );
145
149
showDateTime = getBooleanProperty (AWSLambdaLoggerConfigurationProperty .ShowDateTime );
@@ -192,46 +196,47 @@ private boolean getBooleanProperty(AWSLambdaLoggerConfigurationProperty configur
192
196
return Boolean .parseBoolean (getStringProperty (configurationProperty ));
193
197
}
194
198
195
- private DateFormat getDateTimeFormat (AWSLambdaLoggerConfigurationProperty configurationProperty ) {
196
- String dateTimeFormatString = getStringProperty (configurationProperty );
199
+ private DateFormat getDateTimeFormat () {
200
+ var dateTimeFormatString = getStringProperty (
201
+ AWSLambdaLoggerConfigurationProperty .DateTimeFormat );
197
202
198
203
if (nonNull (dateTimeFormatString )) {
199
204
try {
200
205
return new SimpleDateFormat (dateTimeFormatString );
201
206
} catch (IllegalArgumentException exception ) {
202
- Util . report ( "Bad date format in " + CONFIGURATION_FILE + "; will output relative time" ,
203
- exception );
207
+ Reporter . warn (
208
+ "Bad date-time format in " + CONFIGURATION_FILE + "; will output relative time" );
204
209
}
205
210
}
206
211
207
212
return null ;
208
213
}
209
214
210
- private List <AWSLambdaLoggerLevel > getLoggerLevelProperty (
211
- AWSLambdaLoggerConfigurationProperty configurationProperty ) {
212
- String value = System .getenv (configurationProperty .variableName );
215
+ private List <AWSLambdaLoggerLevel > getLoggerLevelProperty () {
216
+ var defaultLogLevelProperty = AWSLambdaLoggerConfigurationProperty . DefaultLogLevel ;
217
+ var value = System .getenv (defaultLogLevelProperty .variableName );
213
218
214
219
if (nonNull (value )) {
215
220
try {
216
221
return parseLoggerLevelString (value );
217
222
} catch (IllegalArgumentException exception ) {
218
- Util .report ("Bad log level in the variable " + configurationProperty .variableName ,
219
- exception );
223
+ Reporter .warn ("Bad log level in the variable " + defaultLogLevelProperty .variableName );
220
224
}
221
225
}
222
226
223
- value = getProperties ().getProperty (configurationProperty .propertyName );
227
+ value = getProperties ().getProperty (defaultLogLevelProperty .propertyName );
224
228
if (nonNull (value )) {
225
229
try {
226
230
return parseLoggerLevelString (value );
227
231
} catch (IllegalArgumentException exception ) {
228
- Util .report ("Bad log level in the property " + configurationProperty .propertyName + " of "
229
- + CONFIGURATION_FILE , exception );
232
+ Reporter .warn (
233
+ "Bad log level in the property " + defaultLogLevelProperty .propertyName + " of "
234
+ + CONFIGURATION_FILE );
230
235
}
231
236
}
232
237
233
238
return List .of (
234
- AWSLambdaLoggerLevel .builder ().level (Level .valueOf (configurationProperty .defaultValue ))
239
+ AWSLambdaLoggerLevel .builder ().level (Level .valueOf (defaultLogLevelProperty .defaultValue ))
235
240
.build ());
236
241
}
237
242
@@ -252,7 +257,7 @@ private List<AWSLambdaLoggerLevel> getLoggerLevels(String loggerName) {
252
257
try {
253
258
loggerLevels = parseLoggerLevelString (loggerLevelString );
254
259
} catch (IllegalArgumentException exception ) {
255
- Util . report ("Bad log level of the logger " + loggerName , exception );
260
+ Reporter . warn ("Bad log level of the logger " + loggerName );
256
261
}
257
262
}
258
263
@@ -304,7 +309,7 @@ private Properties loadProperties(String configurationFile) {
304
309
properties .load (configurationInputStream );
305
310
} catch (IOException | NullPointerException e ) {
306
311
// ignored
307
- Util . report (CONFIGURATION_FILE + " is missed" );
312
+ Reporter . warn (CONFIGURATION_FILE + " is missed" );
308
313
}
309
314
310
315
return properties ;
0 commit comments