Skip to content

Instantly share code, notes, and snippets.

@telepenin
Forked from marcelom/pysyslog.py
Last active July 11, 2016 09:00
Show Gist options
  • Save telepenin/d547ec076fedb14bf6b1b2ca10d9e631 to your computer and use it in GitHub Desktop.
Save telepenin/d547ec076fedb14bf6b1b2ca10d9e631 to your computer and use it in GitHub Desktop.
Tiny Python Syslog Server
#!/usr/bin/env python
LOG_FILE = 'syslogd.log'
HOST, PORT = "0.0.0.0", 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))
logging.info(str(data))
if __name__ == "__main__":
try:
server = SocketServer.UDPServer((HOST,PORT), SyslogUDPHandler)
print ("Server started on {} {}".format(HOST, PORT))
server.serve_forever(poll_interval=0.5)
except (IOError, SystemExit):
raise
except KeyboardInterrupt:
print ("Crtl+C Pressed. Shutting down.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment