sile / sloggers

A Rust library which provides frequently used slog loggers and convenient functions
MIT License
37 stars 18 forks source link

Feature request: Timestamp in log file name #7

Open dvtomas opened 6 years ago

dvtomas commented 6 years ago

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.

sile commented 6 years ago

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 commented 6 years ago

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).

dvtomas commented 6 years ago

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

przygienda commented 6 years ago

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 ...