Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Tiny Python Syslog Server
#!/usr/bin/env python
## Tiny Syslog Server in Python.
##
## This is a tiny syslog server that is able to receive UDP based syslog
## entries on a specified port and save them to a file.
## That's it... it does nothing else...
## There are a few configuration parameters.
LOG_FILE = 'youlogfile.log'
HOST, PORT = "0.0.0.0", 514
#
# NO USER SERVICEABLE PARTS BELOW HERE...
#
import logging
import SocketServer
logging.basicConfig(level=logging.INFO, format='%(message)s', datefmt='', filename=LOG_FILE, filemode='a')
class SyslogUDPHandler(SocketServer.BaseRequestHandler):
def handle(self):
data = bytes.decode(self.request[0].strip())
socket = self.request[1]
print( "%s : " % self.client_address[0], str(data))
logging.info(str(data))
if __name__ == "__main__":
try:
server = SocketServer.UDPServer((HOST,PORT), SyslogUDPHandler)
server.serve_forever(poll_interval=0.5)
except (IOError, SystemExit):
raise
except KeyboardInterrupt:
print ("Crtl+C Pressed. Shutting down.")

Thanks, I've used it as a syslog frontend to redis.

https://github.com/iobear/beewatch/blob/master/bin/psyslog.py

seefor commented Jan 29, 2015

Great Script BTW
Question, instead of Crtl+C to end, how would you have it end in 30 minutes?

somma commented Apr 20, 2015

Thank's for sharing nice code. 😃

ilmarh commented Jun 5, 2015

Thanks!

pickeld commented Jul 18, 2015

Thanks!!

lidaling commented Sep 8, 2015

I am using rsyslog on centos as a client .
But I can't get message with your code.
Please help me.
: )

Excellent! just what I needed...

Thank you:)

pakru commented May 18, 2017

Nice one!

Thanks!

Thanks for the initiative. How do we add TLS support to this?

sagism commented Sep 10, 2017

Can you explain why would I use this instead of the real syslog facility?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment