java service wrapper日志参数设置及优化

Posted 太白的技术博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java service wrapper日志参数设置及优化相关的知识,希望对你有一定的参考价值。

一般在容器比如tomcat/weblogic中运行时,我们都是通过log4j控制日志输出的,因为我们现在很多服务端使用java service wrapper(至于为什么使用jsw,原先是比较排斥使用的,但是当一台服务器上部署10来个应用时,我们无条件的选择了jsw,因为不需要折腾和规划这么多的端口了,尤其是我们还是自己的RPC时,每个应用的端口需求从4个变成了1个)进行启动和管理,而JSW还有自己的日志格式,可以说在log4j上又套了一层马甲,默认的日志格式并不是输出原始log4j信息,因为我们已经使用log4j管理了,所以不再需要JSW的马甲,其通过如下参数控制日志格式、大小以及滚动。

# Format of output for the console.  (See docs for formats)
wrapper.console.format=PM

# Log Level for console output.  (See docs for log levels)
wrapper.console.loglevel=INFO

# Log file to use for wrapper output logging.
wrapper.logfile=../logs/osm-runtime.log

# Format of output for the log file.  (See docs for formats)
wrapper.logfile.format=M

# Log Level for log file output.  (See docs for log levels)
wrapper.logfile.loglevel=INFO

# Maximum size that the log file will be allowed to grow to before
#  the log is rolled. Size is specified in bytes.  The default value
#  of 0, disables log rolling.  May abbreviate with the ‘k‘ (kb) or
#  ‘m‘ (mb) suffix.  For example: 10m = 10 megabytes.
wrapper.logfile.maxsize=10m

# Maximum number of rolled log files which will be allowed before old
#  files are deleted.  The default value of 0 implies no limit.
wrapper.logfile.maxfiles=100

# Log Level for sys/event log output.  (See docs for log levels)
wrapper.syslog.loglevel=NONE

format的取值如下(贴出来纯属官网依赖google的cdn或嵌入广告,不FQ打开实在慢):

Format to use for logging to the log file. Logging has been intentionally kept simple.

The format consists of the following tokens:

  • L‘ for log level,
  • P‘ for prefix,
  • D‘ (Since ver. 3.1.0) for thread,
  • T‘ for time,
  • Z‘ for millisecond time,
  • R‘ quite duration milliseconds showing the time since the previous JVM output,
  • U‘ (Since ver. 3.5.0) for approximate uptime in seconds (based on internal tick counter and is valid up to one year from startup),
  • G‘ (Since ver. 3.5.8) for time in milliseconds it tool to log the previous log entry (See wrapper.log.warning.threshold for more information),
  • W‘ (Since ver. 3.5.30) for the PID of the Wrapper process.
  • J‘ (Since ver. 3.5.30) for the PID of the Java process (if the JVM is up).
  • M‘ for message.

If the format contains these tokens above, then it will be output with the specified formation. The order of the tokens does not affect the way the log appears, but the ‘M‘ (for message) token should usually be placed last as it is the only column without a uniform width. If the property is missing tokens or commented out, then the default value ‘LPTM‘ will be used.

Logging Disable:

Setting the property to a blank value will cause file logging to be disabled.

wrapper.logfile.format=

设置日志刷新间隔:
wrapper.logfile.flush.timeout=min(5,1*进程数)


以上是关于java service wrapper日志参数设置及优化的主要内容,如果未能解决你的问题,请参考以下文章

Java Service Wrapper简介与使用

Java Service Wrapper简介与使用(转)

Java Service Wrapper 使用(windows)

详解Maven项目利用java service wrapper将Java程序生成Windows服务

Java Service Wrapper 浅谈

使用Java Service Wrapper将java程序作为linux服务并且开机自动启动