Package com.chrisnewland.freelogj
Class LoggerFactory
- java.lang.Object
-
- com.chrisnewland.freelogj.LoggerFactory
-
public class LoggerFactory extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private static java.time.format.DateTimeFormatterdateFormatprivate static Logger.LogLevellogLevelprivate static java.io.PrintStreamprintStream
-
Constructor Summary
Constructors Constructor Description LoggerFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static LoggergetLogger(java.lang.Class<?> clazz)Returns aLoggerfor the given Class.static voidinitialise(Logger.LogLevel logLevel)Initialise the LoggerFactory with the givenLogger.LogLevel.static voidinitialise(Logger.LogLevel logLevel, java.io.PrintStream printStream)Initialise the LoggerFactory with the givenLogger.LogLevelandPrintStream.static voidinitialise(Logger.LogLevel logLevel, java.io.PrintStream printStream, java.time.format.DateTimeFormatter dateTimeFormatter)Initialise the LoggerFactory with the givenLogger.LogLevel,PrintStream, andDateTimeFormatterAll loggers created bygetLoggerwill be set at this LogLevel and use this PrintStream and DateTimeFormatter.static voidsetLogFile(java.nio.file.Path logFilePath)Set the LoggerFactory PrintStream to use aPrintStreamwrapping aFileOutputStreamopened on the givenPathAll loggers created bygetLoggerwill use this PrintStream.
-
-
-
Field Detail
-
logLevel
private static Logger.LogLevel logLevel
-
printStream
private static java.io.PrintStream printStream
-
dateFormat
private static java.time.format.DateTimeFormatter dateFormat
-
-
Method Detail
-
initialise
public static void initialise(Logger.LogLevel logLevel)
Initialise the LoggerFactory with the givenLogger.LogLevel. All loggers created bygetLoggerwill be set at this LogLevel.- Parameters:
logLevel- The logging level. Messages below this level will not be logged.
-
initialise
public static void initialise(Logger.LogLevel logLevel, java.io.PrintStream printStream)
Initialise the LoggerFactory with the givenLogger.LogLevelandPrintStream. All loggers created bygetLoggerwill be set at this LogLevel and use this PrintStream.- Parameters:
logLevel- Messages below this level will not be logged.printStream- Messages will be written to this PrintStream.
-
initialise
public static void initialise(Logger.LogLevel logLevel, java.io.PrintStream printStream, java.time.format.DateTimeFormatter dateTimeFormatter)
Initialise the LoggerFactory with the givenLogger.LogLevel,PrintStream, andDateTimeFormatterAll loggers created bygetLoggerwill be set at this LogLevel and use this PrintStream and DateTimeFormatter.- Parameters:
logLevel- Messages below this level will not be logged.printStream- Messages will be written to this PrintStream.dateTimeFormatter- Messages timestamps will be formatted with this DateTimeFormatter.
-
setLogFile
public static void setLogFile(java.nio.file.Path logFilePath)
Set the LoggerFactory PrintStream to use aPrintStreamwrapping aFileOutputStreamopened on the givenPathAll loggers created bygetLoggerwill use this PrintStream.- Parameters:
logFilePath- Path to the log file. If the log file cannot be opened, aRuntimeExceptionis thrown wrapping theFileNotFoundException.
-
-