Building a new rotate file writer:
rfw := l4g.NewRotateFileWriter("_rfw.log").SetMaxSize(1024 * 5).SetMaxBackup(10)
Setting maxium file size as 5M, and keeping only 10 files.
Or:
rfw := l4g.NewRotateFileWriter("_rfw.log").SetDaily(true)
Rotating file every day at midnight.
Setting output as MultiWriter
Logging message to term console and rotate file writer too.
ww := io.MultiWriter(os.Stderr, rfw)
// Get a new logger instance
log := l4g.New(l4g.FINEST).SetOutput(ww).SetPattern("[%D %T] [%L] (%s) %M\n")
Do not forget CLOSE rotate file writer
Call Close() function at the end of main program.
It is necessary to guarantee that all log messages are written.
rfw.Close()
Example
See also: