1

i have create a config file for log4cplus and its works but MaxFileSize don't do anything so my files keep growing without taking in considaration my limit . this is my code :

### logs.properties

# root logger

log4cplus.rootLogger=INFO, Main

# specific logger

log4cplus.logger.myloggerINFO, Main
log4cplus.additivity.mylogger=false

# appender that automatically rolls files

log4cplus.appender.Main=log4cplus::DailyRollingFileAppender
log4cplus.appender.Main.Schedule=DAILY
log4cplus.appender.Main.File=mylogs.log
log4cplus.appender.Main.Append=true
log4cplus.appender.Main.MaxBackupIndex=100
log4cplus.appender.Main.MaxFileSize=100KB
log4cplus.appender.Main.layout=log4cplus::PatternLayout
log4cplus.appender.Main.layout.ConversionPattern=%D | %-5.5p | %-20.20c | %m|%n

log4cplus.logger.myLoggerName=DEBUG, R2
log4cplus.appender.R2=log4cplus::RollingFileAppender
log4cplus.appender.R2.File=logs/webaccess.log
log4cplus.appender.R2.Append=true
log4cplus.appender.R2.MaxBackupIndex=5
log4cplus.appender.R2.MaxFileSize=5KB 
log4cplus.appender.R2.layout=log4cplus::PatternLayout
log4cplus.appender.R2.layout.ConversionPattern=%D | %-5.5p | %-20.20c | %m|%n

this is the example of list of files i get :

webaccess.log | 7kb even if max=5
mylogs.log    | 0
mylogs.log.2012-11-26 | 1k
mylogs.log.2012-11-26.1   |1k
...
mylogs.log.2012-11-26.45  | 1k 
he create new files even if max=100k 

so if you see anything wrong please tell me thanks

wilx
  • 17,697
  • 6
  • 59
  • 114
Amine
  • 347
  • 1
  • 5
  • 12

1 Answers1

2

Log4cplus' DailyRollingFileAppender does not observe MaxFileSize property. At the moment either you choose rolling log files by time or by size, you cannot have both at the same time.

EDIT 1:

The appender R2 does not work because there is a lower bound for the allowed MaxFileSize value: const long MINIMUM_ROLLING_LOG_SIZE = 200*1024L; This is 200 KiB. It in the log4cplus source from the start (or really long) and I have never felt a need to remove the limit.

wilx
  • 17,697
  • 6
  • 59
  • 114
  • thanks for the tip ,but in the second logger i use ROLLINGFILEAPPender but the MAXFileSize doesn't work – Amine Nov 26 '12 at 14:09
  • 1
    is there any method to have one log per day not par execution.i don't like to have many of them (1ko !) – Amine Nov 26 '12 at 15:04
  • IIRC, no, there is no way to have just one log per day instead of one per execution with DailyRollingFileAppender. – wilx Nov 26 '12 at 15:06
  • i remark that the logs are generated after i close the application .so if i keep the application working i will have nothing .i have tested with schedule "MINUTELY" ,i run my app for example at 16h41 and i close it at 16h50 -> i get only one file mylogs.log.2012-11-26-16-41 – Amine Nov 26 '12 at 16:48