The LOG4J environment consists of three main components:
Logger (Logger): controls which logging statements are enabled or disabled. The following levels can be set for the logger:
All, DEBUG, INFO, WARN, ERROR, FATA, OFF.
layout: formats logging requests According to the user's wishes.
Appender: sends formatted output to the destination. Log4j brought in also remember the Appender as follows:
- Consoleappender
- Fileappender
- Smtpappender
- Jdbcappender
- Jmsappender
- Nteventappender
- Syslogappender
You can also create a custom Appender
Gorgeous split-rich ***************************************** ***************************************
Create a custom Appender
1. Inherit the Appenderskeleton class and implement three methods (
you can also inherit existing Appender, override some methods, and implement the required logic)
Public classSimpleappenderextendsAppenderskeleton {//Configure required properties in Log4j.xml, where you can injectPrivateString Developer; @Overrideprotected voidAppend (loggingevent loggingevent) {
Custom Output what System.out.println ("=========" + developer + "test===========" +loggingevent.getmessage ()); } @Override Public BooleanRequireslayout () {
Whether layout is required, or false, even if Log4j.xml is configured with layout does not take effect. return false; } @Override Public voidClose () {
Release resource this.closed = true; } PublicString Getdeveloper () {returndeveloper; } Public voidSetdeveloper (String developer) { This. Developer =developer; }2. Configure Log4j.xml
<!-- --> < appender name = "Simpleappender" class = "Com.cn.simple.logger.SimpleAppender" > < param
name = "developer" = "Lqw" ></ " Span style= "COLOR: #800000" >param > </ appender >
3. Implementation
Logger.info ("[Springdemo]--------Info"); Logger.warn ("[Springdemo]--------warn reminder"); Logger.error ("[Springdemo]--------Error Exception");
4. Output results
=========lqwtest===========[springdemo]--------info =========lqwtest===========[springdemo]-------- warn alert =========lqwtest===========[springdemo]--------Error exception
Reference Documentation:
Http://www.360doc.com/content/16/0121/16/14567867_529569233.shtml
Log output to frame reference:
http://zhangjunhd.blog.51cto.com/113473/48895/
log4j Custom Appender