Package berlin.yuna.justlog.logger
Class Logger
- java.lang.Object
-
- berlin.yuna.justlog.logger.Logger
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DefaultLogger
public abstract class Logger extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected LoggerConfig
config
protected static ForkJoinPool
executor
protected LogFormatter
formatter
protected LogLevel
level
protected String
name
protected LogWriter
writer
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Logger
add(Logger logger)
Registers a new loggerstatic Logger
add(Logger logger, boolean replace)
Registers a new loggerLogger
config(Map<String,String> config)
adds or updates config values for the logger, formatter and writerLoggerConfigLoader
configLoader()
void
debug(Supplier<String> msg)
void
debug(Supplier<String> msg, Supplier<Throwable> t)
static Logger
defaultLogger()
static Logger
defaultLogger(String name)
boolean
equals(Object o)
void
error(Supplier<String> msg)
void
error(Supplier<String> msg, Supplier<Throwable> t)
void
fatal(Supplier<String> msg)
void
fatal(Supplier<String> msg, Supplier<Throwable> t)
LogFormatter
formatter()
Logger
formatter(LogFormatter formatter)
Sets the message formatterstatic Set<Logger>
getAll()
static StackTraceElement
getCaller()
static StackTraceElement
getCaller(int traceId)
static Executor
getExecutor()
Initialises new Executor if not presentint
hashCode()
void
info(Supplier<String> msg)
void
info(Supplier<String> msg, Supplier<Throwable> t)
Logger
init()
Method invoked on initialisationstatic boolean
isRunning()
LogLevel
level()
Logger
level(LogLevel level)
Sets the log level temporarily untilupdateConfig()
- for permanent updates seeconfig(Map)
void
log(LogLevel level, Supplier<String> msg, Supplier<Throwable> throwable)
String
name()
static boolean
remove(Logger logger)
Removes logger from registryString
toString()
void
trace(Supplier<String> msg)
void
trace(Supplier<String> msg, Supplier<Throwable> t)
Logger
updateConfig()
adds or overwrites config values for the logger, formatter and writervoid
warn(Supplier<String> msg)
void
warn(Supplier<String> msg, Supplier<Throwable> t)
LogWriter
writer()
Logger
writer(LogWriter writer)
Sets the configured message writer
-
-
-
Field Detail
-
writer
protected LogWriter writer
-
formatter
protected LogFormatter formatter
-
level
protected LogLevel level
-
name
protected final String name
-
config
protected final LoggerConfig config
-
executor
protected static ForkJoinPool executor
-
-
Method Detail
-
init
public Logger init()
Method invoked on initialisation- Returns:
- self
-
name
public String name()
- Returns:
- Returns logger name
-
level
public LogLevel level()
- Returns:
- Returns log level
-
level
public Logger level(LogLevel level)
Sets the log level temporarily untilupdateConfig()
- for permanent updates seeconfig(Map)
- Parameters:
level
- new log level- Returns:
- self
-
formatter
public LogFormatter formatter()
- Returns:
- Returns configured message formatter
-
formatter
public Logger formatter(LogFormatter formatter)
Sets the message formatter- Parameters:
formatter
- new formatter- Returns:
- self
-
writer
public LogWriter writer()
- Returns:
- Returns configured message writer
-
writer
public Logger writer(LogWriter writer)
Sets the configured message writer- Parameters:
writer
- new writer- Returns:
- self
-
config
public Logger config(Map<String,String> config)
adds or updates config values for the logger, formatter and writer- Parameters:
config
- new configs- Returns:
- self
-
updateConfig
public Logger updateConfig()
adds or overwrites config values for the logger, formatter and writer- Returns:
- self
-
configLoader
public LoggerConfigLoader configLoader()
- Returns:
- Returns the config loader
-
trace
public void trace(Supplier<String> msg)
- Parameters:
msg
- message which will only be loaded ifLogLevel.TRACE
is active
-
trace
public void trace(Supplier<String> msg, Supplier<Throwable> t)
- Parameters:
msg
- message which will only be loaded ifLogLevel.TRACE
is active
-
debug
public void debug(Supplier<String> msg)
- Parameters:
msg
- message which will only be loaded ifLogLevel.DEBUG
is active
-
debug
public void debug(Supplier<String> msg, Supplier<Throwable> t)
- Parameters:
msg
- message which will only be loaded ifLogLevel.DEBUG
is active
-
info
public void info(Supplier<String> msg)
- Parameters:
msg
- message which will only be loaded ifLogLevel.INFO
is active
-
info
public void info(Supplier<String> msg, Supplier<Throwable> t)
- Parameters:
msg
- message which will only be loaded ifLogLevel.INFO
is active
-
warn
public void warn(Supplier<String> msg)
- Parameters:
msg
- message which will only be loaded ifLogLevel.WARN
is active
-
warn
public void warn(Supplier<String> msg, Supplier<Throwable> t)
- Parameters:
msg
- message which will only be loaded ifLogLevel.WARN
is active
-
error
public void error(Supplier<String> msg)
- Parameters:
msg
- message which will only be loaded ifLogLevel.ERROR
is active
-
error
public void error(Supplier<String> msg, Supplier<Throwable> t)
- Parameters:
msg
- message which will only be loaded ifLogLevel.ERROR
is active
-
fatal
public void fatal(Supplier<String> msg)
- Parameters:
msg
- message which will only be loaded ifLogLevel.FATAL
is active
-
fatal
public void fatal(Supplier<String> msg, Supplier<Throwable> t)
- Parameters:
msg
- message which will only be loaded ifLogLevel.FATAL
is active
-
log
public void log(LogLevel level, Supplier<String> msg, Supplier<Throwable> throwable)
- Parameters:
level
- log level to verify if message should be loggedmsg
- msg message which will only be loaded if level is activethrowable
- optional if an exception happened
-
remove
public static boolean remove(Logger logger)
Removes logger from registry- Parameters:
logger
- Logger to be removed from this set, if present- Returns:
- Returns: true if this set contained the specified element
-
add
public static Logger add(Logger logger)
Registers a new logger- Parameters:
logger
- new logger to register- Returns:
- new logger or previous logger if there is already a registered one
-
add
public static Logger add(Logger logger, boolean replace)
Registers a new logger- Parameters:
logger
- new logger to registerreplace
- replace old logger if the same logger already exists- Returns:
- new logger or previous logger if there is already a registered one and replace is set to false
-
defaultLogger
public static Logger defaultLogger()
- Returns:
- default logger
-
getCaller
public static StackTraceElement getCaller()
- Returns:
- caller id aka
StackTraceElement
-
getCaller
public static StackTraceElement getCaller(int traceId)
- Parameters:
traceId
- index of caller- Returns:
- caller id aka
StackTraceElement
-
getExecutor
public static Executor getExecutor()
Initialises new Executor if not present- Returns:
- Executor
-
isRunning
public static boolean isRunning()
- Returns:
- true if the
executor
is used and active threads are running
-
-