简体   繁体   English

linux c程序除了读取/ var / log中的文件外,还有另一种读取日志的方法吗?

[英]linux c program is there another way to read logs than reading files in /var/log?

Hello dear community of stackoverflow, 您好亲爱的stackoverflow社区,

at the moment im programming a tool in c that monitors the linux log files which can be found in /var/log, the c program reads the logs directly from the log files but reading the log files from an c program is is not very good because the user can manipulate log files or the logs got saved in different file eg instead it got saved in syslog it got saved in syslog.1. 目前,我正在用c编程工具监视/ var / log中的linux日志文件,c程序直接从日志文件中读取日志,但是从c程序中读取日志文件不是很好因为用户可以操纵日志文件或将日志保存在其他文件中,例如,而是将其保存在syslog中,所以将其保存在syslog.1中。

Because of this disadvantages i want to ask if there is any alternative in linux instead of reading the files? 由于这个缺点,我想问一下在Linux中是否有替代方法而不是读取文件? Maybe it is possible with an kernel module that catches these logs? 捕获这些日志的内核模块是否有可能?

Thank you for any answer! 谢谢您的回答!

An alternate is to use either /proc/kmsg or /dev/kmsg . 另一种方法是使用/proc/kmsg/dev/kmsg User cannot modify these sources of logs. 用户无法修改这些日志源。 Format will be a bit different but you can change your program to adapt it. 格式会有所不同,但是您可以更改程序以适应它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Linux C程序检查是否存在并读取/ proc文件 - check existence and read /proc files with Linux C program 在C中,附加到打开的文件以供Windows控制台和Linux上的另一个程序读取 - In C, append to file open for read by another program on Windows console and Linux 读取 C 中的文件时,该文件是否需要与程序位于同一文件夹中? 如果是这样,有没有办法读取另一个文件夹中的文件? - When reading a file in C, does the file needs to be in the same folder as the program? And if so, is there any way to read a file in another folder? Linux重定向到C程序-文件读取 - Linux Redirection to C program - File Reading 使用C程序在Linux中读取目录 - reading directory in linux using c program Linux&C:如何在录制mp4文件时在多进程程序中设置文件读取优先级 - Linux & C: How to set file reading priority in multi-process program while recording mp4 files C 程序读取文件读取额外行 - C program to read file reading an extra line 在LINUX上使用AC程序读取/ dev / ttyUSB0 - Read /dev/ttyUSB0 with a c program on LINUX 写入另一个程序的stdin /从c中的另一个程序的stdout读取 - writing to stdin of another program/reading from stdout of another program in c 用javascript读取C程序的输出文件 - Reading C program's output files in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM