Syslog with Python

6 篇文章 0 订阅
3 篇文章 0 订阅

syslog

Options

LOG_PID // log the pid with each message
LOG_CONS // log on the console if errors in sending
LOG_NDELAY // don't delay open
LOG_NOWAIT // don't wait for console forks: DEPRECATED
LOG_PERROR // log to stderr as well

Facilities

LOG_KERN  // kernel messages
LOG_USER  // random user-level messages
LOG_MAIL  // mail system
LOG_DAEMON // system daemons
LOG_AUTH // security/authorization messages
LOG_SYSLOG // messages generated internally by syslogd
LOG_LPR // line printer subsystem
LOG_NEWS // network news subsystem
LOG_UUCP // UUCP subsystem
LOG_CRON // clock daemon
LOG_LOCAL0 // reserved for local use
LOG_LOCAL1 // reserved for local use
LOG_LOCAL2 // reserved for local use
LOG_LOCAL3 // reserved for local use
LOG_LOCAL4 // reserved for local use
LOG_LOCAL5 // reserved for local use
LOG_LOCAL6 // reserved for local use
LOG_LOCAL7 // reserved for local use

Priority levels

LOG_EMERG // system is unusable
LOG_ALERT // action must be taken immediately
LOG_CRIT // critical conditions
LOG_ERR // error conditions
LOG_WARNING // warning conditions
LOG_NOTICE // normal but significant condition
LOG_INFO // informational
LOG_DEBUG // debug-level messages

syslog

syslog.syslog(message)
syslog.syslog(priority, message)

Send the string message to the system logger. A trailing newline is added if necessary. Each message is tagged with a priority composed of a facility and a level. The optional priority argument, which defaults to LOG_INFO, determines the message priority. If the facility is not encoded in priority using logical-or (LOG_INFO LOG_USER), the value given in the openlog() call is used.

If openlog() has not been called prior to the call to syslog(), openlog() will be called with no arguments.

openlog

syslog.openlog([ident[, logoption[, facility]]])

Logging options of subsequent syslog() calls can be set by calling openlog(). syslog() will call openlog() with no arguments if the log is not currently open.

The optional ident keyword argument is a string which is prepended to every message, and defaults to sys.argv[0] with leading path components stripped. The optional logoption keyword argument (default is 0) is a bit field – see below for possible values to combine. The optional facility keyword argument (default is LOG_USER) sets the default facility for messages which do not have a facility explicitly encoded.

closelog

syslog.closelog()

Reset the syslog module values and call the system library closelog().

This causes the module to behave as it does when initially imported. For example, openlog() will be called on the first syslog() call (if openlog() hasn’t already been called), and ident and other openlog() parameters are reset to defaults.

setlogmask

syslog.setlogmask(maskpri)

Set the priority mask to maskpri and return the previous mask value. Calls to syslog() with a priority level not set in maskpri are ignored. The default is to log all priorities. The function LOG_MASK(pri) calculates the mask for the individual priority pri. The function LOG_UPTO(pri) calculates the mask for all priorities up to and including pri.

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import syslog


def log():
    """
    syslog example
    """
    syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_MAIL)
    string = "Hello World."
    syslog.syslog(syslog.LOG_LOCAL1 | syslog.LOG_WARNING, string)
    syslog.closelog()

def main():
    log()

if __name__ == "__main__":
    main()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值