[PATCH v3] log: add timestamp for log

Stephen Hemminger stephen at networkplumber.org
Mon Mar 6 23:03:22 CET 2023


On Mon, 6 Mar 2023 13:00:17 -0800
Tyler Retzlaff <roretzla at linux.microsoft.com> wrote:

> On Sat, Mar 04, 2023 at 08:04:41AM -0800, Stephen Hemminger wrote:
> > On Sat,  4 Mar 2023 16:14:21 +0800
> > luzhipeng <luzhipeng at cestc.cn> wrote:
> >   
> > > From: Zhipeng Lu <luzhipeng at cestc.cn>
> > > 
> > > add timestamp for log
> > > 
> > > Signed-off-by: Zhipeng Lu <luzhipeng at cestc.cn>  
> > 
> > Good idea but:
> >   - it needs to be optional
> >   - timestamp only makes sense on the terminal (stdout) log stream
> >     syslog/journal already have timestamp  
> 
> +1
> 
> also, some people who may have written scripts to consume the log output
> might get kind of irritated that you suddenly broke the format of the
> output. while not strictly an "api" it's not super friendly to break it
> unnecessarily.

Two additional comments.
  - since stderr is unbuffered on most OS, the fprintf of the timestamp
    and then the message is not thread safe. Writes of one thread and another might
    intermix.  Addressed that in my version by using writev
  - Putting full date is unnecessary overhead better to use seconds since startup
    (similar to kernel dmesg). Also simpler to calculate.


More information about the dev mailing list