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 = "", 514
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))
if __name__ == "__main__":
server = SocketServer.UDPServer((HOST,PORT), SyslogUDPHandler)
except (IOError, SystemExit):
except KeyboardInterrupt:
print ("Crtl+C Pressed. Shutting down.")

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

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


pickeld commented Jul 18, 2015


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 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?

You can add utf-8 encoding to improve the server:

def handle(self):
    data = bytes.decode(self.request[0].strip(), encoding="utf-8")
    socket = self.request[1]
    print( "%s : " % self.client_address[0], str(data.encode("utf-8")))"utf-8")))

It worked very well when I needed a syslog server for some tests. Thanks for sharing.

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