The lightweight web server Jetty outputs the following two log files.
By default, these log files are output to logs
directly under the directory specified by the jetty.base
property.
Jetty Reference Default Logging with Jetty's StdErrLog and Configuring Jetty Request Logs I referred to .eclipse.org/jetty/documentation/current/configuring-jetty-request-logs.html), but it was difficult to understand how to change the output destination to an arbitrary directory, so I summarized it in this article.
Log file settings are made from ʻetc / jetty-logging.xml`.
jetty-logging.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<!-- =============================================================== -->
<!-- Configure stderr and stdout to a Jetty rollover log file -->
<!-- this configuration file should be used in combination with -->
<!-- other configuration files. e.g. -->
<!-- java -jar start.jar etc/jetty-logging.xml -->
<!-- =============================================================== -->
<Configure id="logging" class="org.eclipse.jetty.util.log.Log">
<New id="ServerLog" class="java.io.PrintStream">
<Arg>
<New class="org.eclipse.jetty.util.RolloverFileOutputStream">
<Arg><Property name="jetty.logs" default="./logs"/>/yyyy_mm_dd.stderrout.log</Arg>
<Arg type="boolean">false</Arg>
<Arg type="int">90</Arg>
<Arg><Call class="java.util.TimeZone" name="getTimeZone"><Arg>GMT</Arg></Call></Arg>
<Get id="ServerLogName" name="datedFilename"/>
</New>
</Arg>
</New>
<Get name="rootLogger">
<Call name="info"><Arg>Redirecting stderr/stdout to <Ref refid="ServerLogName"/></Arg></Call>
</Get>
<Call class="java.lang.System" name="setErr"><Arg><Ref refid="ServerLog"/></Arg></Call>
<Call class="java.lang.System" name="setOut"><Arg><Ref refid="ServerLog"/></Arg></Call>
</Configure>
<Arg><Property name="jetty.logs" default="./logs"/>/yyyy_mm_dd.stderrout.log</Arg>
It is now output as yyyy_mm_dd.stderrout.log
directly under the directory specified by the jetty.logs
property ($ pwd / logs if there is no property).
As a workaround, specify the value LOG_DIR = / test / logs
in the system property of the Jetty start command and refer to LOG_DIR
in jetty-logging.xml
so that the log can be output to any directory. Will be.
$ java -DLOG_DIR=/test/logs -jar start.jar
<Arg><Property name="LOG_DIR"/>/yyyy_mm_dd.stderrout.log</Arg>
In this example, the standard output / standard error output log is output to /test/logs/yyyy_mm_dd.stderrout.log
.
Log file settings are made from ʻetc / jetty-requestlog.xml`.
jetty-requestlog.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<!-- =============================================================== -->
<!-- Configure the Jetty Request Log -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Configure Request Log -->
<!-- =========================================================== -->
<Ref refid="Handlers">
<Call name="addHandler">
<Arg>
<New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler">
<Set name="requestLog">
<New id="RequestLogImpl" class="org.eclipse.jetty.server.AsyncNCSARequestLog">
<Set name="filename"><Property name="jetty.base" default="." /><Property name="requestlog.filename" default="/logs/yyyy_mm_dd.request.log"/></Set>
<Set name="filenameDateFormat"><Property name="requestlog.filenameDateFormat" default="yyyy_MM_dd"/></Set>
<Set name="retainDays"><Property name="requestlog.retain" default="90"/></Set>
<Set name="append"><Property name="requestlog.append" default="false"/></Set>
<Set name="extended"><Property name="requestlog.extended" default="false"/></Set>
<Set name="logCookies"><Property name="requestlog.cookies" default="false"/></Set>
<Set name="LogTimeZone"><Property name="requestlog.timezone" default="GMT"/></Set>
</New>
</Set>
</New>
</Arg>
</Call>
</Ref>
</Configure>
<Set name="filename"><Property name="jetty.base" default="." /><Property name="requestlog.filename" default="/logs/yyyy_mm_dd.request.log"/></Set>
It is now output as /logs/yyyy_mm_dd.request.log
directly under the directory specified by the jetty.base
property ($ pwd if there is no property).
Unlike the standard output / standard error output log, the output destination directory and output file name are specified separately for the access log.
Note that the output file name includes the logs
directory specification by default.
As a workaround, specify the value LOG_DIR = / test / logs
in the system property of the Jetty start command and refer to LOG_DIR
in jetty-requestlog.xml
as in the standard output / standard error output log. This will allow you to output the log to any directory.
$ java -DLOG_DIR=/test/logs -jar start.jar
<Set name="filename"><Property name="LOG_DIR"/><Property name="requestlog.filename" default="/yyyy_mm_dd.request.log"/></Set>
The logs
directory is removed from the output file name of the requestlog.filename
property so that only the file name is used.
In this example, the access log is output to /test/logs/yyyy_mm_dd.request.log
.
Recommended Posts