0

I'm trying to find a Python script that uses logger to write file data to syslog. There's an application that outputs reports as log files, but I need these log files to be sent to syslog. I have this code, but I cannot determine how to target the log files and send it to syslog in Python.

This code has me on the right track, but I do not know where to specify the file I need to transfer to syslog. Can someone help steer me in the right direction? Or, perhaps provide the documentation I need?

2
  • /var/run/syslog seems wrong. have you tried /dev/log? Commented Jun 11, 2014 at 18:24
  • python -c 'import syslog; help(syslog)'... Commented Nov 3, 2014 at 15:37

1 Answer 1

3

Syslog handler is a service, not a file

You seem to be confused by trying to specify logfile for syslog.

Quoting Wikipedia:

Syslog is a standard for computer message logging. It permits separation of the software that generates messages from the system that stores them and the software that reports and analyzes them.

As syslog is a service, it decides about what to do with log records on it's own. That is why, you can only say address (like localhost on default port) of the syslog service but have no chance to control more from your (separated) application.

On SysLog side, there is configuration, controlling where should what log entry end up, but this is out of control of your log handler.

If you omit address, it would by default talk to localhost and default syslog port. In such a case it is very likely, you find your log records in /var/log/syslog file.

Forwarding log records from another log to syslog

If you have another log in some file and want to send it to syslog, you must:

  1. parse the log file and find log records
  2. send log records to syslog

However, this might create issues with timestamps of LogRecords as usually the created time is derived automatically at the moment log record is created. But it could be possibly resolved.

Conclusions

Do not expect your logger in Python to decide the file where syslog writhes log records. This must be configured at syslog level, not in your app.

If you have to forward logs from another source, most optimal is to manage that it goes directly there. If you cannot do that, you have to parse the log file and resend log records to syslog handler. Here you will have to resolve details about timestamps in log records.

Sign up to request clarification or add additional context in comments.

5 Comments

To articulate what I'm trying to accomplish better- I'm trying to automate this code for Linux with a Python script: blog.logrhythm.com/uncategorized/…
Activity.log is outputted by an application as a log file. I'm trying to write Activity.log to syslogd, in order for an application called Alert Logic to read the syslogd.
@JustinBaxtron Added part about forwarding
Thank you for steering me in the right direction. You've cleared up a lot of confusion. Although I still need to research more on how to write the script exactly, because I've never done it before.
For example, even when I use the command: logger –f Activity.log it only shows up in /var/log/system.log that it was typed in. It doesn't display the contents of the Activity.log file. It says: deny file-read data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.