python syslog 接口_python之syslog模块
syslog模塊為提供了rsyslog模塊的一個接口??梢杂涗洺绦蜻\行時的輸出信息。
個人認(rèn)為此方法沒有l(wèi)ogging模塊方便
常用方法如下:
syslog.open(indent[,logopt[,facility]]) ?####初始化rsyslog日志接口函數(shù)
syslog.syslog([priority],message) ? ?#######將message記錄到日志文件
syslog.closelog() ? ? ? ? ? ? ? ########關(guān)閉日志
syslog.open(indent[,logopt[,facility]])方法
indent參數(shù):
>>> import syslog
>>> syslog.openlog(‘gyyx.py‘)
>>> syslog.syslog(‘this is a brief test!‘)
[[email?protected] ~]# tail -f /var/log/messages
Mar 16 12:19:11 cdn gyyx.py: this is a brief test!
logopt參數(shù):
選項名稱:LOG_CONS,LOG_NDELAY,LOG_NOWAIT,LOG_PID,LOG_PERROR
可以從中選擇一個,或者多個(要借助或操作符”|”)
>>> syslog.openlog(‘gyyx.py‘,syslog.LOG_PID) ? ##########日志增加了進程PID
>>> syslog.syslog(‘this is a brief test!and add pid‘)
[[email?protected] ~]# tail -f /var/log/messages
Mar 16 12:23:21 cdn gyyx.py[11887]: this is a brief test!and add pid
facility參數(shù):
名稱:
LOG_AUTH,LOG_CRON,LOG_DAEMON,LOG_KERN,LOG_LOCALx,LOG_LPR,LOG_MAIL,LOG_NEWS,LOG_USER,LOG_UUCP,系統(tǒng)管理員使用這些參數(shù)配置信息如何分解到不同的文件和服務(wù)中。在前面,我們一直將信息輸出到messages文件中,這次,我們要結(jié)合syslog.conf的配置來將其輸出到其他文件了。修改rsyslog.conf,修改如下:
*.info;mail.none;authpriv.none;cron.none;auth.none? /var/log/messages ?#驗證不寫入message
auth.* ? ? ? ? ? ? ? /var/log/python.auth ?######驗證寫入此文件
syslog.openlog(‘test.py‘,syslog.LOG_PID|syslog.LOG_NOWAIT,syslog.LOG_AUTH)
syslog.syslog(‘the process is test.py111111111111111111111‘)
syslog.closelog()
[[email?protected] ~]# tail -f /var/log/python.auth
Mar 16 12:03:08 cdn test.py[11857]: the process is test.py111111111111111111111
Mar 16 12:04:54 cdn test.py[11874]: the process is test.py111111111111111111111
Mar 16 12:05:07 cdn test.py[11877]: the process is test.py111111111111111111111
syslog.syslog([priority],message)方法
Priority參數(shù)
名稱:LOG_EMERG,LOG_ALERT,LOG_CRIT,LOG_ERR,LOG_WARNING,LOG_INFO,LOG_DEBUG(默認(rèn)為LOG_INFO)
原文:http://weilantiankong.blog.51cto.com/9469693/1751714
總結(jié)
以上是生活随笔為你收集整理的python syslog 接口_python之syslog模块的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Cura代码编译所需的环境配置
- 下一篇: python程序调用写好的代码_扣丁学堂