development

Linux는 내 syslog를 어디에 저장합니까?

big-blog 2020. 11. 11. 20:20
반응형

Linux는 내 syslog를 어디에 저장합니까?


로그 파일에 무언가를 기록하는 간단한 테스트 애플리케이션을 작성했습니다. 내가 사용하고 리눅스 민트 와 응용 프로그램이 실행 된 후 나는이 명령을 사용하여 로그를 보려고 :

tail -n 100 /var/log/messages

그러나 파일 메시지는 테스트되지 않았거나 존재하지 않습니다. 아래에서 내 코드를 찾을 수 있습니다. 내가 뭔가 잘못하고 있거나 파일이 거기에 저장되지 않았거나 Linux Mint에서 로그인을 활성화해야 할 수도 있습니다.

#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>

void init_log()
{
    setlogmask(LOG_UPTO(LOG_NOTICE));
    openlog("testd",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
}

int main(void) {

    init_log();
    printf("Session started!");
    syslog(LOG_NOTICE, "Session started!!");
    closelog();

    return EXIT_SUCCESS;
}

내 Ubuntu 컴퓨터에서 출력을 /var/log/syslog.

RHEL / CentOS 시스템에서 출력은 /var/log/messages.

이는 rsyslog서비스에 의해 제어 되므로 어떤 이유로이 기능이 비활성화 된 경우 systemctl start rsyslog.

다른 사람들이 언급했듯이 syslog()출력은 /var/log/syslog파일에 기록됩니다 .
에서 시스템, 사용자 및 기타 로그를 볼 수 있습니다 /var/log.

자세한 내용 : 여기 흥미로운 링크가 있습니다.


허용되는 답변 외에도 다음을 아는 것이 유용합니다 ...

각 기능에는 관련된 매뉴얼 페이지 가 있어야 합니다.

당신이 실행하는 경우 man -k syslog(man 페이지의 키워드 검색을) 당신은 참조하거나 대해있는 사람이 페이지의 목록을 얻을 것이다 시스템 로그를

$ man -k syslog
logger (1)           - a shell command interface to the syslog(3) system l...
rsyslog.conf (5)     - rsyslogd(8) configuration file
rsyslogd (8)         - reliable and extended syslogd
syslog (2)           - read and/or clear kernel message ring buffer; set c...
syslog (3)           - send messages to the system logger
vsyslog (3)          - send messages to the system logger

더 자세히 알아 보려면 매뉴얼 섹션을 이해해야합니다.

다음은 man 페이지 섹션을 설명하는 man 페이지에서 발췌 한 것입니다.

The table below shows the section numbers of the manual followed  by
the types of pages they contain.

   1   Executable programs or shell commands
   2   System calls (functions provided by the kernel)
   3   Library calls (functions within program libraries)
   4   Special files (usually found in /dev)
   5   File formats and conventions eg /etc/passwd
   6   Games
   7   Miscellaneous  (including  macro  packages and conven‐
       tions), e.g. man(7), groff(7)
   8   System administration commands (usually only for root)
   9   Kernel routines [Non standard]

위의 실행을 읽으려면

$man man 

So, if you run man 3 syslog you get a full manual page for the syslog function that you called in your code.

SYSLOG(3)                Linux Programmer's Manual                SYSLOG(3)

NAME
   closelog,  openlog,  syslog,  vsyslog  - send messages to the system
   logger

SYNOPSIS
   #include <syslog.h>

   void openlog(const char *ident, int option, int facility);
   void syslog(int priority, const char *format, ...);
   void closelog(void);

   #include <stdarg.h>

   void vsyslog(int priority, const char *format, va_list ap);

Not a direct answer but hopefully you will find this useful.


Default log location (rhel) are

General messages:

/var/log/messages

Authentication messages:

/var/log/secure

Mail events:

/var/log/maillog

Check your /etc/syslog.conf or /etc/syslog-ng.conf (it depends on which of syslog facility you have installed)

Example:

$ cat /etc/syslog.conf
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none         /var/log/messages

# The authpriv file has restricted access.
authpriv.*                             /var/log/secure

# Log all the mail messages in one place.
mail.*                                 /var/log/maillog

#For a start, use this simplified approach.
*.*                                     /var/log/messages

You have to tell the system what information to log and where to put the info. Logging is configured in the /etc/rsyslog.conf file, then restart rsyslog to load the new config. The default logging rules are usually in a /etc/rsyslog.d/50-default.conf file.


syslog() generates a log message, which will be distributed by syslogd.

The file to configure syslogd is /etc/syslog.conf. This file will tell your where the messages are logged.

How to change options in this file ? Here you go http://www.bo.infn.it/alice/alice-doc/mll-doc/duix/admgde/node74.html


Logging is very configurable in Linux, and you might want to look into your /etc/syslog.conf (or perhaps under /etc/rsyslog.d/). Details depend upon the logging subsystem, and the distribution.

Look also into files under /var/log/ (and perhaps run dmesg for kernel logs).

참고URL : https://stackoverflow.com/questions/10979435/where-does-linux-store-my-syslog

반응형