现在有一个需求,就是用Python发送syslog日志到另一台机器上
1、Python发送端代码
import logging
import logging.handlers # handlers要单独import
logger = logging.getLogger()
fh = logging.handlers.SysLogHandler(('23.106.133.164', 514), logging.handlers.SysLogHandler.LOG_AUTH)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
logger.warning("msg")
logger.error("msg")
总共的代码就这样,下面单独分开讲一下