如何使用log4cxx保留单个文件并覆盖同一文件中的内容?(How to keep single file and overwrite the contents in the same file us

编程入门 行业动态 更新时间:2024-10-22 23:35:50
如何使用log4cxx保留单个文件并覆盖同一文件中的内容?(How to keep single file and overwrite the contents in the same file using log4cxx?)

在我的应用程序中,多个线程将数据记录在同一个文件中。如果文件大小超过限制,那么我必须删除文件中的特定记录并向上移动每个内容。

我可以在Log4cxx中执行此操作吗?如果是,请回复您的想法..

谢谢..

In my application , Multiple threads log the data in the same file .if the file size exceeds the limit , then i have to delete the particular record in file and move every contents upwards.

can I do this in Log4cxx?if so ,reply your thoughts..

Thanks..

最满意答案

此示例将解决您的问题:

log4j.rootLogger=debug, stdout, R log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout # Pattern to output the caller's file name and line number. log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=example.log log4j.appender.R.MaxFileSize=100KB # Keep one backup file log4j.appender.R.MaxBackupIndex = 0 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

这将覆盖同一文件中的文件内容。

This sample will solve your problem :

log4j.rootLogger=debug, stdout, R log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout # Pattern to output the caller's file name and line number. log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=example.log log4j.appender.R.MaxFileSize=100KB # Keep one backup file log4j.appender.R.MaxBackupIndex = 0 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

This will override the file contents in the same file.

更多推荐

本文发布于:2023-08-04 10:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415304.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   如何使用   内容   log4cxx   contents

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!