17
17
import java .util .function .Predicate ;
18
18
import java .util .stream .Collectors ;
19
19
20
+ import org .apache .logging .log4j .Level ;
21
+ import org .apache .logging .log4j .LogManager ;
22
+ import org .apache .logging .log4j .core .config .Configurator ;
20
23
import org .hl7 .fhir .r4 .model .CapabilityStatement ;
21
24
import org .hl7 .fhir .r4 .model .Enumerations .BindingStrength ;
22
25
import org .slf4j .Logger ;
23
26
import org .slf4j .LoggerFactory ;
27
+ import org .springframework .beans .factory .InitializingBean ;
24
28
import org .springframework .beans .factory .annotation .Value ;
25
29
import org .springframework .context .annotation .Bean ;
26
30
import org .springframework .context .annotation .Configuration ;
64
68
65
69
@ Configuration
66
70
@ PropertySource (ignoreResourceNotFound = true , value = "file:application.properties" )
67
- public class ValidationConfig
71
+ public class ValidationConfig implements InitializingBean
68
72
{
69
73
private static final Logger logger = LoggerFactory .getLogger (ValidationConfig .class );
70
74
@@ -73,9 +77,30 @@ public static enum TerminologyServerConnectionTestStatus
73
77
OK , NOT_OK , DISABLED
74
78
}
75
79
80
+ public static enum LogLevel
81
+ {
82
+ TRACE (Level .TRACE ), DEBUG (Level .DEBUG ), INFO (Level .INFO ), WARN (Level .WARN ), ERROR (Level .ERROR ), FATAL (
83
+ Level .FATAL ), OFF (Level .OFF );
84
+
85
+ private final Level level ;
86
+
87
+ private LogLevel (Level level )
88
+ {
89
+ this .level = level ;
90
+ }
91
+
92
+ public Level level ()
93
+ {
94
+ return level ;
95
+ }
96
+ }
97
+
76
98
@ Value ("${dev.dsf.validation:true}" )
77
99
private boolean validationEnabled ;
78
100
101
+ @ Value ("${dev.dsf.logLevel:INFO}" )
102
+ private LogLevel logLevel ;
103
+
79
104
@ Value ("#{'${dev.dsf.validation.package:}'.trim().split('(,[ ]?)|(\\ n)')}" )
80
105
private List <String > validationPackages ;
81
106
@@ -182,6 +207,15 @@ public static enum TerminologyServerConnectionTestStatus
182
207
@ Value ("${dsf.dev.validation.proxy.password:#{null}}" )
183
208
private char [] proxyPassword ;
184
209
210
+ @ Override
211
+ public void afterPropertiesSet () throws Exception
212
+ {
213
+ Configurator .setLevel (LogManager .getLogger ("dev.dsf" ).getName (), logLevel .level ());
214
+
215
+ if (EnumSet .of (LogLevel .ERROR , LogLevel .WARN , LogLevel .OFF ).contains (logLevel ))
216
+ Configurator .setLevel (LogManager .getRootLogger (), logLevel .level ());
217
+ }
218
+
185
219
@ Bean
186
220
public ObjectMapper objectMapper ()
187
221
{
@@ -286,6 +320,7 @@ private Path cacheFolder(String cacheFolderType, String cacheFolder)
286
320
if (cacheFolderPath .startsWith (systemTempFolder ))
287
321
{
288
322
Files .createDirectories (cacheFolderPath );
323
+
289
324
logger .debug ("Cache folder for type {} created at {}" , cacheFolderType ,
290
325
cacheFolderPath .toAbsolutePath ().toString ());
291
326
}
@@ -327,6 +362,7 @@ private KeyStore trustStore(String trustStoreType, String trustCertificatesFile)
327
362
try
328
363
{
329
364
logger .debug ("Creating trust-store for {} from {}" , trustStoreType , trustCertificatesPath .toString ());
365
+
330
366
List <X509Certificate > certificates = PemReader .readCertificates (trustCertificatesPath );
331
367
return KeyStoreCreator .jksForTrustedCertificates (certificates );
332
368
}
0 commit comments