sourcecode

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

copyscript 2022. 8. 28. 09:51
반응형

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

로그 파일에 기록하기 위해 간단한 테스트 신청서를 작성했습니다.Linux mint를 사용하고 있으며 응용 프로그램이 실행된 후 다음 명령을 사용하여 로그를 표시하려고 합니다.

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 머신의 출력은, 다음의 URL 에 있습니다./var/log/messages.

이것은 에 의해 제어됩니다.rsyslog어떤 이유로 디세블이 되어 있는 경우는, 다음의 순서로 개시할 필요가 있습니다.systemctl start rsyslog.

다른 사람들이 지적한 바와 같이syslog()출력은 에 의해 기록됩니다./var/log/syslog파일.
시스템, 사용자 및 기타 로그는 다음 사이트에서 볼 수 있습니다./var/log.

상세한 것에 대하여는, 이쪽의 링크를 참조해 주세요.

기본 로그 위치(rhel)는 다음과 같습니다.

일반 메시지:

/var/log/messages

인증 메시지:

/var/log/secure

메일 이벤트:

/var/log/maillog

체크해 주세요./etc/syslog.conf또는/etc/syslog-ng.conf(설치되어 있는Syslog 패실리티에 따라 다름)

예:

$ 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

인정된 답변 외에 다음 사항을 알아두면 도움이 됩니다.

이러한 기능에는 각각 수동 페이지가 관련되어 있어야 합니다.

뛰면man -k syslog(man 페이지의 키워드 검색) syslog를 참조하거나 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 

그래서, 만약 네가 뛰면man 3 syslog의 완전한 매뉴얼 페이지가 표시됩니다.syslog코드 내에서 호출한 함수입니다.

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

직접적인 대답은 아니지만 이것이 유용하기를 바랍니다.

어떤 정보를 기록하고 어디에 저장해야 하는지 시스템에 알려야 합니다.로깅은 로 설정됩니다./etc/rsyslog.confrsyslog를 재시작하여 새 설정을 로드합니다.디폴트 로깅 규칙은/etc/rsyslog.d/50-default.conf파일.

WSL(Windows Subsystem for Linux)에서 Ubuntu를 실행하고 있습니다.systemctl start rsyslog나한테는 통하지 않았어

그래서 제가 한 일은 이렇습니다.

$ service rsyslog start

지금이다syslog파일이 다음 위치에 표시됩니다./var/log/

syslog()는 syslogd에 의해 배포되는 로그 메시지를 생성합니다.

syslogd를 설정하는 파일은 /etc/syslog.conf 입니다.이 파일은 메시지가 기록되는 위치를 알려줍니다.

이 파일의 옵션을 변경하는 방법여기 있습니다.http://www.bo.infn.it/alice/alice-doc/mll-doc/duix/admgde/node74.html

Linux 에서는 로깅을 매우 쉽게 구성할 수 있으며, 이 기능을 통해/etc/syslog.conf 아마 아래일 이다)/etc/rsyslog.d/ 내용은 서브시스템 및 의 자세한 내용은 로깅 서브시스템 및 배포에 따라 달라집니다.

이 밑에 있는 도 한 번 찾아보세요./var/log/ 도망칠지도 )dmesg★★★★★★★★★★★★★★★★★★★★★」

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

반응형