Log4j+log4j2+logback+syslog+graylog

Source: Internet
Author: User
Tags syslog graylog log4j
Let's say log4j,log4j2,logback how to write logs into Graylog

Log4j:

<!--log write graylog only slow SQL log slow SQL uses facility is LOCAL1 other logs please do not use Local1 log4j the Syslogappender can only configure host addresses that accept the Syslog log, the port does not Configurable, using the default: 514 Pom: <dependency> <groupId>org.syslog4j</groupId> <artifactid&gt ;syslog4j</artifactid> <version>0.9.30</version> </dependency>--> <append Er name= "syslogappender" class= "Org.productivity.java.syslog4j.impl.log4j.Syslog4jAppender" > <param name= " Sysloghost "value=" 172.16.2.167 "/> <param name=" port "value=" 8888 "/><!--input node port--> <param Name= "facility" value= "LOCAL1"/> <param "name=" Protocol "UDP" value=/> <param "header" Name= "tr
	            UE "/> <param name=" Threshold "value=" INFO "/> <layout class=" Org.apache.log4j.PatternLayout "> <param name= "Conversionpattern" value= "[%d{yyyy-mm-dd hh:mm:ss\}][%-5p] [%t] [%c:%l]-%m%n"/> </layo Ut> </appender>

Log4j2:

<?xml version= "1.0" encoding= "UTF-8"?> <!--priority is from high to Low: off, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, all-->
<!--status is used to specify the level of print logs for the log4j itself.
Monitorinterval is used to specify the monitoring interval for log4j automatic reconfiguration, in S, and minimum 5s. --> <configuration strict= "true" > <Properties> <property name= "Logbasedir" >d:/ttpai_boss_ log</property> <property name= "APPNAME" >log_test</Property> <property name= "log.layou T ">[%d{yyyy-mm-dd hh:mm:ss}][%-5p] [%t] [%c:%l]-%m%n</property> </Properties> <!--Two types of apps are used here
            Ender,rollingfile is a scrolling type, new folder records are created when policy conditions are met--> <Appenders> <appender type= "Console" name= "STDOUT" > <Target>SYSTEM_OUT</Target> <layout type= "patternlayout" pattern= "${log.layout}"/&G
        T </Appender> <rollingfile name= "FILE" filename= "${logbasedir}/${appname}.log" Filepattern =
     "${logbasedir}/${appname}-%d{yyyy-mm-dd}.%i.log" >       <Policies> <timebasedtriggeringpolicy/> <sizebasedtriggeringpolicy siz
            E= "100MB"/> </Policies> <defaultrolloverstrategy max= "/><!--The default value is 7--> <layout type= "Patternlayout" > <Charset>UTF-8</Charset> <patt ern>${log.layout}</pattern> </Layout> </RollingFile> <socket name= "Syslog" Host= "172.16.2.167" port= "2222" protocol= "UDP" > <patternlayout pattern= "${log.layout}"/> > </Appenders> <Loggers> <logger name= "Com.alibaba.druid.filter.stat.StatFilter" level= "Debug" additivity= "false" >--> <appender-ref ref= "FILE"/> <!--<appenderref R ef= "Syslog"/>--> <appenderref ref= "STDOUT"/> </Logger> <!--<asyncroot level = "Debug" includelocation= "true" additivity= "false" >--> <!--<appenderref ref= "STDOUT"/>--> <!--<ap Penderref ref= "FILE"/>--> <!--<appenderref ref= "syslog"/>--> <!--</asyncroot& Gt --> <root level= "Debug" > <!--<appenderref ref= "STDOUT"/>--> <!--<ap Penderref ref= "FILE"/>--> <!--<appenderref ref= "syslog"/>--> </Root> &L T;/loggers> </Configuration>

Maven:

<dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactid&gt ;log4j-core</artifactid> <version>2.7</version> </dependency> <dependency> <gr Oupid>org.slf4j</groupid> <artifactId>slf4j-api</artifactId> <version>1.7.12</ version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> < artifactid>log4j-slf4j-impl</artifactid> <version>2.7</version> </dependency> <depe ndency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <ve rsion>1.1.3</version> </dependency> <dependency> <groupid>ch.qos.logback</groupid&
			Gt <artifactId>logback-classic</artifactId> <version>1.1.3</version> </dependency> ;d ependency> <groupid>com.lmax</groupId> <artifactId>disruptor</artifactId> <version>3.3.2</version> </dependency> </dependencies>

Logback:

<?xml version= "1.0" encoding= "UTF-8"?> <configuration> <property name= "Log.path" value= "d:/logtest/" logback/asy_50_100000 "/> <appender name= STDOUT" class= "Ch.qos.logback.core.ConsoleAppender" > <e Ncoder> <pattern>[%d{yyyy-mm-dd hh:mm:ss}][%-5p] [%t] [%c:%l]-%m%n</pattern> </e Ncoder> </appender> <!--file output formatting--> <appender name= "file" class= "ch.qos.logback.core.rolling .
        Rollingfileappender "> <!--log daily print file--> <file>${log.path}/log_test.log</file> <!--the directory generated by the configuration log and the rules for generating file names in Logs/mylog-2017-06-31.0.log.zip--> <rollingpolicy class= "Ch.qos.logback.core . Rolling. Timebasedrollingpolicy "> <filenamepattern>${log.path}/log_test-%d{yyyy-mm-dd}.%i.log</filenamepatt ern> <timebasedfilenamingandtriggeringpolicy class= "Ch.qos.logback.core.rolling.SizeAndT
 IMEBASEDFNATP ">               <!--files will be compressed and cut--> <maxfilesize>100 when the maximum 128MB is reached mb</maxfilesize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <filter class= "Ch.qos.logback. Classic.filter.ThresholdFilter "> <level>DEBUG</level> </filter> <!--article  The format of the log output of the piece--> <encoder> <pattern> [%d{yyyy-mm-dd hh:mm:ss}][%-5p] [%t]
        [%c:%l]-%m%n </pattern> <charset>UTF-8</charset> <!--set up the character set--> </encoder> </appender> <appender name= "Bizsyslogappender" class= "Ch.qos.logback.classic.net.Syslo Gappender "> <syslogHost>172.16.2.167</syslogHost> <port>3333</port> <facility> Local0</facility> <suffixpattern>[%d{yyyy-mm-dd hh:mm:ss}][%-5p] [%t] [%c:%l]-%m%n%xexception</

	Suffixpattern> </appender><appender name= "ASYNC" class= "Ch.qos.logback.classic.AsyncAppender" ><!--Configure the asynchronous printing info information--> <!--do not lose the log.  By default, tract, DEBUG, info-level logs--> <discardingThreshold>0</discardingThreshold> <!--are discarded if the queue is full 80% Changes the depth of the default queue, which affects performance. The default value is 256--> <queueSize>256</queueSize> <appender-ref ref= "Bizsyslogappe NDEr "/> </appender> <root level=" Debug "><!--Specify all appender--> <!--<append to perform Er-ref ref= "STDOUT"/>--> <appender-ref ref= "ASYNC"/> <!--<appender-ref ref= "Bizsyslog" Appender "/>--> </root> </configuration>

Maven:

<dependencies>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactid >slf4j-api</artifactId>
			<version>1.7.12</version>
		</dependency>

		< dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactid>logback-core</ artifactid>
			<version>1.1.3</version>
		</dependency>
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
			<version>1.1.3</version>
		</dependency>

		<dependency>
			<groupId> com.lmax</groupid>
			<artifactId>disruptor</artifactId>
			<version>3.3.2</ version>
		</dependency>
	</dependencies>


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.