gpt4 book ai didi

java - tomcat : slf4j doesn't find logback. xml 上的 spring mvc 应用程序,仅记录到 catalina.out

转载 作者:行者123 更新时间:2023-11-28 22:07:37 25 4
gpt4 key购买 nike

更新:问题已解决。问题是我试图将日志文件放入 tomcat7 用户无权访问的目录中。请参阅下面的答案和评论。

原帖:

我有一个在 tomcat 上运行的 spring mvc 应用

我使用 gradle (3.0) 构建我的应用

我刚刚安装了 slf4j,但它只记录到 catalina.out(与帖子 unable to find logback.xml 中的相同)

我已将 logback.xml 文件放在我的“project\src\main\java”和“project\src\main\webapp\resources”下,但无论哪种方式都不会创建日志文件,只是将所有日志放入 catalina.out

上面那个帖子说要把文件放在classpath下,我理解的是'project\src'目录

任何关于如何解决这个问题的想法将不胜感激

谢谢阿尔法

logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<!-- *** CONFIGURE APPLICATION LOG DIRECTORY *** -->
<property name="DEV_HOME" value="/var/lib/tomcat7/logs/spring4-1" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>

<appender name="FILE-AUDIT"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${DEV_HOME}/debug.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} - %msg%n
</Pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${DEV_HOME}/archived/debug.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>

</appender>

<appender name="FILE-ERROR"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${DEV_HOME}/error.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} - %msg%n
</Pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${DEV_HOME}/archived/error.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>

</appender>

<!-- Send logs to both console and file audit -->
<logger name="com.concretepage" level="debug"
additivity="false">
<appender-ref ref="FILE-AUDIT" />
<appender-ref ref="STDOUT" />
</logger>

<root level="error">
<appender-ref ref="FILE-ERROR" />
</root>

</configuration>

项目树:

vagrant@precise32:/vagrant/Spring4RESTAngularJS$ tree .
.
|-- build
| |-- classes
| | `-- main
| | `-- com
| | `-- concretepage
| | |-- config
| | | |-- AppConfig.class
| | | |-- DBConfig.class
| | | `-- WebAppInitializer.class
| | |-- controller
| | | `-- PersonController.class
| | |-- dao
| | | |-- IPersonDAO.class
| | | `-- PersonDAO.class
| | |-- entity
| | | `-- Person.class
| | `-- service
| | |-- IPersonService.class
| | `-- PersonService.class
| |-- dependency-cache
| |-- libs
| | `-- spring4-1.war
| |-- resources
| | `-- main
| | `-- logback.xml
| `-- tmp
| |-- compileJava
| | `-- emptySourcePathRef
| `-- war
| `-- MANIFEST.MF
|-- build.gradle
|-- deploy.sh
`-- src
`-- main
|-- java
| `-- com
| `-- concretepage
| |-- config
| | |-- AppConfig.java
| | |-- DBConfig.java
| | `-- WebAppInitializer.java
| |-- controller
| | `-- PersonController.java
| |-- dao
| | |-- IPersonDAO.java
| | `-- PersonDAO.java
| |-- entity
| | `-- Person.java
| `-- service
| |-- IPersonService.java
| `-- PersonService.java
|-- resources
| `-- logback.xml
`-- webapp
|-- resources
| |-- css
| | `-- style.css
| |-- js
| | |-- app.js
| | `-- lib
| | |-- angular.min.js
| | `-- angular-resource.min.js
| `-- sql
| `-- db.sql
`-- WEB-INF
`-- view
`-- home.jsp

37 directories, 30 files
vagrant@precise32:/vagrant/Spring4RESTAngularJS$

build.gradle:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
archivesBaseName = 'spring4'
version = '1'
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web:1.3.3.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.3.3.RELEASE'
compile 'org.hibernate:hibernate-core:4.3.6.Final'
compile 'mysql:mysql-connector-java:5.1.31'
compile 'commons-dbcp:commons-dbcp:1.4'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat:1.3.3.RELEASE'
compile "ch.qos.logback:logback-classic:1.1.3"
compile "org.slf4j:log4j-over-slf4j:1.7.13"
}
configurations.all {
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "log4j", module: "log4j"
}
sourceSets {
main {
resources {
srcDirs "src/main/resources"
}
}
}

运行服务器进程的tomcat用户:

vagrant@precise32:/vagrant/Spring4RESTAngularJS$ ps auxwww | grep -v grep | grep tomcat
tomcat7 2435 3.2 77.0 1238660 291328 ? Sl 14:13 0:16 /usr/lib/jvm/java-7-oracle/bin/java -Djava.util.logging.config.file=/var/lib/tomcat7/conf/logging.properties -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms512m -Xmx1024m -Djava.endorsed.dirs=/usr/share/tomcat7/endorsed -classpath /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat7 -Dcatalina.home=/usr/share/tomcat7 -Djava.io.tmpdir=/tmp/tomcat7-tomcat7-tmp org.apache.catalina.startup.Bootstrap start
vagrant@precise32:/vagrant/Spring4RESTAngularJS$

日志文件夹的权限:

vagrant@precise32:/vagrant/Spring4RESTAngularJS$ ll /home/vagrant/
total 72
drwxr-xr-x 7 vagrant vagrant 4096 Sep 2 19:04 ./
drwxr-xr-x 3 root root 4096 Sep 14 2012 ../
-rw------- 1 vagrant vagrant 8574 Sep 3 09:31 .bash_history
-rw-r--r-- 1 vagrant vagrant 220 Sep 14 2012 .bash_logout
-rw-r--r-- 1 vagrant vagrant 3486 Sep 14 2012 .bashrc
drwx------ 2 vagrant vagrant 4096 Sep 14 2012 .cache/
drwxrwxr-x 6 vagrant vagrant 4096 Aug 28 20:01 .gradle/
drwxrwxr-x 2 vagrant vagrant 4096 Sep 2 19:04 logs/
drwxrwxr-x 3 vagrant vagrant 4096 Aug 27 21:59 .m2/
-rw------- 1 vagrant vagrant 1155 Aug 30 22:28 .mysql_history
-rwxr-xr-x 1 vagrant vagrant 6487 Sep 14 2012 postinstall.sh*
-rw-r--r-- 1 vagrant vagrant 675 Sep 14 2012 .profile
drwx------ 2 vagrant vagrant 4096 Aug 27 08:37 .ssh/
-rw-r--r-- 1 vagrant vagrant 0 Sep 14 2012 .sudo_as_admin_successful
-rw------- 1 vagrant vagrant 6 Sep 14 2012 .vbox_version
-rw------- 1 vagrant vagrant 12 Sep 14 2012 .veewee_version
vagrant@precise32:/vagrant/Spring4RESTAngularJS$

最佳答案

你是如何启动你的服务器的?您确定运行服务器进程的用户有权访问/home/vagrant/logs 目录吗?

此外,在 logback.xml 中,尝试设置调试属性:

<configuration debug="true"> 

这应该会向 catalina.out 输出大量附加信息如果您的 logback.xml 被提取。

关于java - tomcat : slf4j doesn't find logback. xml 上的 spring mvc 应用程序,仅记录到 catalina.out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39289204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com