Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum File Size - supported in log4j FileAppender

I have a requirement that I need to store audit information in a TEXT file. I planned to write the audit information using Apache Log4j.

Seems to be reliable option. But, I should be able to write the Audit information even the fileSize reaches 3GB.

Does the log4j supports the fileSize even at GigaBytes?.

Or with a Quick Question, What is the MaximumFileSize can be supported in Log4j.

NOTE : I could not go for RollingFileAppender or DailyFileAppender, I need to log the information Only in One text file, where some other components are reading this file content and doing some process.

like image 693
omega Avatar asked Aug 06 '13 14:08

omega


People also ask

What is FileAppender in log4j?

FileAppender appends log events to a file. Support for java. io. Writer and console appending has been deprecated and then removed.

What is ConsoleAppender log4j?

ConsoleAppender, Java Logging. Log4j2 ConsoleAppender appends the log events generated by application into the System. out or System. err . The default target is System.


1 Answers

By default, maximum file size is 10MB(If you don't mention explicitly). And if you define explicitly, you can define any value upto GB(even 1000GB). But think, when you open this file, your machine must have an equal amount of RAM. So you have to take this into consideration before choosing file size. An example here

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=logging.log
log4j.appender.file.MaxFileSize=100GB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

FileAppender doesn't contain any field for setting file size. But its subclasses RollingFileAppender and DailyFileAppender contains.

like image 51
user2550754 Avatar answered Sep 20 '22 18:09

user2550754