In the spring MVC project, you only need to put the log4j. xml file under the src/main/resources directory, and the log will work.
I still don't know which line of code is imported into the configuration file.
Example of a log4j. xml file:
<? XML version = "1.0" encoding = "UTF-8"?> <! Doctype log4j: configuration public "-// Apache // DTD log4j 1.2 // en" "log4j. DTD"> <log4j: configuration xmlns: log4j = "http://jakarta.apache.org/log4j/"> <! -- Use log4j: Add a jar package to the program, configure the file. xml or property, instantiate the logger object in the program, and use logger.info () and other output --> <! -- Log4j has three main components: logger, appender, and layout. I think the first two are the main ones. layout describes logger and appender --> <! -- Appenders --> <appender name = "console" class = "org. apache. log4j. consoleappender "> <Param name =" target "value =" system. out "/> <layout class =" org. apache. log4j. patternlayout "> <Param name =" conversionpattern "value =" [mediask] % d {hh: mm: SS} %-5 p [% T] % c {1}-% m % N "/> </layout> </appender> <appender name =" file "class = "org. apache. log4j. dailyrollingfileappender "> <Param name =" file "value =" $ {log. dir}/org. CC NT. med. log "/> <Param name =" APPEND "value =" true "/> <Param name =" datepattern "value = ". yyyy-mm-dd "/> <layout class =" org. apache. log4j. patternlayout "> <Param name =" conversionpattern "value =" % d [% T] %-5 p % C-% m % N "/> </layout> </appender> <! -- Application loggers --> <logger name = "org. ccnt. Med"> <level value = "debug"/> </logger> <! -- 3 rdparty loggers --> <logger name = "org. springframework. core "> <level value =" info "/> </logger> <logger name =" org. springframework. beans "> <level value =" info "/> </logger> <logger name =" org. springframework. context "> <level value =" info "/> </logger> <logger name =" org. springframework. HTTP "> <level value =" debug "/> </logger> <logger name =" org. springframework. web "> <level value =" debug "/> </logger> <! -- Root logger --> <root> <priority value = "Warn"/> <appender-ref = "console"/> </root> </log4j: configuration>