Code Monkey home page Code Monkey logo

log4error's Introduction

What is 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.

Detailed Article - Medium Link

With log4error library -

  • You can COLLECT INFO LOGS on the GO and print them to the console only when an exception occurs.
  • You can also collect debug logs for a request and print them only if some error occurs.
  • With this, you can minimize the logging (that includes I/O operation for printing to console or file) via skipping logging for happy flows.
  • And only perform I/O operation with bulk writing of logs in unhappy flows.

How does it work?

  • It keeps collecting info logs in an in-memory request scoped local thread.
  • When you print an error log at any statement, at the point it prints the complete info stack for reference.
  • That helps debug issues when they occur and reduces overall logging data.

Performance Statistics -

  • 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

How to use it -

Create a LoggerFilter

  • Create a LoggerFilter.Class for the initialization of Logger
  • Check out LoggerFilterExample.class for reference.

Logger.info()

  • Using the Logger().info(String message, Object... obj) method you can collect the info logs, across the flow of a request.
  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()

  • Will print the complete info log stack until that point and will reset the info log stack to empty.
- Logger().error(String message, Object... obj);

Logger.debug()

  • Using the Logger().debug(String message, Object... obj) method you can collect the debug logs, across the flow of a request.
  Logger().debug(String message, Object... obj)
  example - Logger().debug("Here I am printing some logs with argument one: {} and arg 2 : {}", arg1, arg2)

normal log methods for direct console printing

  • For directly printing to console log methods you can use the following methods -
  Logger.pInfo(String message, Object... obj)
  Logger.pError(String message, Object... obj)
  Logger.pDebug(String message, Object... obj)
  Logger.pWarn(String message, Object... obj)

Installation

Maven Central Repository - Link

Add the following dependency to your pom.xml file

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")

Run the following command for installation

mvn clean install

log4error's People

Contributors

dependabot[bot] avatar parvez3019 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ravirawal13

log4error's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.