Introduction to SLF4 APIs and best practices

Source: Internet
Author: User

Add the following dependencies to the Pom file

<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId>< Version>1.7.2</version></dependency><dependency><groupid>org.slf4j</groupid> <artifactId>slf4j-log4j12</artifactId><version>1.7.2</version></dependency>< Dependency><groupid>log4j</groupid><artifactid>log4j</artifactid><version> 1.2.17</version></dependency>

Log4j.properties Instructions for use

# Types of output levels ERROR, WARN, INFO, DEBUG

# Configure log information output destination, Log4j.appender.appenderName = Fully.qualified.name.of.appender.class

# # Org.apache.log4j.ConsoleAppender (console)

# # Org.apache.log4j.FileAppender (file)

# # Org.apache.log4j.DailyRollingFileAppender (Generate a log file every day)

# # Org.apache.log4j.RollingFileAppender (creates a new file when the file size reaches the specified size)

# # Org.apache.log4j.WriterAppender (send log information in stream format to any specified location)

# Configure the format of log information, log4j.appender.appenderName.layout = Fully.qualified.name.of.layout.class

# # Org.apache.log4j.HTMLLayout (layout in HTML table format)

# # Org.apache.log4j.PatternLayout (flexibility to specify layout mode)

# # Org.apache.log4j.DailyRollingFileAppender (Generate a log file every day)

# # Org.apache.log4j.SimpleLayout (contains level and information strings for log information)

# # Org.apache.log4j.TTCCLayout (contains information about the time, thread, category, etc.) of log generation

# Console Options

# # Threshold=debug: Specifies the lowest level of output for log messages.

# # Immediateflush=true: The default value is true, meaning that all messages will be output immediately.

# # Target=system.err: Default is: System.out, specify output console

# Fileappender Options

# # Threshold=debuf: Specifies the lowest level of output for log messages.

# # Immediateflush=true: The default value is true, meaning that all messages will be output immediately.

# # File=mylog.txt: Specifies the message output to the Mylog.txt file.

# # Append=false: The default value is True, the message is added to the specified file, and false means that the message is overwritten with the specified file content.

# Rollingfileappender Options

# # Threshold=debug: Specifies the lowest level of output for log messages.

# # Immediateflush=true: The default value is true, meaning that all messages will be output immediately.

# # File=mylog.txt: Specifies the message output to the Mylog.txt file.

# # Append=false: The default value is True, the message is added to the specified file, and false means that the message is overwritten with the specified file content.

# # maxfilesize=100kb: The suffix can be kb, MB or GB. When the log file reaches this size, it will automatically scroll to move the original content to the Mylog.log.1 file.

# # maxbackupindex=2: Specifies the maximum number of scrolling files that can be produced.

# The meaning that several symbols represent in the log Information format

# # x: x Information output when left-aligned;

# #%p: Output log information priority, i.e. Debug,info,warn,error,fatal,

#%d: the date or time of the output log time, the default format is ISO8601, can also be specified after the format, such as:%d{yyy MMM dd hh:mm:ss,sss}, output similar: October 18, 2002 22:10:28,921

#%c: Output log information belongs to the class, which is usually the full name of the class

# #%t: Output The name of the thread that generated the log event

# #%l: The location of the output log event, equivalent to the combination of%c.%m (%f:%l), including the class name, the thread that occurred, and the number of rows in the code

# #%l: line numbers in the output code

# #%m: Output The message specified in the code, resulting in the log specific information

# #%n: Output a carriage return line break, Windows platform is "\ r \ n", Unix platform for "\ n" Output log information wrapping

# Settings for custom classes category

Log4j.appender.fileout=org.apache.log4j.dailyrollingfileappender

Log4j.appender.fileout.encoding=utf-8

Log4j.appender.fileout.DatePattern = '. ' Yy-mm-dd HH ' \u65f6.log '

Log4j.appender.fileout.file=g:/log/jmoco_mag.log

Log4j.appender.fileout.layout=org.apache.log4j.patternlayout

LOG4J.APPENDER.FILEOUT.LAYOUT.CONVERSIONPATTERN=-[%D{YY-MM-DD HH:MM:SS}]<%P><%C>{\U4FE1\U606F\UFF1A %m}%n


Introduction to SLF4 APIs and best practices

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.