Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to prefix all logs with date time before they are written to the log file?

Let's say I am logging unexpected errors in crontab in the following way:

python >> /tmp/output.log 2>&1

Is there an easy way to prefix (perhaps by piping through some third party command) all lines in the output.log with the date time so I would know when a given error happened?

share|improve this question
Maybe some of the answers from this will apply to you?… – Zoredache Feb 16 '12 at 0:40

One way is to use logger (1) (usually /bin/logger), and simply send everything to syslog:

python | logger -t

Syslog will automatically prepend the time/date to the log entry for you, and write this information to /var/log/messages (or whatever is specified in /etc/syslog.conf).

And this way, you have the advantage of all of the normal syslog/logrotation utilities.

share|improve this answer
And if a central syslog server is being used, you have backups and a secure logging environment to boot. – Mei Feb 16 '12 at 2:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.