linux syslog

来源:互联网 发布:2016年度网络热词 编辑:程序博客网 时间:2024/05/29 01:54
void openlog(const char *ident, int option, int facility);void syslog(int priority, const char *format, ...);void closelog(void);

option

LOG_CONS       Write directly to system console if there  is  an  error               while sending to system logger.LOG_NDELAY     Open  the  connection immediately (normally, the connec‐               tion is opened when the first message is logged).LOG_NOWAIT     Don't wait for child processes that may have  been  cre‐               ated while logging the message.  (The GNU C library does               not create a child process, so this option has no effect               on Linux.)LOG_ODELAY     The converse of LOG_NDELAY; opening of the connection is               delayed until syslog() is called.  (This is the default,               and need not be specified.)LOG_PERROR     (Not  in POSIX.1-2001 or POSIX.1-2008.)  Print to stderr               as well.LOG_PID        Include PID with each message.

配置文件

# ls /etc/rsyslog.conf# ls /etc/rsyslog.d/20-ufw.conf  50-default.conf
# cat 50-default.confauth,authpriv.*                 /var/log/auth.log*.*;auth,authpriv.none          -/var/log/syslog#cron.*                         /var/log/cron.log#daemon.*                       -/var/log/daemon.logkern.*                          -/var/log/kern.log#lpr.*                          -/var/log/lpr.logmail.*                          -/var/log/mail.log#user.*                         -/var/log/user.log#local5.*                       -/var/log/user.log

auth:身份认证相关
cron:进程或调度相关
daemon:守护进程相关
kern:内核相关
mail:邮件相关
user:用户自定义相关
local[0-7]:用户自定义相关

格式:
facility.level

:配置生效需要重启rsyslog

facility

LOG_AUTH       security/authorization messagesLOG_AUTHPRIV   security/authorization messages (private)LOG_CRON       clock daemon (cron and at)LOG_DAEMON     system daemons without separate facility valueLOG_FTP        ftp daemonLOG_KERN       kernel messages (these can't be generated from user pro‐               cesses)LOG_LOCAL0 through LOG_LOCAL7               reserved for local useLOG_LPR        line printer subsystemLOG_MAIL       mail subsystemLOG_NEWS       USENET news subsystemLOG_SYSLOG     messages generated internally by syslogd(8)LOG_USER (default)               generic user-level messagesLOG_UUCP       UUCP subsystem

level

LOG_EMERG      system is unusableLOG_ALERT      action must be taken immediatelyLOG_CRIT       critical conditionsLOG_ERR        error conditionsLOG_WARNING    warning conditionsLOG_NOTICE     normal, but significant, conditionLOG_INFO       informational messageLOG_DEBUG      debug-level message

emerg:紧急
alert:报警
crit:关键
err:错误
warning:警告
notice:通知
info:消息
debug:调试

举例

local5.*                            -/var/log/user.logopenlog("hello furong.", LOG_CONS | LOG_PID | LOG_PERROR, LOG_LOCAL5);FILE *f = fopen("hello", "r");      syslog(LOG_ERR, "oops - %m\n");  closelog();
# tail -n1 /var/log/user.loghello furong.[5317]: oops - No such file or directory
1 0
原创粉丝点击