zoukankan      html  css  js  c++  java
  • syslog

    syslog

    1. 声明

    #include <syslog.h>
    void openlog(char*ident,int option ,int facility);
    void syslog(int priority,char*format,……)
    void closelog()
    

    2. openlog

    例子:

    openlog(argv[0], LOG_PID, LOG_LOCAL5);
    

    a. openlog会指定一个indent,那么这个程序的每个信息前面都有这个indent,一般是这个程序名。

    b. option控制syslog行为:

       option
           The option argument to openlog() is an OR of any of these:
    
           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 connection is opened when the first message is logged).
    
           LOG_NOWAIT     Don't  wait  for  child  processes that may have been created 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.
    
    

    c. The facility argument is used to specify what type of program is logging the message. This lets the configuration file specify that messages from
    different facilities will be handled differently.
    配置文件是/etc/syslog.conf,可以配置不同程序类型,保存不同的位置:

    kern.*                  /var/log/kern.log
    user.*                  /var/log/syslog
    local2.*                /var/log/network.log
    local3.*                /var/log/onvif.log
    local5.*                /var/log/media.log
    local6.*                /var/log/rtspd.log
    

    syslog

    例子:

    syslog(LOG_DEBUG, "This is test message %s
    ", argv[0]);
    

    第一个参数是level,表示消息的重要性,syslog man page里关于level的选项,从上往下重要性逐渐下降。

       level
           This determines the importance of the message.  The levels are, in order of decreasing importance:
    
           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
    
    

    后面的参数就是fmt与参数。

    closelog

    closelog()关闭描述符。是否使用是可选的。

  • 相关阅读:
    单例模式的懒汉式在多线程的问题
    String、StringBuffer、与StringBuilder的区别
    java网络编程(7)——利用tcp实现文件上传
    java网络编程(6)——实现一个服务器把小写转大写
    java网络编程(5)——Tcp
    java网络编程(4)——udp实现聊天
    数据库单表增量备份方案
    java网络编程(3)——UDP
    使用Docker快速搭建Tensorflow开发环境
    word2vec并行实现小记
  • 原文地址:https://www.cnblogs.com/gr-nick/p/11125762.html
Copyright © 2011-2022 走看看