Configure log4j in a generic project

Source: Internet
Author: User
Tags log4j
first, the introduction of JAR package

Gralde Project

Compile ' log4j:log4j:1.2.17 '
compile ' commons-logging:commons-logging:1.2 '

Maven Project

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>
<dependency>
    <groupId> commons-logging</groupid>
    <artifactId>commons-logging</artifactId>
    <version> 1.2</version>
</dependency>

General items

Directly into the jar file, add to the project directory can
Second, add log4j.properties configuration file

Gradle/maven Project creates log4j.properties in the resources directory

Common items Create log4j.properties in the same sibling directory of the package

Log4j.properties Simple example below

Log4j.rootlogger=debug,console

# Applies to console
Log4j.appender.console=org.apache.log4j.consoleappender
Log4j.appender.threshold=debug
log4j.appender.console.target=system.out
log4j.appender.console.layout= Org.apache.log4j.PatternLayout
Log4j.appender.console.layout.conversionpattern=[%-12d{hh\:mm\:ss. SS}] [%p]%l%m%n

More configuration can refer to the configuration and use of log4j three, use the way

public class Resourcecontentutil {

    private static final Logger log = Logger.getlogger (Resourcecontentutil.class) C9/>public static void Main (string[] args) {
        log.info ("Hello world!")
    }

}

Specific source please refer to: GitHub Project Io.resource Module

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.