Log4Error is a JAVA library that helps in reducing logs via smartly printing info logs only when error occur
APACHE-2.0 License
log4error
?Organisations often turn off INFO
level logs in production to reduce the logging cost.
I have worked in many projects where teams have only enabled ERROR
level logs in production.
The problem with logging only an ERROR
log is you don't get any other information at the time of any unexpected incident, just the limited info from the error logs and stack trace.
Contextual, logical, or debugging information is absent since you have disabled info logs.
log4error
library -COLLECT INFO LOGS
on the GO and print
them to the console only when an exception occurs
.Actual profiling hasn't been done yet (TBD).
Using this library we will be reducing total I/O operation as well.
For all happy flows we will not be making any system calls, we just be collecting logs on the go in an array.
There is going to be a performance difference for unhappy flows with the current implementation.
And printing all info logs during error, there is an increase in time to process both usages.
To Improve - Collect logs into a bulk record and print all logs on the error with a single I/O operation.
Thanks to Christian Hujer pointed out that "Your library is actually improving performance, always, at least in the happy path. Appending a log entry to a linked list (or array list, who cares these days…) is much cheaper than writing a log entry out. The former will rarely require a system call (only if the JVM process needs more memory from the OS), the latter will always require a system call (write)."
RUN Suite of 10 sets while logging 10,000 times each time to get average performance -
Info Logs -
Log4j - Average log time was 15 ns
log4error - Average log time was 38 ns
ERROR Logs -
Log4j - Average log time was 15 ns
log4error - Average log time was 42 ns
LoggerFilter.Class
for the initialization of LoggerLoggerFilterExample.class
for reference. Logger().info(String message, Object... obj)
example - Logger().info("Here I am printing some logs with argument one: {} and arg 2 : {}", arg1, arg2)
- Logger().error(String message, Object... obj);
Logger().debug(String message, Object... obj)
example - Logger().debug("Here I am printing some logs with argument one: {} and arg 2 : {}", arg1, arg2)
Logger.pInfo(String message, Object... obj)
Logger.pError(String message, Object... obj)
Logger.pDebug(String message, Object... obj)
Logger.pWarn(String message, Object... obj)
Maven
<dependency>
<groupId>io.github.parvez3019</groupId>
<artifactId>log4error</artifactId>
<version>0.0.11</version>
</dependency>
Gradle
implementation group: 'io.github.parvez3019', name: 'log4error', version: '0.0.11'
Gradle (short)
implementation 'io.github.parvez3019:log4error:0.0.11'
Gradle (kotlin)
implementation("io.github.parvez3019:log4error:0.0.11")
mvn clean install