rsyslog - syslog 程序无法写入 /var/log/messages 文件
问题描述
编写系统日志消息的程序。
#include <stdio.h>
#include <unistd.h>
#include <syslog.h>
int main(void) {
openlog("slog", LOG_PID|LOG_CONS, LOG_USER);
syslog(LOG_INFO, "A different kind of Hello world ... ");
closelog();
return 0;
}
解决方案
为我工作
% cat > syslog.c
#include <stdio.h>
#include <unistd.h>
#include <syslog.h>
int main(void) {
openlog("slog", LOG_PID|LOG_CONS, LOG_USER);
syslog(LOG_INFO, "A different kind of Hello world ... ");
closelog();
return 0;
}
% cc syslog.c
% ./a.out
% tail /var/log/messages
tail: cannot open ‘/var/log/messages’ for reading: Permission denied
% su
Password:
[root@build-centos7 src]# tail /var/log/messages | grep slog
Sep 17 13:09:10 build-centos7 slog[3040]: A different kind of Hello world ...
推荐阅读
- mqtt - MQTT 集群信息
- ruby-on-rails - Ruby 函数搜索栏
- r - 如何从 R 中的面板数据中删除不平衡组
- php - 使用 php 生成一个包含字符和数字的唯一字符串,如 ABCD1234
- python - 通过管道从 C++ 到 Python 的数据传输 (pywin32)
- javascript - 是否可以使用 javascript 和/或 Node.js 登录到经过 SAML 身份验证的应用程序?
- firebase - Firebase 身份验证仅管理员登录
- python - 根据 Mongo 中的特定索引查询 2 个数组
- php - Carbon::now 显示错误的时间,除非格式化
- ruby-on-rails - CanCan::NotImplemented(此模型适配器不支持从数据库中获取记录。):