rsan
rsan

Reputation: 1887

Configuring lift application logging in a service jetty installation

I'm deploying a scala lift application in a Jetty service installation in Centos 6.x. I have tried everything in order to change the log level and pattern but always get debug and truncated messages.

I have followed the official documentation in order to configure logback, in the same way I have change every single configuration file related to logging without luck. When running the app thry maven works perfectly mvn jetty:run but when deploying the war in the server can configure logging.

I have readed and tried:

Jetty 6 always generates debug logs? http://www.eclipse.org/jetty/documentation/current/configuring-logging.html

Have anyone faced this kind of problem?

[Edit]

Inside src/main/resources/props I have an empty file with name default.props. (0 bytes)

Inside src/main/resources/ I have a jetty-logback.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d %5p | %.-1000m %n</pattern>
        </encoder>
    </appender>


    <logger name="mx.ssf.sicom.brokerGaspar">
        <level value="INFO" />
    </logger>

    <logger name="mx.ssf.sicom.gasparIntegration">
        <level value="INFO" />
    </logger>

    <logger name="mx.ssf.sicom.commProtocol">
        <level value="INFO" />
    </logger>

<!--    <logger name="org.hibernate"> -->
<!--        <level value="DEBUG" /> -->
<!--    </logger> -->


    <logger name="mx.ssf.sicom.operationalServices">
        <level value="INFO" />
    </logger>

    <logger name="mx.ssf.sicom.catalogsServices.brokerapiImpl">
        <level value="INFO" />
    </logger>

    <root>
        <level value="INFO" />
        <appender-ref ref="CONSOLE" />
    </root>
</configuration>

This file works when running with maven. When deploying directly in jetty I move this file to Jetty_HOME/resources following all the tutorials of logging in jetty.

No extra JVM runtime params when starting jetty.

[Edit 2]

In the source/main/resources/props I have a file with name production.default.logback.xml. The contents of that file are the same as the logback file listed jetty-logback.xml in the first EDIT.

I was running without running.mode property. Even then I have tried using run.mode=development but the result is the same.

I don't use SBT, I use the scala maven plugin. The pom's configuration is a little complicated because we have three levels of pom configurations. Starting with the pom of the lift web application (the child):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>MyLiftApp</artifactId>
    <parent>
        <artifactId>LiftApp-project</artifactId>
        <groupId>mygroupid</groupId>
        <version>0.1.0-SNAPSHOT</version>
        <relativePath>..</relativePath>
    </parent>
    <packaging>war</packaging>
    <name>MyAppName</name>

    <properties>
        <maven.scaladoc.vscaladocVersion>1.2-m1</maven.scaladoc.vscaladocVersion>
        <vscaladoc.links.liftweb.pathsufix>scaladocs/</vscaladoc.links.liftweb.pathsufix>
        <vscaladoc.links.liftweb.baseurl>http://scala-tools.org/mvnsites/liftweb</vscaladoc.links.liftweb.baseurl>
        <scala.version>2.9.1</scala.version>
    </properties>

    <build>
        <sourceDirectory>src/main/scala</sourceDirectory>
        <testSourceDirectory>src/test/scala</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <version>2.15.2</version>

                <executions>
                    <execution>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <launchers>
                        <launcher>
                            <id>mainLauncher</id>
                            <mainClass>
                                mx.ssf.sicom.brokerGaspar.Main
                            </mainClass>
                            <jvmArgs>
                                <jvmArg>-DdataAccess.props.dir=${project.build.directory}/classes/</jvmArg>
                            </jvmArgs>
                        </launcher>
                    </launchers>
                    <scalaVersion>${scala.version}</scalaVersion>
                    <sendJavaToScalac>true</sendJavaToScalac>
                    <args>
                        <!--arg>-target:jvm-1.5</arg -->
                        <arg>-g:vars</arg>
                        <arg>-deprecation</arg>
                        <arg>-dependencyfile</arg>
                        <arg>${project.build.directory}/.scala_dependencies</arg>
                    </args>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12</version>
                <configuration>
                    <parallel>methods</parallel>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.25</version>
                <configuration>
                    <systemProperties>
                        <systemProperty>
                            <name>logback.configurationFile</name>
                            <value>${project.build.outputDirectory}/jetty-logback.xml</value>
                        </systemProperty>
                    </systemProperties>
                    <contextPath>/</contextPath>
                    <scanIntervalSeconds>0</scanIntervalSeconds>
                    <connectors>
                        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                            <port>8100</port>
                        </connector>
                    </connectors>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.sf.alchim</groupId>
                <artifactId>yuicompressor-maven-plugin</artifactId>
                <version>0.7.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compress</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <nosuffix>true</nosuffix>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>mx.ssf.sicom</groupId>
            <artifactId>JPADataAccess</artifactId>
            <version>0.1.0-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.rxtx</groupId>
            <artifactId>rxtx</artifactId>
            <version>2.1.7</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>net.liftweb</groupId>
            <artifactId>lift-mapper_2.9.1</artifactId>
            <version>2.4-M4</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty</artifactId>
            <version>6.1.25</version>
            <scope>test</scope>
        </dependency>
        <!-- for LiftConsole -->
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-compiler</artifactId>
            <version>${scala.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.databinder</groupId>
            <artifactId>dispatch-http_2.9.1</artifactId>
            <version>0.8.8</version>
        </dependency>
        <dependency>
            <groupId>mx.ssf.sicom</groupId>
            <artifactId>CommProtocol</artifactId>
            <version>0.1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>mx.ssf.sicom</groupId>
            <artifactId>GasparIntegration</artifactId>
            <version>0.1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>mx.ssf.sicom</groupId>
            <artifactId>ScalaCommons</artifactId>
            <version>0.1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>mx.ssf.sicom</groupId>
            <artifactId>CorporateStructureServiceBrokerImpl</artifactId>
            <version>0.1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>mx.ssf.sicom</groupId>
            <artifactId>BrokerMessagingService</artifactId>
            <version>0.1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>mx.ssf.sicom</groupId>
            <artifactId>OperationalServicesBrokerImpl</artifactId>
            <version>0.1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>mx.ssf.sicom</groupId>
            <artifactId>CatalogsServiceBrokerImpl</artifactId>
            <version>0.1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

</project>

After that the parent project have this pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>TheParent-project</artifactId>
    <version>0.1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>TheParent-project</name>

    <parent>
        <groupId>thegroupid</groupId>
        <artifactId>TheParent-Solution</artifactId>
        <version>1</version>
    </parent>

    <modules>
        <module>MyLiftApp</module>
        <module>OtherModule</module>
        <module>OtherModule2</module>
        <module>OtherModule3</module>
        <module>OtherModule4</module>
        <module>OtherModule5</module>
        <module>OtherModule6</module>
    </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5</version>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>mygroupid</groupId>
                <artifactId>CommonDomain</artifactId>
                <version>0.1.0-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

And lastly, the parent of all my projects is:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>mygroupid</groupId>
        <artifactId>TheGreat-Solution</artifactId>
        <version>1</version>
        <packaging>pom</packaging>

        <properties>
                <spring.version>3.1.1.RELEASE</spring.version>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <hibernate.version>4.1.4.Final</hibernate.version>
                <hibernate.validator.version>4.3.0.Final</hibernate.validator.version>
        </properties>

        <organization>
                <name>My company</name>
                <url>www.www.www</url>
        </organization>

        <issueManagement>
                <url>http://mybt.com</url>
                <system>MantisBT</system>
        </issueManagement>

        <ciManagement>
                <system>Jenkins</system>
                <url>http://myci.com</url>
        </ciManagement>



        <dependencies>
                <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-core</artifactId>
                        <version>${spring.version}</version>
                        <exclusions>
                                <exclusion>
                                        <artifactId>commons-logging</artifactId>
                                        <groupId>commons-logging</groupId>
                                </exclusion>
                        </exclusions>
                </dependency>
                <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-beans</artifactId>
                        <version>${spring.version}</version>
                </dependency>
                <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-context-support</artifactId>
                        <version>${spring.version}</version>
                </dependency>
                <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <version>4.10</version>
                </dependency>
                <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-test</artifactId>
                        <version>${spring.version}</version>
                </dependency>
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                        <version>1.6.6</version>
                </dependency>
                <dependency>
                        <groupId>ch.qos.logback</groupId>
                        <artifactId>logback-classic</artifactId>
                        <version>1.0.6</version>
                </dependency>
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>jcl-over-slf4j</artifactId>
                        <version>1.6.4</version>
                </dependency>
                <dependency>
                        <groupId>org.mockito</groupId>
                        <artifactId>mockito-all</artifactId>
                        <version>1.9.0</version>
                </dependency>
        </dependencies>

        <dependencyManagement>
                <dependencies>
                        <dependency>
                                <groupId>org.hibernate</groupId>
                                <artifactId>hibernate-entitymanager</artifactId>
                                <version>${hibernate.version}</version>
                        </dependency>
                        <dependency>
                                <groupId>org.hibernate</groupId>
                                <artifactId>hibernate-validator</artifactId>
                                <version>${hibernate.validator.version}</version>
                        </dependency>
                        <dependency>
                                <groupId>org.hibernate</groupId>
                                <artifactId>hibernate-envers</artifactId>
                                <version>${hibernate.version}</version>
                        </dependency>
                        <dependency>
                                <groupId>org.hibernate</groupId>
                                <artifactId>hibernate-ehcache</artifactId>
                                <version>${hibernate.version}</version>
                        </dependency>
                </dependencies>
        </dependencyManagement>

        <build>
                <!-- To define the plugin version in your parent POM -->
                <pluginManagement>
                        <plugins>
                                <plugin>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-release-plugin</artifactId>
                                        <version>2.5</version>
                                </plugin>
                        </plugins>
                </pluginManagement>

                <plugins>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-compiler-plugin</artifactId>
                                <version>2.3.2</version>
                                <configuration>
                                        <source>1.6</source>
                                        <target>1.6</target>
                                        <encoding>UTF-8</encoding>
                                </configuration>
                        </plugin>
                </plugins>
        </build>

</project>

I know it looks complicated but I'm almost sure the problem is not related with dependency management because the logging via logback works in all the modules deployed in tomcat. Only the lift webapp deployed in jetty fails...... I check the contains of the deployable lift war and it contains all the dependencies required by logback.

Upvotes: 1

Views: 328

Answers (1)

Dave Whittaker
Dave Whittaker

Reputation: 3102

Try this:

  1. When starting your jetty instance do not include a -Drun.mode flag
  2. copy your jetty-logback.xml file to /src/main/resources/props/default.logback.xml

If that doesn't work, Lift can be passed a config file directly by using code like the following in your Boot class

Logger.setup = Full(Logback.withFile(pathToLogbackxml))

Upvotes: 1

Related Questions