Linux Syslog Learning

Source: Internet
Author: User
Tags int size openlog syslog system log file transfer protocol rsyslog

Most of the things that have been related to watching lighttpd facgi. See the following sample code on the LIGHTTPD website.

#include <stdlib.h> #include <string.h> #include <syslog.h> #include <alloca.h> #include < fcgiapp.h> #define Listensock_fileno 0#define listensock_flags 0int Main (int argc, char** argv) {openlog ("testfastcgi ", log_cons|  Log_ndelay, Log_user); int err = Fcgx_init ();  /* Call before Accept in multithreaded apps */if (err) {syslog (Log_info, "Fcgx_init failed:%d", err); return 1;}  Fcgx_request CGI;  Err = Fcgx_initrequest (&cgi, Listensock_fileno, listensock_flags);  if (err) {syslog (Log_info, "Fcgx_initrequest failed:%d", err); return 2;}    while (1) {err = Fcgx_accept_r (&cgi);    if (err) {syslog (Log_info, "Fcgx_accept_r stopped:%d", err);    char** envp;    int size = 200;    for (envp = CGI.ENVP; *envp; ++envp) Size + = strlen (*ENVP) + 11;    char* result = (char*) alloca (size);    strcpy (Result, "status:200 ok\r\ncontent-type:text/html\r\n\r\n"); strcat (Result, "

This fastcgi process is to output log to the syslog. The syslog was not very well understood, and it was then checked. Syslog is primarily a log system for Linux. There are mainly the following 3 Api:openlog,syslog and Closelog for the user process to write some log to the corresponding system log.

void Openlog (const char *ident, int option, int facility);

Function Description: Open the log device for reading and writing, similar to the open file system call; calling Openlog is optional. If you do not call Openlog, the Openlog is called automatically when you first call the syslog.

Parameter description:

Ident: is a token, the string represented by ident will be fixed in front of each line of the log to identify the log, usually written as the name of the current program for marking.

Option

Specifies the control flags for the Openlog function and the syslog function that is called next. You can take the following values:

Log_cons If an error occurs when sending information to the SYSLOGD daemon, output the relevant information directly to the terminal

Log_ndelay immediately open a connection to the system log (typically, the connection to the log system is turned on only if the first log information is generated)

Log_odelay is similar to the Log_ndelay parameter, and the connection to the system log is created only when the syslog function is called

Log_perror sends information to the standard error output while writing information to the log

Log_pid Each log message contains the process number

Facility: Specifies the type of message program to record, corresponding to facility in the configuration file syslog.conf of the syslogd daemon. The following values are desirable:

Log_auth Authentication System (login, Su, Getty, etc.)

Log_authpriv with Log_auth but only log in to a single user-readable file of your choice. Log_cron CRON Daemon

Log_daemon Other system daemons, such as routed

Log_ftp File Transfer Protocol: FTPD, TFTPD

Log_kern kernel-generated messages

LOG_LPR System Printer Buffer pool: LPR, LPD

Log_mail e-mail system

Log_news Network News System

Log_syslog internal messages generated by SYSLOGD (8)

Log_user messages generated by random user processes

LOG_UUCP UUCP Subsystem

LOG_LOCAL0 ~ LOG_LOCAL7 local use reserved

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

Function Description: Writes a log similar to the file system call to write.

Priority: Represents the level of the message, corresponding to the levels in the configuration file syslog.conf of the syslogd daemon. The following values are desirable:

Log_emerg Emergency situation

Log_alert should be immediately corrected for problems such as system database corruption

Log_crit important situations, such as hard drive errors

Log_err Error

Log_warning warning message

Log_notice is not an error condition, but may need to be handled

Log_info Intelligence Error

Log_debug contains information about intelligence, which is usually used when debugging a program

void Closelog ();

Function Description: Turn off the log device, similar to the file system call Close; Call Closelog is also optional, it simply closes the descriptor that is used to communicate with the syslog daemon.

Since I first learned about the syslog, I don't know where the log output of the fastcgi process is. I checked the output to/var/log/messages. However, there are no messages files in this directory.

This is because the config file for syslog is not configured.

The/etc/syslog.conf file is a configuration file for the Linux journaling system. (under Ubuntu for/etc/rsyslog.d/50-default.conf)

Edit/etc/rsyslog.d/50-default.conf

One of them has such a *.=info;*.=notice;*.=warn;\ auth,authpriv.none;\ cron,daemon.none;\ mail,news.none-/var/log/messa Ges This is already there, but it is commented (some options are commented like Log_user). Now the annotation is OK. Then restart the Syslog:sudo service rsyslog restart (sudo restart rsyslog).

Linux Syslog Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.