Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2095379
  • 博文数量: 229
  • 博客积分: 7217
  • 博客等级: 上校
  • 技术积分: 3224
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-19 17:23
个人简介

个人主页https://xugaoxiang.com,微信公众号: Dev_Club 或者搜索 程序员Club

文章分类

全部博文(229)

文章存档

2017年(1)

2016年(20)

2015年(23)

2013年(1)

2012年(23)

2011年(68)

2010年(62)

2009年(31)

分类: LINUX

2010-10-13 14:15:47

Generally speaking,there is a output from our program.But on server endian,we don't hope that the message printing in the screen.So,we put them in a local file.It's not a good idea to deal with the file operation in our programs.Because it's not convenient to maintain the system for some people who is not familar with the program.

/* test.c */
#include
#include

int main(int argc, char **argv)
{
    openlog("syslogTest", LOG_CONS | LOG_PID, 0);
    syslog(LOG_DEBUG,"There is a syslog message generated by '%s'\n",argv[0]);
    closelog();
    return 0;
}

gcc -o syslogTest test.c
./syslogTest

vi /var/log/syslog


void openlog(const char *ident, int option, int facility);
This function connect to the daemon process syslogd.

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 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 SUSv3.) Print to stderr as well.

       LOG_PID
              Include PID with each message.

facility:
       LOG_AUTH       security/authorization messages (DEPRECATED Use LOG_AUTHPRIV instead)

       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 processes)

       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

void syslog(int priority, const char *format, ...);

priority:
       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



djstava
阅读(2065) | 评论(1) | 转发(0) |
0

上一篇:How to write a daemon process?

下一篇:Libevent

给主人留下些什么吧!~~

chinaunix网友2010-10-13 20:15:29

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com