-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
088360b
commit 97cb23f
Showing
16 changed files
with
251 additions
and
551 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 0 additions & 60 deletions
60
src/main/java/io/github/brenoepics/at4j/util/logging/FallbackLoggerConfiguration.java
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
src/main/java/io/github/brenoepics/at4j/util/logging/Log4jPropertySource.java
This file was deleted.
Oops, something went wrong.
96 changes: 23 additions & 73 deletions
96
src/main/java/io/github/brenoepics/at4j/util/logging/LoggerUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,31 @@ | ||
package io.github.brenoepics.at4j.util.logging; | ||
|
||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.simple.SimpleLogger; | ||
import org.apache.logging.log4j.util.PropertiesUtil; | ||
import org.apache.logging.log4j.util.ProviderUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** This class is used to get a {@link Logger} instance. */ | ||
public class LoggerUtil { | ||
LoggerUtil() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
private static final AtomicReference<Boolean> initialized = new AtomicReference<>(false); | ||
private static final AtomicBoolean noLogger = new AtomicBoolean(); | ||
private static final Map<String, Logger> loggers = new ConcurrentHashMap<>(); | ||
|
||
/** | ||
* Get or create a logger with the given name. | ||
* | ||
* @param name The name of the logger. | ||
* @return The logger with the given name. | ||
*/ | ||
public static Logger getLogger(String name) { | ||
AtomicBoolean logWarning = new AtomicBoolean(false); | ||
initialized.updateAndGet( | ||
initialized -> { | ||
if (Boolean.TRUE.equals(!initialized) && !ProviderUtil.hasProviders()) { | ||
noLogger.set(true); | ||
logWarning.set(true); | ||
} | ||
return true; | ||
}); | ||
LoggerUtil() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
if (noLogger.get()) { | ||
return loggers.computeIfAbsent( | ||
name, | ||
key -> { | ||
Level debugLevel = | ||
FallbackLoggerConfiguration.isDebugEnabled() ? Level.DEBUG : Level.INFO; | ||
Level level = FallbackLoggerConfiguration.isTraceEnabled() ? Level.TRACE : debugLevel; | ||
Logger logger = | ||
new SimpleLogger( | ||
name, | ||
level, | ||
true, | ||
false, | ||
true, | ||
true, | ||
"yyyy-MM-dd HH:mm:ss.SSSZ", | ||
null, | ||
new PropertiesUtil(new Properties()), | ||
System.out); | ||
if (logWarning.get()) { | ||
logger.info( | ||
"No Log4j2 compatible logger was found. Using default AT4J implementation!"); | ||
} | ||
return new PrivacyProtectionLogger(logger); | ||
}); | ||
} else { | ||
return new PrivacyProtectionLogger(LogManager.getLogger(name)); | ||
/** | ||
* Get or create a logger with the given name. | ||
* | ||
* @param name The name of the logger. | ||
* @return The logger with the given name. | ||
*/ | ||
public static Logger getLogger(String name) { | ||
return LoggerFactory.getLogger(name); | ||
} | ||
} | ||
|
||
/** | ||
* Gets or creates a logger for the given name. | ||
* | ||
* @param clazz The class of the logger. | ||
* @return A logger for the given class. | ||
*/ | ||
public static Logger getLogger(Class<?> clazz) { | ||
return getLogger(clazz.getName()); | ||
} | ||
} | ||
/** | ||
* Gets or creates a logger for the given class. | ||
* | ||
* @param clazz The class of the logger. | ||
* @return A logger for the given class. | ||
*/ | ||
public static Logger getLogger(Class<?> clazz) { | ||
return LoggerFactory.getLogger(clazz); | ||
} | ||
} |
Oops, something went wrong.