sloggers icon indicating copy to clipboard operation
sloggers copied to clipboard

Feature request: Timestamp in log file name

Open dvtomas opened this issue 7 years ago • 4 comments

This is first in a series of feature requests I'd appreciate to have in sloggers. I can eventually implement them myself when I feel a pressing need (that will probably be in a couple of weeks), but I'm opening the issues anyway to have a proper place to discuss them.

For the type = "file" logger, I'd like to be able to write something like

path = "file_{timestamp}.log"

and have sloggers generate the filename on logger instantiation, something like file_170321_123459.log

Question is, whether the timestamp should be fixed, or if an e.g. strftime format should be supported. I personally would be happy with the fixed variant outlined above.

One thing not to forgot is that the timestamp should probably also honor the timezone setting.

dvtomas avatar Jan 08 '18 09:01 dvtomas

Good! This is a feature that I also have wanted to add someday.

In my use case, either "prefix_{year}{month}{day}.log" or "prefix_{year}{month}{day}_{hour}.log" is often used as log file name, so it is helpful to be able to specify a somewhat flexible format (although it is not mandatory requirement). If there is a widely used format (template) for log file names, I think that it is better to follow it.

sile avatar Jan 11 '18 14:01 sile

Related with this feature, I have wanted to add a basic file rotation functionality too, but even if it is useful, it may be better to separate it to another issue or PR (or crate).

sile avatar Jan 12 '18 00:01 sile

I just implemented it on top of master. Please see the relevant PR.

dvtomas avatar Sep 18 '18 10:09 dvtomas

yes, this is good. There is no fixed format but some kind of timestamp logging is very helpful. Trick is that we don't want rotation to leave too many files so we'd have to understand which files have been left by the logger ...

przygienda avatar Sep 24 '18 16:09 przygienda