V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
syslog-ng
RSYSLOG
Livid
V2EX  ›  Syslog

Tiny Syslog Server in Python

  •  
  •   Livid · 2014-07-06 18:25:24 +08:00 via iPhone · 6395 次点击
    这是一个创建于 3841 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Found on GitHub:

    #!/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.")
    view raw pysyslog.py hosted with ❤ by GitHub
    4 条回复    2014-07-06 18:40:17 +08:00
    kmvan
        1
    kmvan  
       2014-07-06 18:27:17 +08:00
    虽然不是很明白,但感觉很厉害的样子。
    Livid
        2
    Livid  
    MOD
    OP
       2014-07-06 18:31:30 +08:00 via iPhone
    @kmvan 请不要在 V2EX 用这种灌水的方式回复。

    http://www.v2ex.com/about
    zorceta
        3
    zorceta  
       2014-07-06 18:33:28 +08:00 via Android
    这么看起来 syslog 就是个远程日志服务器……
    mckelvin
        4
    mckelvin  
       2014-07-06 18:40:17 +08:00
    类似日志收集的事情,pyzmq提供了 zmq.log.handlers.PUBHandler ,可以很方便扩展:

    一个例子: https://github.com/zeromq/pyzmq/blob/master/examples/logger/zmqlogger.py
    一篇很好的ZeroMQ介绍: http://nichol.as/zeromq-an-introduction
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1830 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 16:22 · PVG 00:22 · LAX 08:22 · JFK 11:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.