LoggingExtras.jl
LoggingExtras.jl copied to clipboard
Always same filename of active logfile in DatetimeRotatingFilelogger, until rotated out
Currently the timestamp is added to the active logger and not just when changing log files. logrotate
only appends the timestamp when rotating the file such that the active file is always the same. This behavior is sometimes useful and I think it would be good to support that there too. It is very easy to implement, but I am just not sure what the API should be. Perhaps just a filename and a prefix as two arguments?
Would that be a better option than the current way? It would be nice to avoid having configurable options, and have one consistent way it always worked.
I am just not sure what the API should be. Perhaps just a filename and a prefix as two arguments?
It would be nice to keep the current API, where you pass a DateFormat
, I think.
I feel like a we could derive a simple filename from the DateFormat.
julia> fmt = DateFormat(raw"\a\c\c\e\s\s-yyyy-mm-dd.\l\o\g")
dateformat"acc\e\s\s-yyyy-mm-dd.log"
julia> fmt.tokens
(Delim(acc\e\s\s-), DatePart(yyyy), Delim(-), DatePart(mm), Delim(-), DatePart(dd), Delim(.log))
- Either very simply by juust dropping the the
DateParts
, which would end up withaccess---.log
- or a bit more complex where we drop Delims that are only non-alphanums when they occur between
DateParts
: that would give useaccess-.log
- or even more complex: when adjacent to DateParts, except for if they are in the last
Delim
and are.
, which would get us toaccess-.log
but all the above heuristics fail for:
julia> fmt = DateFormat(raw"\a\c\c\e\s\s-\yYY-\mMM.\l\o\g")
dateformat"acc\e\s\s-\yYY-\mMM.log"
Which is a reasonable format of access-y21-09.log
which even the last will reduce to access-ym.log
.
But maybe something more complex could do it?
Or maybe something simplete, of just keeping first and last Delim
?
Would that be a better option than the current way?
The motivation for this issue is tools that monitor a log file. I worked around this issue by just using the rotation_callback
function to create a symlink. I can post the workaround when I have access to that computer again. Might be simple enough to do it like that.