LogX, also known as Log Express, is a Java-based logging utility designed to integrate seamlessly with Java programs, providing an efficient and organized logging system. It aims to simplify the process of debugging by organizing logs in a standard format, allowing developers to identify and address program issues more effectively. The idea for creating LogX stemmed from the reported flaw in log4j, which resulted in a surge of cyberattacks towards the end of 2021.
LogX offers a range of features to streamline the logging process and enhance the overall debugging experience:
-
Custom Logger Implementation: LogX provides a custom logger implementation that supports various logging levels, ensuring flexibility and expressiveness while debugging.
-
Multiple Logging Levels: The utility supports multiple logging levels, including:
- All: Captures all logging information.
- TRACE: Detailed information, typically used for troubleshooting and diagnosing.
- DEBUG: Information helpful for debugging purposes.
- WARN: Indicates potential issues that might need attention.
- FATAL: Critical errors that might lead to the program's termination.
- ERROR: Reports errors that need immediate attention.
-
Console and File Logging: LogX allows logs to be directed both to the console and a log file, providing developers with flexibility in monitoring and storing log data.
-
Well-Formatted Logs: Logs generated by LogX are well-formatted and include essential details such as timestamp, log level, class name, line number, and log message. This ensures better readability and comprehension of the logged information.
-
Log File Rotation: To manage log file size and avoid overwhelming log files, LogX supports automatic log file rotation. This feature helps maintain log files within a specified size limit.
-
Exception Handling: LogX can effectively handle logging exceptions along with stack traces, making it easier to identify the root cause of errors and exceptions.
-
Set the desired logging level and configure other options (e.g., log file path, rotation size) as needed.
-
Enjoy easy and efficient logging with LogX in your Java application!
- With LogX, you can rest assured that your logging needs are well-handled, and debugging your Java programs becomes a breeze.
Note: This logger is designed as a singleton, and you can get an instance using getLogger() method ,Ensure you keep the LogX library up-to-date to leverage the latest improvements and security enhancements.
To integrate LogX into your Java program, follow these steps:
-
Clone the LogX library and include it in your project's classpath or create a jar and include.
-
Initialize the logger instance in your Java code:
-
you can find the log file in User Home directory
import com.logger.express.LogLevel;
import com.logger.express.LogOperator;
import com.logger.express.Logger;
public class Main {
private static final Logger logger = LogOperator.getLogger().writeHeaderBanner();
public static void main(String[] args) {
// Your code here
logger.trace("This is a trace message.");
logger.debug("This is a debug message.");
logger.info("This is an info message.");
logger.warn("This is a warning message");
logger.error("This is a error message");
logger.error(new Exception("This is error printStackTrace message of exception "));
logger.fatal("This is a fatal message");
logger.setLogLevel(LogLevel.WARN); // Set log level to WARN
logger.trace("This debug message won't be logged.");
logger.debug("This debug message won't be logged.");
logger.info("This is an info message after changing log level.");
logger.warn("This is a warning message after changing log level.");
logger.error("This is an error message after changing log level.");
logger.fatal("This is an fatal message after changing log level.");
}
}