Log4j: Warn please initialize the log4j system properly Solution

Source: Internet
Author: User

Log4j: warn no appenders cocould be found for Logger

(Org. springframework. Context. Support. classpathxmlapplicationcontext ).

Log4j: Warn please initialize the log4j system properly.

 

Spring uses the open-source framework log4j to output information,

To solve this problem, you can create a log4j configuration file. Create a configuration file in the src directory, select

Choose File> New> file. Enter log4j. properties as the file name. The file content is as follows:

Log4j. rootlogger = warn, stdout

Log4j. appender. stdout = org. Apache. log4j. leleappender

Log4j. appender. stdout. layout = org. Apache. log4j. patternlayout

Log4j. appender. stdout. layout. conversionpattern = % d % P [% C]-% m % N

Listing 10.6 log4j configuration file

After the configuration file is added, the warning on running the program again disappears. Especially during web layer development

The complete error message in the spring background can be seen only after this file is added. Integrate applications in spring development

When a 404 error occurs, but no error information is displayed, you need to check

Whether the file exists.

 

 

Org. springframework. Core. CollectionFactory2008-05-17 18: 50log4j: warn no appenders cocould be found for logger (Org. springframework. Core. collectionfactory ).

Log4j: Warn please initialize the log4j system properly.

 

 

Log4j configuration is commonly used. Two methods are generally used:. properties and. xml. The following two simple examples are provided:

1. log4j. Properties

### Set the levels of info, debug, warn, error, and output location A1, A2 for the org. zblog domain ##

Log4j.category.org. zblog = error, A1

Log4j.category.org. zblog = info, A2

Log4j. appender. A1 = org. Apache. log4j. leleappender

### Set output location A1 to leleappender (console )##

Log4j. appender. a1.layout = org. Apache. log4j. patternlayout

### Set the output layout format patterlayout of A1. (you can flexibly specify the layout mode )##

Log4j. appender. a1.layout. conversionpattern = % d {yyyy-mm-dd hh: mm: SS, SSS} [% C]-[% P] % m % N

### Configure the log output format ##

Log4j. appender. A2 = org. Apache. log4j. rollingfileappender

### Set the output location A2 to the file (a new file is generated when the file size reaches the specified size )##

Log4j. appender. a2.file = E:/study/log4j/zhuwei.html

### File location ##

Log4j. appender. a2.maxfilesize = 500kb

### File size ##

Log4j. appender. a2.maxbackupindex = 1

Log4j. appender. a2.layout = org. Apache. log4j. htmllayout

# Specify HTML output

Ii. log4j. xml

<? XML version = "1.0" encoding = "gb2312"?>

<! Doctype log4j: Configuration System "log4j. DTD">

<Log4j: configuration xmlns: log4j = "http://jakarta.apache.org/log4j/">

<Appender name = "org. zblog. All" class = "org. Apache. log4j. rollingfileappender">

<! -- Set the channel ID: org. zblog. All and the output method: org. Apache. log4j. rollingfileappender -->

<Param name = "file" value = "E:/study/log4j/all. Output. log"/> <! -- Set the file parameter: log output file name -->

<Param name = "APPEND" value = "false"/> <! -- Set whether to add a new log to the base of the original log when the service is restarted -->

<Param name = "maxbackupindex" value = "10"/>

<Layout class = "org. Apache. log4j. patternlayout">

<Param name = "conversionpattern" value = "% P (% C: % L)-% m % N"/> <! -- Set the output file project and format -->

</Layout>

</Appender>

<Appender name = "org. zblog. zcw" class = "org. Apache. log4j. rollingfileappender">

<Param name = "file" value = "E:/study/log4j/zhuwei. Output. log"/>

<Param name = "APPEND" value = "true"/>

<Param name = "maxfilesize" value = "10240"/> <! -- Set the file size -->

<Param name = "maxbackupindex" value = "10"/>

<Layout class = "org. Apache. log4j. patternlayout">

<Param name = "conversionpattern" value = "% P (% C: % L)-% m % N"/>

</Layout>

</Appender>

<Logger name = "zcw. log"> <! -- Set the domain name limit, that is, the zcw. log domain and the following logs are output to the corresponding channel below -->

<Level value = "debug"/> <! -- Set level -->

<Appender-ref = "org. zblog. zcw"/> <! -- Corresponds to the preceding channel id -->

</Logger>

<Root> <! -- Set the channel for receiving all output -->

<Appender-ref = "org. zblog. All"/> <! -- Corresponds to the preceding channel id -->

</Root>

</Log4j: configuration>

Iii. configuration file loading method:

Import org. Apache. log4j. Logger;

Import org. Apache. log4j. propertyconfigurator;

Import org. Apache. log4j. xml. domconfigurator;

Public class log4japp {

Public static void main (string [] ARGs ){

Domconfigurator. Configure ("E:/study/log4j/log4j. xml"); // load the. xml file

// Propertyconfigurator. Configure ("E:/study/log4j/log4j. properties"); // load the. properties File

Logger log = logger. getlogger ("org. zblog. test ");

Log.info ("test ");

}

}

Log4j: Warn please initialize the log4j system properly Solution

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.