Javaweb Log System

Source: Internet
Author: User

1.slf4j

SLF4J, the simple log façade (easy Logging facade for Java), is not a specific log solution, it only serves a wide variety of log systems. Officially, SLF4J is a simple facade for the log system, allowing end users to use the log systems they want when they deploy their apps.

2.log4j

LOG4J is an Apache open source project, through the use of log4j, we can control the log information delivery destination is the console, files, GUI components, even the socket server, NT Event recorder, UNIX syslog daemon, etc. We can also control the output format of each log, and by defining the level of each log information, we can control the log generation process more carefully. Most interesting of all, these can be configured flexibly with a single configuration file, without the need to modify the code of the application.

Configuration method:

Recommend a website http://mvnrepository.com, this site can easily get to

    • Maven
    • Gradle
    • SBT
    • Ivy
    • Grape
    • Leiningen
    • Buildr
such as the dependency code block for project management tools like I'm using Maven management, just search log4j and click on the most used version.
<!--https://mvnrepository.com/artifact/log4j/log4j<dependency>    < groupid>log4j</groupid>    <artifactId>log4j</artifactId>    <version>1.2 . </version></dependency>

The first step is done.

The second step is to configure the Log4j.properties file to be created under Classpath

log4j.rootcategory=INFO, stdout, R log4j.appender.stdout=Org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=Org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=[QC]%p [%t]%c.%m (%l) | %m%N LOG4J.APPENDER.R=Org.apache.log4j.dailyrollingfileappenderlog4j.appender.r.file=d:\\tomcat5.5\\logs\\qc.loglog4j.appender.R.layout=Org.apache.log4j.patternlayoutlog4j.appender.r.layout.conversionpattern=%d-[ts]%p%t%c-%m%N Log4j.logger.com.neusoft=DEBUGlog4j.logger.com.opensymphony.oscache=ERRORlog4j.logger.net.sf.navigator=ERRORlog4j.logger.org.apache.commons=ERRORlog4j.logger.org.apache.struts=WARNlog4j.logger.org.displaytag=ERRORlog4j.logger.org.springframework=DEBUGlog4j.logger.com.ibatis.db=WARNlog4j.logger.org.apache.velocity=FATAL log4j.logger.com.canoo.webtest=WARN Log4j.logger.org.hibernate.ps.PreparedStatementCache=WARNlog4j.logger.org.hibernate=DEBUGlog4j.logger.org.logicalcobwebs=warn

(1) Logger-Use this object for the output client to use logger for output

(2) Appender-Use this object to define where the output goes

Logger and Appender are a one-to-many relationship

Eg:consoleappender, Fileappender, Roolingfileappender

(3) Layout "Patternlayout"-use this object to define the format of the output

Layout and Appender are one-to-many relationships (i.e. one appender corresponds to a layout, and one layout can correspond to multiple Appender)

Specific can look at the Baidu Encyclopedia, speak very detailed

The third step is to use in the project, the simplest is the console output

SLF4J is used here.

Static Logger logger= Loggerfactory.getlogger (indexcontroller.  Class. GetName ());

You can then use logger to output the log where you want it.

3.Jakarta Commons Logging

This is Java's own logging, it is said that performance is not very good. Large projects are relatively small.

Javaweb Log System

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.