如何在Java中将统计数据写入滚动文件 [英] How to write statistical data into rolling files in java

查看:375
本文介绍了如何在Java中将统计数据写入滚动文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建包含有关我的服务的统计数据的滚动文件. 例如,使用特定结果集记录每个包含参数X的请求. 我必须编写这些文件以符合其他系统的统计数据:

I would like to create rolling files that contains statistical data about my service. for example, logging each request that contained parameter X with a certain result set. I have to write these files to comply with other systems statistical data:

  • 每半小时滚动文件
  • 每个文件都必须具有列标题
  • 我必须遵循严格的文件名约定,例如 tracking.display.1314116577.done

我的服务是用Java编写的.

My service is written in Java.

由于我需要滚动文件,因此使用记录器似乎是一个很好的方向,因此我尝试了一种使用logback logger(我选择的记录器)记录数据的方法,但是传统的滚动文件附加器无法每次都充当文件的角色半小时(或者我错了吗?),无法添加列标题,并且具有自己的严格命名约定. 我曾尝试编写自己的RollingPolicy,但找不到足够的资源或如何完成此操作的示例.

Since I need to roll files, using loggers seems like a good direction so I have tried an approach where I would log the data using logback logger (my logger of choise), but the conventional rolling file appender cannot role the file every half an hour (or am i wrong?), cannot add column headers and has a strict naming convention of its own. I have tried to write my own RollingPolicy, but can't find enough resources or examples of how it's done.

任何人都可以告诉/推荐我如何完成此任务吗? 如果没有,您会推荐其他方法吗?

Can anyone show/refer me how to accomplish this? If not, would you recommend a different approach?

谢谢!

推荐答案

是的,您可以使用回退附加程序来完成此操作.

Yes, you can do it with a logback appender.

看看 TimeBasedRollingPolicy /logback.qos.ch/manual/appenders.html#RollingFileAppender"rel =" nofollow> RollingFileAppender ,您可以每半小时轻松滚动一次文件.

Take a look at TimeBasedRollingPolicy of RollingFileAppender you can easily roll the file each half hour.

要编写标题,您可以扩展RollingFileAppender并根据需要添加标题.

To write the header you can extend RollingFileAppender and add the header based on your needs.

这篇关于如何在Java中将统计数据写入滚动文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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