estk / log4rs

A highly configurable logging framework for Rust
Apache License 2.0
1.01k stars 150 forks source link

add same log file header for each new log (RollingFileAppender) #303

Open jpfreyen opened 1 year ago

jpfreyen commented 1 year ago

I'd like the option to have the same (minus timestamp stuff), log header for every new log created on rotation. Example:

Log-06-23-99.txt: T12:36:38.522798300-07:58 Appblast, All Rights Reserved T12:36:38.522798300-08:00...started process [45] . .

Log-06-24-99.txt: T12:36:38.522798300-08:58 Appblast, All Rights Reserved T12:36:38.522798300-09:05...process [45] still running T12:36:38.522798300-09:55...whoops error reading file heyyah.txt . .

I've thought the way to start this is RollingFileAppender::builder() needs to now pass a parameter, ie:

RollingFileAppender::builder(String)

example:

RollingFileAppender::builder("Appblast, All Rights Reserved".to_string()) If this is null/empty/"" then the parameter is not used

(hmm...side note, an array of Strings may be better to pass in and allow multiple line log header like: Log-06-26-99.txt: T12:36:38.522798300-07:57 Appblast, All Rights Reserved T12:36:38.522798300-07:58 This is the new log file feature T12:36:38.522798300-07:59 Copyright (c) 2023 T12:36:38.522798300-08:00...started process [49] )

The question would then be how/where-in-code does one make the rest of the changes so there is a guarantee the log header is always written on the first line(s) in a new file? It sounds basic, but as a new basic Rust programmer, it may be advanced :-P

jpfreyen commented 1 year ago

If someone could guide me to the code areas that need changing for this feature and what changes you would like to see to do it right, I'll do the work. Thanks!