无法使码头使用logback进行日志记录 [英] Unable to make jetty use logback for logging

查看:90
本文介绍了无法使码头使用logback进行日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照此页面的要求在Amazon EC2实例上安装了码头.我的(Ubuntu 14.04.2 LTS).码头正在运行.但是,我无法使其使用logback进行日志记录.以下是相关信息.我在这里做错了什么?

I followed this page to install jetty on a Amazon EC2 instance of mine (Ubuntu 14.04.2 LTS). Jetty is running. However, I can't make it use logback for logging. Below are relevant information. What did I do wrong here?

服务检查

$ service jetty check
Checking arguments to Jetty:
START_INI      =  /opt/jetty/start.ini
START_D        =  /opt/jetty/start.d
JETTY_HOME     =  /opt/jetty
JETTY_BASE     =  /opt/jetty
JETTY_CONF     =  /opt/jetty/etc/jetty.conf
JETTY_PID      =  /tmp/jetty.pid
JETTY_START    =  /opt/jetty/start.jar
JETTY_LOGS     =  /opt/jetty/logs
JETTY_STATE    =  /opt/jetty/jetty.state
CLASSPATH      =
JAVA           =  /usr/bin/java
JAVA_OPTIONS   =  -Djetty.logs=/opt/jetty/logs -Djetty.home=/opt/jetty -Djetty.base=/opt/jetty -Djava.io.tmpdir=/tmp
JETTY_ARGS     =  jetty.state=/opt/jetty/jetty.state jetty-started.xml
RUN_CMD        =  /usr/bin/java -Djetty.logs=/opt/jetty/logs -Djetty.home=/opt/jetty -Djetty.base=/opt/jetty -Djava.io.tmpdir=/tmp -jar /opt/jetty/start.jar jetty.state=/opt/jetty/jetty.state jetty-started.xml

/etc/default/jetty

$ cat /etc/default/jetty
# Defaults for jetty see /etc/init.d/jetty for more

# change to 0 to allow Jetty to start
NO_START=0

# change to 'no' or uncomment to use the default setting in /etc/default/rcS
VERBOSE=yes

# Run Jetty as this user ID (default: jetty)
# Set this to an empty string to prevent Jetty from starting automatically
JETTY_USER=jetty

# Listen to connections from this network host
# Use 0.0.0.0 as host to accept all connections.
# Uncomment to restrict access to localhost
JETTY_HOST=0.0.0.0

# The network port used by Jetty
JETTY_PORT=8080

# Timeout in seconds for the shutdown of all webapps
JETTY_SHUTDOWN=30

# Additional arguments to pass to Jetty
#JETTY_ARGS=

# Extra options to pass to the JVM
#JAVA_OPTIONS="-Xmx256m -Djava.awt.headless=true -Djava.library.path=/usr/lib"

# Home of Java installation.
JAVA=/usr/bin/java
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
JETTY_HOME=/opt/jetty

# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
# defined in /etc/default/jetty). Should contain a list of space separated directories.
#JDK_DIRS="/usr/lib/jvm/default-java /usr/lib/jvm/java-6-sun"

# Java compiler to use for translating JavaServer Pages (JSPs). You can use all
# compilers that are accepted by Ant's build.compiler property.
#JSP_COMPILER=jikes

# Jetty uses a directory to store temporary files like unpacked webapps
#JETTY_TMP=/var/cache/jetty

# Jetty uses a config file to setup its boot classpath
#JETTY_START_CONFIG=/etc/jetty/start.config

# Default for number of days to keep old log files in /var/log/jetty/
#LOGFILE_DAYS=14

/opt/jetty/etc/jetty.conf

$ cat /opt/jetty/etc/jetty.conf
# ========================================================
# jetty.conf Configuration for jetty.sh script
# --------------------------------------------------------
# This file is used by the jetty.sh script to provide
# extra configuration arguments for the start.jar command
# created by that script.
#
# Each line in this file becomes an arguement to start.jar
# in addition to those found in the start.ini file
# =======================================================
#jetty-logging.xml
jetty-started.xml

/opt/jetty/modules/logging.mod

$ cat /opt/jetty/modules/logging.mod
#
# Jetty std err/out logging
#

[name]
logging

[files]
logs/

[lib]
lib/logging/*.jar
resources/

[ini-template]
## Logging Configuration
# Configure jetty logging for default internal behavior STDERR output
# -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog

# Configure jetty logging for slf4j
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog

# Configure jetty logging for java.util.logging
# -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog

# STDERR / STDOUT Logging
# Number of days to retain logs
# jetty.log.retain=90
# Directory for logging output
# Either a path relative to ${jetty.base} or an absolute path
# jetty.logs=logs

/opt/jetty/resources/logback.xml

$ cat /opt/jetty/resources/logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!-- Insert the current time formatted as "yyyyMMdd'T'HHmmss" under
       the key "bySecond" into the logger context. This value will be
       available to all subsequent configuration elements. -->
    <timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"/>

    <!-- console appender -->
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{100} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/opt/jetty/logs/server.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <fileNamePattern>/opt/jetty/logs/server.%d{yyyy-MM-dd}.log</fileNamePattern>

            <!-- keep 30 days' worth of history -->
            <maxHistory>30</maxHistory>
        </rollingPolicy>

        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{100} - %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="org.eclipse.jetty" level="INFO"/>
    <logger name="org.springframework" level="INFO"/>
    <logger name="org.apache" level="INFO"/>

    <root level="DEBUG">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="FILE" />
    </root>

</configuration>

/opt/jetty/start.ini

$ cat /opt/jetty/start.ini
#===========================================================
# Jetty Startup
#
# Starting Jetty from this {jetty.home} is not recommended.
#
# A proper {jetty.base} directory should be configured, instead
# of making changes to this {jetty.home} directory.
#
# See documentation about {jetty.base} at
# http://www.eclipse.org/jetty/documentation/current/startup.html
#
# A demo-base directory has been provided as an example of
# this sort of setup.
#
# $ cd demo-base
# $ java -jar ../start.jar
#
#===========================================================

# To disable the warning message, comment the following line
--module=home-base-warning


# ---------------------------------------
# Module: server
--module=server
##
## Server Threading Configuration
##
# minimum number of threads
threads.min=10
# maximum number of threads
threads.max=200
# thread idle timeout in milliseconds
threads.timeout=60000
# buffer size for output
jetty.output.buffer.size=32768
# request header buffer size
jetty.request.header.size=8192
# response header buffer size
jetty.response.header.size=8192
# should jetty send the server version header?
jetty.send.server.version=true
# should jetty send the date header?
jetty.send.date.header=false
# What host to listen on (leave commented to listen on all interfaces)
#jetty.host=0.0.0.0
# Dump the state of the Jetty server, components, and webapps after startup
jetty.dump.start=false
# Dump the state of the Jetty server, before stop
jetty.dump.stop=false
# Enable delayed dispatch optimisation
jetty.delayDispatchUntilContent=false

# ---------------------------------------
# Module: deploy
--module=deploy
## DeployManager configuration
# Monitored Directory name (relative to jetty.base)
# jetty.deploy.monitoredDirName=webapps


# ---------------------------------------
# Module: websocket
--module=websocket

# ---------------------------------------
# Module: ext
--module=ext

# ---------------------------------------
# Module: resources
--module=resources

# ---------------------------------------
# Module: jsp
--module=jsp
# JSP Configuration

# Select JSP implementation, choices are
#   glassfish : The reference implementation
#               default in jetty <= 9.1
#   apache    : The apache version
#               default jetty >= 9.2
jsp-impl=apache

# To use a non-jdk compiler for JSP compilation when using glassfish uncomment next line
# -Dorg.apache.jasper.compiler.disablejsr199=true

# ---------------------------------------
# Module: jstl
--module=jstl
# JSTL Configuration
# The glassfish jsp-impl includes JSTL by default and this module
# is not required to activate it.
# The apache jsp-impl does not include JSTL by default and this module
# is required to put JSTL on the container classpath


#
# Initialize module logging
#
--module=logging

# ---------------------------------------
# Module: http
--module=http
### HTTP Connector Configuration
-Djava.net.preferIPv4Stack=true

## HTTP port to listen on
jetty.port=8080

## HTTP idle timeout in milliseconds
http.timeout=30000

## HTTP Socket.soLingerTime in seconds. (-1 to disable)
# http.soLingerTime=-1

## Parameters to control the number and priority of acceptors and selectors
# http.selectors=1
# http.acceptors=1
# http.selectorPriorityDelta=0
# http.acceptorPriorityDelta=0

推荐答案

运行以下命令,然后 Jetty 做所有事情:

Run the following command and Jetty do all the things:

[my-base]$ java -jar ../start.jar --add-to-start=logging-logback


更多配置: https://www.eclipse.org/jetty/documentation/jetty-9/index.html#configuring-logging

这篇关于无法使码头使用logback进行日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆