Change the logback configuration file path in the java web project
My small Website: http://51kxd.com/welcome to visit when you are not happy, adjust the mood
Configuration in web. xml:
LogbackConfigLocation
File:/datum/Data/conf/config/logback. xml
LogbackConfigLocation
File: E: \ datum \ data \ conf \ logback. xml
File: Yes.
Com. cxfmvcstu. comn. LogbackConfigListener
LogbackConfigListener is your own implementation class
Import javax. servlet. servletContextEvent; import javax. servlet. servletContextListener; import org. slf4j. logger; import org. slf4j. loggerFactory; import org. springframework. core. io. urlResource; import ch. qos. logback. classic. loggerContext; import ch. qos. logback. classic. joran. joranaggregator; import ch. qos. logback. core. joran. spi. joranException;/*** @ description * @ path com. cxfmvcstu. comn. logbackConfigListener * @ author lijun. justin * @ time June 27, 2015 8:13:19 */public class LogbackConfigListener implements ServletContextListener {private static final Logger logger = LoggerFactory. getLogger (LogbackConfigListener. class); private static final String CONFIG_LOCATION = "logbackConfigLocation"; @ Overridepublic void contextInitialized (ServletContextEvent event) {// from the web. string logbackConfigLocation = event. getServletContext (). getInitParameter (CONFIG_LOCATION); String fn = event. getServletContext (). getRealPath (logbackConfigLocation); try {UrlResource urlResource = new UrlResource (logbackConfigLocation); LoggerContext loggerContext = (LoggerContext) LoggerFactory. getILoggerFactory (); loggerContext. reset (); JoranConfigurator joranConfigurator = new JoranConfigurator (); joranConfigurator. setContext (loggerContext); // joranConfigurator. doConfigure (fn); joranConfigurator. doConfigure (urlResource. getFile (). getAbsolutePath (); logger. debug ("loaded slf4j configure file from {}", fn);} catch (JoranException e) {logger. error ("can loading slf4j configure file from" + fn, e);} catch (Exception e) {logger. error (e. getMessage (), e) ;}@overridepublic void contextDestroyed (ServletContextEvent event ){}}
It depends on the UrlResource class of spring. Useless code in it, and readers can streamline it themselves
Logback. xml configuration example:
% Date [% thread] %-5 level % logger {80}-% msg % n
Class = "ch. qos. logback. core. rolling. RollingFileAppender">
INFO
ACCEPT
DENY
D:/logs/INFO. % d {yyyy-MM-dd}. log
30
% Date [% thread] %-5 level % logger {80}-% msg % n
ERROR
ACCEPT
DENY
D:/logs/error. % d {yyyy-MM-dd}. log
30
% Date [% thread] %-5 level % logger {80}-% msg % n
My small Website: http://51kxd.com/welcome to visit
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.