【发布时间】:2014-02-26 23:50:35
【问题描述】:
我正在 Centos 6.x 的 Jetty 服务安装中部署 scala lift 应用程序。我已经尝试了一切以更改日志级别和模式,但总是得到调试和截断消息。
我已经按照官方文档来配置 logback,就像我更改了与日志记录相关的每个配置文件一样,但没有运气。当运行应用程序时,maven 可以完美运行mvn jetty:run,但是在服务器中部署战争时可以配置日志记录。
我已阅读并尝试过:
Jetty 6 always generates debug logs? http://www.eclipse.org/jetty/documentation/current/configuring-logging.html
有人遇到过这种问题吗?
[编辑]
在 src/main/resources/props 我有一个名为 default.props 的空文件。 (0 字节)
在 src/main/resources/ 我有一个 jetty-logback.xml 文件。
<?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>
此文件在使用 maven 运行时有效。直接在 jetty 中部署时,我按照所有登录 jetty 的教程将此文件移动到 Jetty_HOME/resources。
启动码头时没有额外的 JVM 运行时参数。
[编辑 2]
在 source/main/resources/props 我有一个名为 production.default.logback.xml 的文件。该文件的内容与第一个 EDIT 中列出的 logback 文件 jetty-logback.xml 相同。
我在没有 running.mode 属性的情况下运行。即使那样我也尝试过使用 run.mode=development 但结果是一样的。
我不使用 SBT,我使用 scala maven 插件。 pom的配置有点复杂,因为我们有三个级别的pom配置。从 lift web 应用程序的 pom 开始(孩子):
<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>
之后父项目就有了这个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>
最后,我所有项目的父级是:
<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>
我知道它看起来很复杂,但我几乎可以肯定这个问题与依赖管理无关,因为通过 logback 进行的日志记录适用于部署在 tomcat 中的所有模块。只有在 jetty 中部署的 lift webapp 失败了……我检查了可部署的 lift war 的包含,它包含了 logback 所需的所有依赖项。
【问题讨论】:
-
您是否阅读过如何在 Lift wiki 中配置日志记录? assembla.com/spaces/liftweb/wiki/Logging
-
嗨,戴夫,是的,我愿意,使用该文档我能够在使用 maven 运行时配置日志记录。事实上,在这一点上,我认为问题不仅仅与码头有关,我会尝试在我的应用程序中嵌入码头,看看是否有什么变化。
-
您是否使用 -Drun.mode=production(或其他值)启动您的应用程序?如果您需要更多帮助,请发布您用于配置日志记录的代码以及 source/main/resources/props 文件夹的内容
-
完成,我不会使用 -Drun.mode=production 启动应用程序,我会尝试发布我的发现。
-
使用 -Drun.mode=production 获得相同的行为。这真的很令人沮丧,我收到了很多调试消息,所以我的内存很快就满了,当我在应用程序中遇到错误时,日志就没用了,因为所有的行都被截断了,我无法读取完整的堆栈跟踪。 :(