Linux中的守护程序日志记录 [英] Daemon logging in Linux

查看:105
本文介绍了Linux中的守护程序日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个在Linux系统上运行的守护程序,我想要记录其活动:日志.问题是,完成此任务的最佳"方法是什么?

So I have a daemon running on a Linux system, and I want to have a record of its activities: a log. The question is, what is the "best" way to accomplish this?

我的第一个想法是简单地打开一个文件并将其写入.

My first idea is to simply open a file and write to it.

FILE* log = fopen("logfile.log", "w");
/* daemon works...needs to write to log */
fprintf(log, "foo%s\n", (char*)bar);
/* ...all done, close the file */
fclose(log);

以这种方式记录是否有天生的错误?有没有更好的方法,例如Linux内置的某些框架?

Is there anything inherently wrong with logging this way? Is there a better way, such as some framework built into Linux?

推荐答案

Unix长期以来一直使用一种名为系统日志.输入您的外壳程序

Unix has had for a long while a special logging framework called syslog. Type in your shell

man 3 syslog

,您将获得C接口的帮助.

and you'll get the help for the C interface to it.

有些

这篇关于Linux中的守护程序日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆