Logging
Add precise timing and exact code location to your logging data.
Last updated
Add precise timing and exact code location to your logging data.
Last updated
Built on Standard Java Logging Utilizes the built-in java.util.logging framework, part of Java SE. No additional external libraries, such as Apache Log4j, are required.
High Performance Capable of logging over 10,000 lines per second on a MacBook Pro when using the FileHandler and KLogLineFormatter.
Simplified Logging Streamlines logging with straightforward methods for debug, error, and info messages.
Static Methods All methods are static, eliminating the need for instantiation.
Flexible Handlers and Formatters Includes handlers and formatters for generating log output in various formats: tabular text, CSV, XML, JSON, and YAML. Supports sending logs to JDBC-compliant databases or routing error logs to any SMTP server.
Enhanced Log Details Provides precise timestamps and exact code locations in formatted log outputs.
Configuration and Runtime Adjustments Logging is enabled via the KLog.properties configuration file, which must be located in the current directory. Logging levels can be dynamically adjusted during execution using setLevelXXX() methods and reset to the configured value with resetLevel().
The Java utility package ch.k43.util leverages KLog internally to assist with problem determination. Setting the log level to FINEST in the KLog.properties file enables detailed debugging mode, providing comprehensive insights during code execution.
The logging properties file enables and configures the logging framework used by all KLog
methods. Simply download, edit and place the file in the current directory of your Java application.
To override the default settings of KLog at runtime, the following Java system properties may be used:
-DKLogPropertyFile
Klog.properties
Path and file name of KLog properties file
-DKLogLevel
n/a
Set the KLog level (INFO, ERROR, DEBUG or OFF)
Example
Please note that all command line options are case sensitive.
In addition to the built-in handlers ConsoleHandler and FileHandler of the standard java.util.logging package, the following KLog handlers are provided:
KLogJDBCHandler: Send output to any JDBC compliant database
KLogSMTPHandler: Send errors (FATAL log level) to any SMTP server
The log information (timestamp, logging level, code location and message) are formatted with the formatter classes:
KLogCSVFormatter: Format each log entry as a one-line CSV string
KLogJSONFormatter: Format each log entry as a multi-line JSON string
KLogLineFormatter: Format each log entry as a one-line tabular string
KLogXMLFormatter: Format each log entry as a multi-line XML string
KLogYAMLFormatter: Format each log entry as a multi-line YAML string