1 package org
.argeo
.init
.logging
;
3 import java
.lang
.System
.Logger
;
4 import java
.lang
.System
.LoggerFinder
;
5 import java
.util
.HashMap
;
7 import java
.util
.Objects
;
10 * Factory for Java system logging. As it has to be a public class in order to
11 * be exposed as a service provider, it is also the main entry point for the
12 * thin logging system, via static methos.
14 public class ThinLoggerFinder
extends LoggerFinder
{
15 private static ThinLogging logging
;
16 private static ThinJavaUtilLogging javaUtilLogging
;
18 public ThinLoggerFinder() {
20 throw new IllegalStateException("Only one logging can be initialised.");
25 public Logger
getLogger(String name
, Module module
) {
26 return logging
.getLogger(name
, module
);
29 private static void init() {
30 logging
= new ThinLogging();
32 Map
<String
, String
> configuration
= new HashMap
<>();
33 for (Object key
: System
.getProperties().keySet()) {
34 Objects
.requireNonNull(key
);
35 String property
= key
.toString();
36 if (property
.startsWith(ThinLogging
.LEVEL_PROPERTY_PREFIX
)
37 || property
.equals(ThinLogging
.DEFAULT_LEVEL_PROPERTY
))
38 configuration
.put(property
, System
.getProperty(property
));
40 logging
.update(configuration
);
44 * Falls back to java.util.logging if thin logging was not already initialised.
46 public static void lazyInit() {
49 if (javaUtilLogging
!= null)
52 javaUtilLogging
= ThinJavaUtilLogging
.init();
53 javaUtilLogging
.readConfiguration(logging
.getLevels());
56 public static void update(Map
<String
, String
> configuration
) {
58 throw new IllegalStateException("Thin logging must be initialized first");
59 logging
.update(configuration
);
60 if (javaUtilLogging
!= null)
61 javaUtilLogging
.readConfiguration(logging
.getLevels());
64 static Logger
getLogger(String name
) {
65 return logging
.getLogger(name
, null);