Package eu.woolplatform.utils.log
Class FileLogger
- java.lang.Object
-
- eu.woolplatform.utils.log.FileLogger
-
public class FileLogger extends Object
This class can write log messages to log files. It is constructed with a log directory. In this directory, the file logger will automatically create log files. Each log file will get a name with the current date.
-
-
Field Summary
Fields Modifier and Type Field Description static ObjectARCHIVE_LOCK
-
Constructor Summary
Constructors Constructor Description FileLogger(File logDir)Constructs a new file logger.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intprintTaggedMessage(int priority, String tag, org.joda.time.LocalDate date, String msg)Writes a log message.voidsetArchiveDelay(int days)Sets the number of days after which log files should be archived to a zip file.voidsetPurgeDelay(int days)Sets the number of days after which log files should be purged.
-
-
-
Field Detail
-
ARCHIVE_LOCK
public static final Object ARCHIVE_LOCK
-
-
Constructor Detail
-
FileLogger
public FileLogger(File logDir) throws IOException
Constructs a new file logger. The specified log directory will be created if it doesn't already exist.- Parameters:
logDir- the log directory- Throws:
IOException- if the log directory can't be created
-
-
Method Detail
-
setArchiveDelay
public void setArchiveDelay(int days)
Sets the number of days after which log files should be archived to a zip file. If you set "days" to 1, then it will archive yesterday's log file and older log files. If you set "days" to 0, then it won't archive any log files. The default is 0.- Parameters:
days- the number of days after which log files should be archived
-
setPurgeDelay
public void setPurgeDelay(int days)
Sets the number of days after which log files should be purged. If you set "days" to 1, then it will purge yesterday's log file and older log files. If you set "days" to 0, then it won't purge any log files. The default is 0.- Parameters:
days- the number of days after which log files should be purged
-
printTaggedMessage
public int printTaggedMessage(int priority, String tag, org.joda.time.LocalDate date, String msg)Writes a log message. The lines in the message should already be tagged with the log level, message tag (identifies the source of the log message) and the current date and time. Every line should end with a new line character, including the last line. This method is thread safe.If the specified date has already been archived or purged, then this method has no effect.
- Parameters:
priority- the log leveltag- the message tagdate- the date of the log messagemsg- the tagged message- Returns:
- 0 if no error occurred, an error code otherwise
-
-