Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

any function to do a log rotation? #32

Closed
jiang-wei opened this issue Nov 5, 2014 · 3 comments
Closed

any function to do a log rotation? #32

jiang-wei opened this issue Nov 5, 2014 · 3 comments

Comments

@jiang-wei
Copy link

Is there a function to set the log rotation?
otherwise I have to write some function to:

  1. setup a new LogBackend with a new filename and replace the current Backend
  2. rename the old log file to xxx.log.$DATETIME
  3. rename the new log file to xxx.log
@guycalledseven
Copy link

IMHO this is job for os at system level via logrotate or similar on unix.
But you could try Rotating File writer which implements io.writer so you just push that to logging.NewLogBackend instead.

@op
Copy link
Owner

op commented Nov 7, 2014

Agree, there are already many solutions out there. Good luck!

@op op closed this as completed Nov 7, 2014
@cedricve
Copy link

cedricve commented Aug 6, 2019

This library is great: https://github.com/natefinch/lumberjack.

fileBackend := logging.NewLogBackend(&lumberjack.Logger{
Filename:   "./logs/log.log",
MaxSize:    2, // megabytes
Compress:   true, // disabled by default
}, "", 0)
logging.SetBackend(stdBackendLeveled, mqttBackend, fileBackend)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants