linux在哪里存储我的系统日志

linux在哪里存储我的系统日志

本文介绍了linux在哪里存储我的系统日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个简单的测试应用程序,以将某些内容记录到日志文件中.我正在使用 linux mint ,并且在应用程序执行后,我尝试使用以下命令查看日志:

I wrote a simple test application to log something in a log file. I am using linux mint and after the application executes I try to view the log using this command:

tail -n 100 /var/log/messages

,但是文件消息既不经过测试也不存在.您可以在下面找到我的代码.也许我做错了什么,该文件未存储在该文件中,或者我需要启用Linux Mint中的登录功能.

but the file messages does not exist neither tested or something. Below you can find my code. Maybe I am doing something wrong, the file isn't stored there or I need to enable logging in 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看到输出.

On my Ubuntu machine, I can see the output at /var/log/syslog.

在RHEL/CentOS计算机上,在/var/log/messages中找到输出.

On a RHEL/CentOS machine, the output is found in /var/log/messages.

这是由rsyslog服务控制的,因此,如果出于某些原因将其禁用,则可能需要使用systemctl start rsyslog启动它.

This is controlled by the rsyslog service, so if this is disabled for some reason you may need to start it with systemctl start rsyslog.

正如其他人所指出的,您的syslog()输出将由/var/log/syslog文件记录.
您可以在/var/log上查看系统,用户和其他日志.

As noted by others, your syslog() output would be logged by the /var/log/syslog file.
You can see system, user, and other logs at /var/log.

有关更多详细信息:这是一个有趣的链接.

For more details: here's an interesting link.

这篇关于linux在哪里存储我的系统日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 11:24