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

Support file logging rollover #29

Open
wassimz opened this issue Oct 4, 2015 · 2 comments
Open

Support file logging rollover #29

wassimz opened this issue Oct 4, 2015 · 2 comments

Comments

@wassimz
Copy link

wassimz commented Oct 4, 2015

Hi, Thanks for this great add-on.

Is it possible to support daily/periodically file logging rollover like other language logging framework (for example log4j)

Thanks

@muxspace
Copy link
Contributor

muxspace commented Oct 5, 2015

Hiya, Yes it is possible to do log rotation. I don't have time to implement that at the moment. It shouldn't be that hard. Really all you need to do is check the timestamp of the file and move it after a certain age. Probably the biggest issue would be performance. If you implement it, please submit a pull request.

@giko45
Copy link

giko45 commented Aug 9, 2016

see below for rolling file appender

use with

flog.appender(appender.rollingfile('/data/log/meta.log',20))

implementation

appender.rollingfile<-function (file,size_Mb) {
     if (file.exists(file) && file.size(file) > size_Mb*1024*1024) {
          last = sprintf("%s.%i" ,file,10)
          if (file.exists(last)) file.remove(last)
          for   (i in 9:1) {
               from = sprintf("%s.%i" ,file,i)
               to   = sprintf("%s.%i" ,file,i+1)
               if (file.exists(from)) file.rename(from,to)
          }
          file.rename(sprintf("%s" ,file),sprintf("%s.%i" ,file,1))
     }
     function(line) cat(line, file = file, append = TRUE, sep = "")
}

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

No branches or pull requests

3 participants