解决jetty7.x log日志异常巨大问题

简介:

最近从jetty6升级到了jetty7发现硬盘空间动不动就满了,我找... 我找.... 我找原因.... 发现是jetty7 logs目录搞得鬼,仅仅是个开发环境,1天1GB的日志,疯了! 这要是弄到生产环境还不完蛋啦!!我相信jetty的开发者不会这么缺心眼的、少智慧的,于是乎googling.....


E文太差先找中文的,发现了两位网友写的文章,说jetty自己实现了log系统,需要复写这个类.....  当时晕倒,不用这么麻烦吧。。。 于是觉然的开始 googling E文,终于找到了解决办法


jetty7有两套log系统,默认使用自己的 org.eclipse.jetty.util.log 如果配置来log4j则使用log4j。


在${jetty.home}/lib/ext 放入log4j jar包


在.jettyrc中加入 (jettyrc是什么我就不解释了)


-Dlog4j.configuration=file:/home/jetty/app/jetty7/resources/log4j.properties


# This is not needed by Jetty - but it helps with many web apps.

 

log4j.rootLogger=WARN, stdout

 

log4j.appender.stdout=org.apache.log4j.RollingFileAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] %t $

log4j.appender.stdout.File=${log4j.logdir}/stderrout.log

log4j.appender.stdout.MaxFileSize=204800KB

log4j.appender.stdout.MaxBackupIndex=10


 


之后修改etc/jetty-logging.xml


<?xml version="1.0"?>

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.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="Server" class="org.eclipse.jetty.server.Server">

 

    <New id="ServerLog" class="java.io.PrintStream">

      <Arg>

        <New class="org.eclipse.jetty.util.RolloverFileOutputStream">

          <Arg><Property name="jetty.logs" default="/var/log/jetty"/>/yyyy_mm_dd.stderrout.log</Arg>

          <Arg type="boolean">false</Arg>

          <Arg type="int">30</Arg>

          <Arg><Call class="java.util.TimeZone" name="getTimeZone"><Arg>GMT</Arg></Call></Arg>

          <Get id="ServerLogName" name="datedFilename"/>

        </New>

      </Arg>

    </New>

 

    <Call class="org.eclipse.jetty.util.log.Log" name="info"><Arg>Redirecting stderr/stdout to <Ref id="ServerLogName"/></Arg></Call>

    <Call class="java.lang.System" name="setErr"><Arg><Ref id="ServerLog"/></Arg></Call>

    <Call class="java.lang.System" name="setOut"><Arg><Ref id="ServerLog"/></Arg></Call>

 

</Configure>


30我猜是保留的文件个数,这个还有在考证

 


重启jetty,世界清爽啦!~~~


 


英文如下:


With Jetty 7.x you have 2 options.

Both require you to tell Jetty what kind of advanced logger you want to use.

* java.util.logging

* SLF4J


- java.util.logging -

Set a system property called "org.eclipse.jetty.util.log.class" to

"org.eclipse.jetty.util.log.JavaUtilLog" and from there you have all of the

standard java.util.logging configuration options to write to a file / roll

the log / etc ...


- SLF4J -

You'll want to setup SLF4J, have JettyLog use its SLF4J impl.

The mere existence of slf4j-api.jar in the classpath is enough to trigger

this behavior.

Download the slf4j-api.jar of your choice, and put it in

${jetty.home}/lib/ext

Be sure you checkout $ java -jar start.jar --version to see if it will load

into the Jetty Classpath (not your webapps)


Then you'll want to worry about how to take the SLF4J produced logging

events and route them to a logging impl you like.

Check out the docs at http://slf4j.org/ to understand how to setup slf4j.

For example: you can have SLF4J use log4j to write the logs to disk.


I personally like logback http://logback.qos.ch/ opposed to log4j, as it

allows me greater log routing control than log4j alone.

(Example: I can route all commons-logging & log4j & java.util.logging &

slf4j & stderr & stdout generated logging events to a file controlled by the

logback configuration under slf4j)


本文转自 guowang327 51CTO博客,原文链接:http://blog.51cto.com/guowang327/1770770,如需转载请自行联系原作者

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
17天前
|
Java
使用Java代码打印log日志
使用Java代码打印log日志
73 1
|
18天前
|
Linux Shell
Linux手动清理Linux脚本日志定时清理日志和log文件执行表达式
Linux手动清理Linux脚本日志定时清理日志和log文件执行表达式
72 1
|
22天前
|
SQL 关系型数据库 MySQL
MySQL数据库,可以使用二进制日志(binary log)进行时间点恢复
对于MySQL数据库,可以使用二进制日志(binary log)进行时间点恢复。二进制日志是MySQL中记录所有数据库更改操作的日志文件。要进行时间点恢复,您需要执行以下步骤: 1. 确保MySQL配置文件中启用了二进制日志功能。在配置文件(通常是my.cnf或my.ini)中找到以下行,并确保没有被注释掉: Copy code log_bin = /path/to/binary/log/file 2. 在需要进行恢复的时间点之前创建一个数据库备份。这将作为恢复的基准。 3. 找到您要恢复到的时间点的二进制日志文件和位置。可以通过执行以下命令来查看当前的二进制日志文件和位
|
9天前
|
运维 安全 Ubuntu
`/var/log/syslog` 和 `/var/log/messages` 日志详解
`/var/log/syslog` 和 `/var/log/messages` 是Linux系统的日志文件,分别在Debian和Red Hat系发行版中记录系统事件和错误。它们包含时间戳、日志级别、PID及消息内容,由`rsyslog`等守护进程管理。常用命令如`tail`和`grep`用于查看和搜索日志。日志级别从低到高包括`debug`到`emerg`,表示不同严重程度的信息。注意保护日志文件的安全,防止未授权访问,并定期使用`logrotate`进行文件轮转以管理磁盘空间。
19 1
|
10天前
|
网络协议 应用服务中间件 Linux
centos7 Nginx Log日志统计分析 常用命令
centos7 Nginx Log日志统计分析 常用命令
23 2
|
10天前
|
Ubuntu Linux 网络安全
/var/log/auth.log日志详解
`/var/log/auth.log`是Linux(尤其是Debian系如Ubuntu)记录身份验证和授权事件的日志文件,包括登录尝试(成功或失败)、SSH活动、sudo使用和PAM模块的操作。登录失败、SSH连接、sudo命令及其它认证活动都会在此记录。查看此日志通常需root权限,可使用`tail`、`less`或`grep`命令。文件内容可能因发行版和配置而异。例如,`sudo tail /var/log/auth.log`显示最后几行,`sudo grep &quot;failed password&quot; /var/log/auth.log`搜索失败密码尝试。
39 8
|
23天前
|
监控 Java 测试技术
日志框架到底是Logback 还是 Log4j2
日志框架到底是Logback 还是 Log4j2
17 0
|
24天前
|
XML 运维 监控
【深入探究 C++ 日志库清理策略】glog、log4cplus 和 spdlog 的日志文件管理策略
【深入探究 C++ 日志库清理策略】glog、log4cplus 和 spdlog 的日志文件管理策略
62 0
|
SQL 数据采集 监控
基于日志服务数据加工分析Java异常日志
采集并脱敏了整个5月份的项目异常日志,准备使用日志服务数据加工做数据清洗以及分析。本案例是基于使用阿里云相关产品(OSS,RDS,SLS等)的SDK展开自身业务。需要对异常日志做解析,将原始日志中时间、错误码、错误信息、状态码、产品信息、请求方法、出错行号提取出来。然后根据提取出来的不同产品信息做多目标分发处理。对清洗后的数据做异常日志数据分析。
709 0
基于日志服务数据加工分析Java异常日志
|
28天前
|
监控 Shell Linux
【Shell 命令集合 系统管理 】Linux 自动轮转(log rotation)日志文件 logrotate命令 使用指南
【Shell 命令集合 系统管理 】Linux 自动轮转(log rotation)日志文件 logrotate命令 使用指南
48 0