This is not doable when using the syslog
call on it's own. The reason is that the timestamp that you see on the log file is after the log message has been sent to the daemon. It's the syslog daemon that actually performs the addition of the timestamp. The logging daemon is the thing that applies the timestamp.
When you use the LOG_CONS
and LOG_PERROR
options the message is sent to the console or stderr without ever getting timestamped because the timestamping does not occur at the point of logging.
Essentially the use of LOG_CONS
and LOG_PERROR
bypass the daemon entirely; you would need to modify the implementation of the syslog call itself to add your own timestamp. Thankfully, that's pretty easy as the implementation of the syslog library call is in the glibc source, and the source isn't terribly complicated.