Update: Question has been solved. The problem was that I tried to put my log files into a directory to which tomcat7 user did not have access. See answers and comments below.
Original post:
I have a spring mvc app that runs on tomcat
I build my app with gradle (3.0)
I have just installed slf4j but it only logs to catalina.out (same as in post unable to find logback.xml)
I have put the logback.xml file both under my 'project\src\main\java' and also under 'project\src\main\webapp\resources', but either way it doesn't create the log files, just puts all logs into catalina.out
From the other post mentioned above, it says to put the file under the classpath, which I understand is the 'project\src' directory
Any ideas on how to work this out would be much appreciated
Thanks AHL
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>
project tree:
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 user that runs the server process:
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$
permissions of log folder:
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$