Java 回写不是';t在springmvc中创建日志文件
我将logback添加到我的SpringMVC4项目中。它在控制台中工作,但不创建日志文件并将日志写入其中 我的依赖关系是Java 回写不是';t在springmvc中创建日志文件,java,spring,spring-mvc,logback,Java,Spring,Spring Mvc,Logback,我将logback添加到我的SpringMVC4项目中。它在控制台中工作,但不创建日志文件并将日志写入其中 我的依赖关系是 <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.2.3</version> </dependency> <
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
并且logback无法写入文件您确定需要此处的第一个正斜杠:
/files/log
?添加调试选项
可能会发现一些问题。我刚刚检查了一个已成功使用的配置,我的路径以一个前导的/
开始,因此请尝试/files/log
,并确保文件和日志
目录存在(例如使用mkdir-p files/log
).我在哪里创建文件/日志目录@David ConradUh,在你运行它的目录下,你想把日志文件放在哪里?不过,仔细想想,我不认为我必须亲自去查目录。我想它会创建它。我想把日志文件放在运行tomcat的spring应用程序的目录中@大卫·康拉德
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- log INFO or higher messages to the console -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- log everything to a rolling file -->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/files/log</file>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- keep 30 days' worth of history -->
<maxHistory>1</maxHistory>
</rollingPolicy>
</appender>
<!-- use AsyncAppender for lower latencies -->
<appender name="async" class="ch.qos.logback.classic.AsyncAppender">
<!--<appender-ref ref="console"/>-->
<appender-ref ref="file"/>
</appender>
<root level="debug">
<appender-ref ref="console"/>
<appender-ref ref="file"/>
</root>
</configuration>
INFO [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
|-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
|-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
|-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file /IdeaProjects/spring/target/spring-1.0/WEB-INF/classes/logback.xml]
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [console]
|-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [file]
|-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
|-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@501115326 - No compression will be used
|-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@501115326 - Will use the pattern logFile.%d{yyyy-MM-dd}.log for the active file
|-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'logFile.%d{yyyy-MM-dd}.log'.
|-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
|-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to
|-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file] - Active log file name: files/log
|-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file] - File property is set to [files/log]
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.AsyncAppender]
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [async]
|-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [file] to ch.qos.logback.classic.AsyncAppender[async]
|-INFO in ch.qos.logback.classic.AsyncAppender[async] - Attaching appender named [file] to AsyncAppender.
|-INFO in ch.qos.logback.classic.AsyncAppender[async] - Setting discardingThreshold to 51
|-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
|-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [console] to Logger[ROOT]
|-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [file] to Logger[ROOT]
|-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
|-INFO in ch.qos.logback.classic.joran.JoranConfigurator@73ae94ae - Registering current configuration as safe fallback point
|-INFO in ch.qos.logback.classic.servlet.LogbackServletContainerInitializer@16c752bf - Adding an instance of class ch.qos.logback.classic.servlet.LogbackServletContextListener to the current web-app
INFO [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization started
INFO [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing Root WebApplicationContext: startup date [Tue Aug 14 20:34:04 IRDT 2018]; root of context hierarchy
INFO [RMI TCP Connection(3)-127.0.0.1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-mvc-servlet.xml]