syslog — 유닉스 syslog 라이브러리 루틴¶
이 모듈은 유닉스 syslog 라이브러리 루틴에 대한 인터페이스를 제공합니다. syslog 기능에 대한 자세한 설명은 유닉스 매뉴얼 페이지를 참조하십시오.
가용성: Unix, not WASI, not iOS.
이 모듈은 시스템 syslog 계열의 루틴을 감쌉니다. syslog 서버와 통신할 수 있는 순수한 파이썬 라이브러리는 logging.handlers 모듈에서 SysLogHandler로 제공됩니다.
모듈은 다음 함수를 정의합니다:
- syslog.syslog(message)¶
- syslog.syslog(priority, message)
message 문자열을 시스템 로거로 보냅니다. 필요하면 끝에 줄 넘김이 추가됩니다. 각 메시지에는 시설(facility) 과 수준(level)으로 구성된 우선순위(priority)로 꼬리표가 붙습니다. 선택적 priority 인자(기본값은
LOG_INFO)는 메시지 우선순위를 결정합니다. 시설이 논리합(LOG_INFO | LOG_USER)을 사용하여 priority로 인코딩되지 않으면,openlog()호출에 지정된 값이 사용됩니다.If
openlog()has not been called prior to the call tosyslog(),openlog()will be called with no arguments.인자
priority,message로 감사 이벤트syslog.syslog를 발생시킵니다.버전 3.2에서 변경: In previous versions,
openlog()would not be called automatically if it wasn’t called prior to the call tosyslog(), deferring to the syslog implementation to callopenlog().버전 3.12에서 변경: This function is restricted in subinterpreters. (Only code that runs in multiple interpreters is affected and the restriction is not relevant for most users.)
openlog()must be called in the main interpreter beforesyslog()may be used in a subinterpreter. Otherwise it will raiseRuntimeError.
- syslog.openlog([ident[, logoption[, facility]]])¶
Logging options of subsequent
syslog()calls can be set by callingopenlog().syslog()will callopenlog()with no arguments if the log is not currently open.선택적 ident 키워드 인자는 모든 메시지 앞에 추가되는 문자열이며, 기본값은 선행 경로 구성 요소가 제거된
sys.argv[0]입니다. 선택적 logoption 키워드 인자(기본값은 0)는 비트 필드입니다 – 결합할 수 있는 가능한 값은 아래를 보십시오. 선택적 facility 키워드 인자(기본값은LOG_USER)는 명시적으로 인코드 된 시설이 없는 메시지에 대한 기본 시설을 설정합니다.인자
ident,logoption,facility로 감사 이벤트syslog.openlog를 발생시킵니다.버전 3.2에서 변경: 이전 버전에서는, 키워드 인자가 허용되지 않았고, ident가 필수였습니다.
버전 3.12에서 변경: This function is restricted in subinterpreters. (Only code that runs in multiple interpreters is affected and the restriction is not relevant for most users.) This may only be called in the main interpreter. It will raise
RuntimeErrorif called in a subinterpreter.
- syslog.closelog()¶
syslog 모듈값을 재설정하고 시스템 라이브러리
closelog()를 호출합니다.This causes the module to behave as it does when initially imported. For example,
openlog()will be called on the firstsyslog()call (ifopenlog()hasn’t already been called), and ident and otheropenlog()parameters are reset to defaults.인자 없이 감사 이벤트
syslog.closelog를 발생시킵니다.버전 3.12에서 변경: This function is restricted in subinterpreters. (Only code that runs in multiple interpreters is affected and the restriction is not relevant for most users.) This may only be called in the main interpreter. It will raise
RuntimeErrorif called in a subinterpreter.
- syslog.setlogmask(maskpri)¶
Set the priority mask to maskpri and return the previous mask value. Calls to
syslog()with a priority level not set in maskpri are ignored. The default is to log all priorities. The functionLOG_MASK(pri)calculates the mask for the individual priority pri. The functionLOG_UPTO(pri)calculates the mask for all priorities up to and including pri.인자
maskpri로 감사 이벤트syslog.setlogmask를 발생시킵니다.
모듈은 다음 상수를 정의합니다:
- syslog.LOG_EMERG¶
- syslog.LOG_ALERT¶
- syslog.LOG_CRIT¶
- syslog.LOG_ERR¶
- syslog.LOG_WARNING¶
- syslog.LOG_NOTICE¶
- syslog.LOG_INFO¶
- syslog.LOG_DEBUG¶
우선순위 수준 (높음에서 낮음 순서).
- syslog.LOG_AUTH¶
- syslog.LOG_AUTHPRIV¶
- syslog.LOG_CRON¶
- syslog.LOG_DAEMON¶
- syslog.LOG_FTP¶
- syslog.LOG_INSTALL¶
- syslog.LOG_KERN¶
- syslog.LOG_LAUNCHD¶
- syslog.LOG_LPR¶
- syslog.LOG_MAIL¶
- syslog.LOG_NETINFO¶
- syslog.LOG_NEWS¶
- syslog.LOG_RAS¶
- syslog.LOG_REMOTEAUTH¶
- syslog.LOG_SYSLOG¶
- syslog.LOG_USER¶
- syslog.LOG_UUCP¶
- syslog.LOG_LOCAL0¶
- syslog.LOG_LOCAL1¶
- syslog.LOG_LOCAL2¶
- syslog.LOG_LOCAL3¶
- syslog.LOG_LOCAL4¶
- syslog.LOG_LOCAL5¶
- syslog.LOG_LOCAL6¶
- syslog.LOG_LOCAL7¶
시설,
LOG_AUTHPRIV,LOG_FTP,LOG_NETINFO,LOG_REMOTEAUTH,LOG_INSTALL및LOG_RAS는<syslog.h>에 정의되었을 때만 제공됩니다.버전 3.13에서 변경:
LOG_FTP,LOG_NETINFO,LOG_REMOTEAUTH,LOG_INSTALL,LOG_RAS및LOG_LAUNCHD를 추가했습니다.
- syslog.LOG_PID¶
- syslog.LOG_CONS¶
- syslog.LOG_NDELAY¶
- syslog.LOG_ODELAY¶
- syslog.LOG_NOWAIT¶
- syslog.LOG_PERROR¶
로그 옵션,
LOG_ODELAY,LOG_NOWAIT및LOG_PERROR는<syslog.h>에 정의되었을 때만 제공됩니다.
예제¶
간단한 예제¶
간단한 예제 집합:
import syslog
syslog.syslog('Processing started')
if error:
syslog.syslog(syslog.LOG_ERR, 'Processing started')
일부 로그 옵션 설정의 예, 이것은 로그 메시지에 프로세스 ID를 포함하며, 메일 로깅에 사용되는 대상 시설로 메시지를 기록합니다:
syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_MAIL)
syslog.syslog('E-mail processing initiated...')