Log expansion Pack ESLF4J Introduction

Source: Internet
Author: User

ESLF4J's MAVEN project is hosted in https://github.com/xionghuiCoder/eslf4j , you can also http://www.oschina.net/p/eslf4j to learn about it in a simple introduction.

1, eslf4j introduction
  • ESLF4J (expand SLF4J) is primarily used to troubleshoot bug locating issues on online logs. For large concurrent sites, in order to ensure performance, often set the log level is error, but in this case, if there is a bug on the line, often there is only one error log, which is almost no help to locate the problem, Because this error is often caused by one or more error data or actions in the context, the context's info or debug log is not output.

  • eslf4j can cache the context log, as in the case above, if error occurs, the debug or info before the error will be printed level of logging. However, if error does not occur, no logs will be printed. This facilitates the location of the problem, but also prevents the output of a large number of logs and affect performance.

2, configuration eslf4j
Count=100buffersize=10mminthreshold=debugfilter=com.jd.o2o.filter.null1filterfilter= Com.jd.o2o.filter.null2filtermemorymanager=com.jd.o2o.memory.nullmemorymanager

  • Count is the number of logs cached and must be configured (otherwise it may cause a memory leak, which is related to the implementation of thread connection pooling and threadlocal); For example, this configuration is 100, indicating that once a log is printed, the 100 logs before the log are printed.

  • BufferSize the space occupied by the log for ESLF4J cache, it must be configured to use Memorymanager to free memory when the cache reaches the configured size, and the buffersize configured here is 10m, which means that the cache consumes up to 10m of memory. In addition, Unit B (bit), K (KB), and G (GB) are supported.

  • Minthreshold is the lowest gate value for log level, must be configured to support All,trace,debug,info,warn,error,fatal and off, for example, this is configured as debug, Only logs with a level greater than or equal to debug will be cached and printed.

  • Filter is a log filter, can be configured or not configured, of course, you can configure multiple Filter needs to implement the Com.jd.o2o.core.filter.Filter interface, and requires a parameterless constructor; The filter is called before the log is cached and can be self-processed by the log.

  • Memorymanager is used to manage memory, can be configured or not configured, Memorymanager needs to implement the Com.jd.o2o.core.memory.IMemoryManager interface, and requires a parameterless constructor, which is used by default if not configured Com.jd.o2o.core.memory.impl.DefaultMemoryM Anagerimpl to manage memory, Memorymanager will buffersize si cho in the log cache to free up memory.

3, extension point

    1) filter is a extension point, Need to implement Com.jd.o2o.core.filter.Filter interface, filter interface is used to process Com.jd.o2o.core.bean.messagebean,messagebean contains log message and Throwable,filter can modify the log or modify the exception, for example, want to filter out with "Debug" string message can define the following filter:

      private static final  string debug_sign =  "DEBUG";   @Override   public boolean dofilter ( Messagebean messagebean)  {    String message =  Messagebean.getmessage ();    if  (message == null)  {       throw new eslf4jexception ("Message should not be null");     }    if  (Message.contains (debug_sign))  {       //  return false will not be cached, nor will it print       return false;     }    return true;  } 

    2)Memorymanageris the other one . extension point, buffersize, Defaultmemorymanagerimpl clears the log cache for some threads, which guarantees space availability, but may lose the context log for some thread caches, so if you use the default DEFAULTMEMORYMANAGERIMPL best configured Count and buffersize, the following formula can be used to calculate the appropriate buffersize (unit m):

     
     

    Of course you can also customize memorymanager, need to implement Imemorymanager interface, for example, to output a context log before emptying the cache, you can define the following memorymanager:

    @Override public void Manager (Fixedqueue queue) {while (queue.size () > 0) {Messagebean bean = Queue.remove ()      ;    Logger for slf4j logger logger.error (Bean.getmessage (), bean.getthrowable ()); }  }
4. Other

ESLF4J is a slf4j-based extension, choosing slf4j because it is convenient to switch logs, such as switching log4j to logback just modify the rack package and configuration files, without modifying the code at all. In addition, use ESLF4J API and SLF4J is very similar, you can refer to the following demo:

private static final Logger Logger = Eslf4jloggerfactory.getlogger (clazz); Logger.info (msg), .....


Log expansion Pack ESLF4J Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.