Class LogFormatterConsole
java.lang.Object
java.util.logging.Formatter
org.nanonative.nano.helper.logger.logic.LogFormatterConsole
Formatter for logging messages to the console.
This formatter provides a consistent log format comprising the timestamp, log level, logger name, and message. The formatted log entries are easy to read and allow for quick scanning of log files. The log format is as follows:
[Timestamp] [Log Level] [Logger Name] - Message
The formatter supports parameterized messages, allowing insertion of values at runtime. To include dynamic content in your log messages, use placeholders '{}' for automatic replacement or '%s' for manual specification. Each placeholder will be replaced with corresponding parameters provided in the logging method call.
Usage Example:
logger.info(() -> throwable, "Processed records - success: [{}], failure: [%s], ignored; [{2}]", successCount, failureCount, ignoreCount);
In this example, 'successCount' replaces the first '{}' placeholder, 'failureCount' replaces the '%s' placeholder and 'ignoreCount' replaces the last [{2}] placeholder.
Note: The formatter also handles exceptions by appending the stack trace to the log entry, should an exception be thrown during execution.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static StringapplyCustomFormat(String message, Object... params) Replacing placeholders with parameters.Format a LogRecord into a string representation.protected static StringformatLoggerName(LogRecord logRecord) Methods inherited from class java.util.logging.Formatter
formatMessage, getHead, getTail
-
Field Details
-
dateFormat
-
paddingLogLevel
protected final int paddingLogLevel
-
-
Constructor Details
-
LogFormatterConsole
public LogFormatterConsole()
-
-
Method Details
-
format
Format a LogRecord into a string representation. -
formatLoggerName
-
applyCustomFormat
Replacing placeholders with parameters.- Parameters:
message- the message to be formatted.params- the parameters for the message.- Returns:
- a string with the formatted message.
-