java tomcat logback_java - tomcat上的spring mvc app:slf4j找不到logback.xml,只记录到catalina.out - 堆栈内存溢出...

孔征
2023-12-01

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

原帖:

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

我用gradle(3.0)构建我的应用程序

我刚刚安装了slf4j,但它只记录到catalina.out(与post 无法找到logback.xml相同 )

我已将logback.xml文件放在我的'project \\ src \\ main \\ java'下,也放在'project \\ src \\ main \\ webapp \\ resources'下,但无论如何它都不会创建日志文件,只需将所有文件放入登录到catalina.out

从上面提到的另一篇文章中,它说把文件放在classpath下,我理解的是'project \\ src'目录

关于如何解决这个问题的任何想法都将非常感激

谢谢AHL

logback.xml:

%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n

class="ch.qos.logback.core.rolling.RollingFileAppender">

${DEV_HOME}/debug.log

%d{yyyy-MM-dd HH:mm:ss} - %msg%n

${DEV_HOME}/archived/debug.%d{yyyy-MM-dd}.%i.log

class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">

10MB

class="ch.qos.logback.core.rolling.RollingFileAppender">

${DEV_HOME}/error.log

%d{yyyy-MM-dd HH:mm:ss} - %msg%n

${DEV_HOME}/archived/error.%d{yyyy-MM-dd}.%i.log

class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">

10MB

additivity="false">

项目树:

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$

 类似资料: