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

本文是小编为大家收集整理的关于如何使用log4cxx保留单个文件并覆盖同一文件中的内容?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

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

我可以在log4cxx中执行此操作吗?如果是这样,请回答您的想法.

谢谢..

推荐答案

此样本将解决您的问题:

  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

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

本文地址:https://www.itbaoku.cn/post/1574848.html

问题描述

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..

推荐答案

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.