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

编程入门 行业动态 更新时间:2024-10-27 08:24:37
本文介绍了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在哪里存储我的系统日志?

本文发布于:2023-10-19 14:29:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1507801.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:系统   日志   linux

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!