我写了一个简单的测试应用程序来记录日志文件中的内容.我正在使用linux mint,在应用程序执行后,我尝试使用此命令查看日志:
tail -n 100 /var/log/messages
Run Code Online (Sandbox Code Playgroud)
但文件消息既不存在,也不存在.您可以在下面找到我的代码.也许我做错了什么,文件没有存储在那里或者我需要启用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;
}
Run Code Online (Sandbox Code Playgroud)
Rob*_*lty 21
除了接受的答案,了解以下内容是有用的...
这些功能中的每一个都应具有与之关联的手册页.
如果运行man -k syslog(手册页的关键字搜索),您将获得一个引用或关于syslog的手册页列表
$ 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
Run Code Online (Sandbox Code Playgroud)
您需要了解手册部分以便进一步深入研究.
这是man的手册页的摘录,它解释了man page部分:
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]
Run Code Online (Sandbox Code Playgroud)
阅读上面的内容
$man man
Run Code Online (Sandbox Code Playgroud)
因此,如果您运行,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);
Run Code Online (Sandbox Code Playgroud)
不是直接的答案,但希望你会发现这很有用.
rko*_*egi 19
默认日志位置(rhel)是
一般信息:
/var/log/messages
Run Code Online (Sandbox Code Playgroud)
验证消息:
/var/log/secure
Run Code Online (Sandbox Code Playgroud)
邮件事件:
/var/log/maillog
Run Code Online (Sandbox Code Playgroud)
检查你的/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
Run Code Online (Sandbox Code Playgroud)
小智 8
您必须告诉系统要记录哪些信息以及将信息放在何处.在cat /etc/rsyslog.conf文件中配置日志记录,重启rsyslog以加载新配置.默认日志记录规则通常位于文件/etc/rsyslog.d/50-default.conf中.
小智 5
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内核日志)。