zoukankan      html  css  js  c++  java
  • linux syslog

    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.conf
    auth,authpriv.*                 /var/log/auth.log
    *.*;auth,authpriv.none          -/var/log/syslog
    #cron.*                         /var/log/cron.log
    #daemon.*                       -/var/log/daemon.log
    kern.*                          -/var/log/kern.log
    #lpr.*                          -/var/log/lpr.log
    mail.*                          -/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 messages
    LOG_AUTHPRIV   security/authorization messages (private)
    LOG_CRON       clock daemon (cron and at)
    LOG_DAEMON     system daemons without separate facility value
    LOG_FTP        ftp daemon
    LOG_KERN       kernel messages (these can't be generated from user pro‐
                   cesses)
    LOG_LOCAL0 through LOG_LOCAL7
                   reserved for local use
    LOG_LPR        line printer subsystem
    LOG_MAIL       mail subsystem
    LOG_NEWS       USENET news subsystem
    LOG_SYSLOG     messages generated internally by syslogd(8)
    LOG_USER (default)
                   generic user-level messages
    LOG_UUCP       UUCP subsystem

    level

    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 message
    LOG_DEBUG      debug-level message

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

    举例

    local5.*                            -/var/log/user.log
    
    openlog("hello furong.", LOG_CONS | LOG_PID | LOG_PERROR, LOG_LOCAL5);
    FILE *f = fopen("hello", "r");      
    syslog(LOG_ERR, "oops - %m
    ");  
    closelog();
    # tail -n1 /var/log/user.log
    hello furong.[5317]: oops - No such file or directory
  • 相关阅读:
    递归打印99乘法表
    递归对一个数组求和
    在控制台打印出99乘法表
    ie9以下浏览器不兼容placeholder的解决方案
    二列布局 左边固定宽度 右边响应
    Scala并发编程实战初体验及其在Spark源码中的应用解析之Scala学习笔记-56
    Scala中隐式转换内幕操作规则揭秘、最佳实践及其在Spark中的应用源码解析之Scala学习笔记-55
    Scala中隐式对象代码实战详解之Scala学习笔记-54
    Scala中隐式类代码实战详解之Scala学习笔记-53
    Scala中上下文界定内幕中的隐式参数与隐式参数的实战详解及其在Spark中的应用源码解析之Scala学习笔记-52
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/11709709.html
Copyright © 2011-2022 走看看