dinit icon indicating copy to clipboard operation
dinit copied to clipboard

[Feature Request] Timestamps for service logs

Open Xynonners opened this issue 3 years ago • 2 comments

I was wondering if it is possible to add timestamps to logs of services. Would be quite useful for some long running processes, etc.

Xynonners avatar Dec 30 '21 13:12 Xynonners

I think this would be better managed by adding support to logging chain/logging processors. This way, the timestamp and log rotate programs in projects like busybox, runit and others could be reused. This can even sort-of be done already with FIFO trickery, but official support (and having the Dinit process keep the pipe file descriptors open, for safety) would be nice.

I understand being modular isn't as much of a priority to dinit as it is to the projects I've mentioned, but it'd be a way to keep it focused on service management.

capezotte avatar Dec 31 '21 04:12 capezotte

@XynonWasTaken sure, I'm thinking about this. The reason why it is not trivial is because timestamps should be associated with messages when they are generated, but the time is not reliable at early system startup (before the system time has been set from the hardware clock for example). It might be possible to work around this by recording the monotonic time that messages are generated and then, when the log service starts, assume the system time is correct, and use the delta between the current and recorded monotonic clock times to determine the real time of a message.

In the meantime, perhaps you can configure your log daemon to fill in the times? My old syslogd (from GNU inetutils) does this, it seems. The times aren't necessarily fully accurate since the messages may have been created before the logging daemon started.

@capezotte I think this is about log messages generated by dinit, regarding services, rather than messages generated by services themselves. Incidentally, keeping descriptors between services processes and their loggers only gives the illusion of safety: if a logger crashes, it may well have already consumed some of the process output without having recorded it in any log file. (It does have some other benefits though).

davmac314 avatar Jan 03 '22 08:01 davmac314

I think this would be better managed by adding support to logging chain/logging processors

This has now been implemented.

davmac314 avatar Aug 12 '23 02:08 davmac314

I think I'll not implement this after all. It's non-trivial in terms of how complex it is to do (see explanation above) and there's really no reason why the logging daemon can't add timestamps to syslog messages that come in without a timestamp; the implementations I've tried actually do so.

davmac314 avatar Aug 18 '23 10:08 davmac314