1 package org
.argeo
.init
.logging
;
3 import java
.io
.Serializable
;
4 import java
.lang
.System
.Logger
;
5 import java
.lang
.System
.LoggerFinder
;
6 import java
.util
.HashMap
;
8 import java
.util
.Objects
;
9 import java
.util
.concurrent
.Flow
;
10 import java
.util
.function
.Consumer
;
13 * Factory for Java system logging. As it has to be a public class in order to
14 * be exposed as a service provider, it is also the main entry point for the
15 * thin logging system, via static methos.
17 public class ThinLoggerFinder
extends LoggerFinder
{
18 private static ThinLogging logging
;
19 private static ThinJavaUtilLogging javaUtilLogging
;
21 public ThinLoggerFinder() {
23 throw new IllegalStateException("Only one logging can be initialised.");
28 public Logger
getLogger(String name
, Module module
) {
29 return logging
.getLogger(name
, module
);
32 private static void init() {
33 logging
= new ThinLogging();
35 Map
<String
, Object
> configuration
= new HashMap
<>();
36 for (Object key
: System
.getProperties().keySet()) {
37 Objects
.requireNonNull(key
);
38 String property
= key
.toString();
39 if (property
.startsWith(ThinLogging
.LEVEL_PROPERTY_PREFIX
)
40 || property
.equals(ThinLogging
.DEFAULT_LEVEL_PROPERTY
))
41 configuration
.put(property
, System
.getProperty(property
));
43 logging
.accept(configuration
);
47 * Falls back to java.util.logging if thin logging was not already initialised
48 * by the {@link LoggerFinder} mechanism.
50 public static void lazyInit() {
53 if (javaUtilLogging
!= null)
56 javaUtilLogging
= ThinJavaUtilLogging
.init();
57 javaUtilLogging
.readConfiguration(logging
.getLevels());
60 public static Consumer
<Map
<String
, Object
>> getConfigurationConsumer() {
61 Objects
.requireNonNull(logging
);
65 public static Flow
.Publisher
<Map
<String
, Serializable
>> getLogEntryPublisher() {
66 Objects
.requireNonNull(logging
);
67 return logging
.getLogEntryPublisher();
70 static void update(Map
<String
, Object
> configuration
) {
72 throw new IllegalStateException("Thin logging must be initialized first");
73 logging
.accept(configuration
);
74 if (javaUtilLogging
!= null)
75 javaUtilLogging
.readConfiguration(logging
.getLevels());
78 static Logger
getLogger(String name
) {
79 return logging
.getLogger(name
, null);