How to write an C/C++ application that writes to a /var/log/myapp directory?

笑着哭i 提交于 2019-12-04 03:19:57

No, no no no. No suid for such stuff. These logs are managed by a process known as "syslog" and there is an API to send messages to this logger:

   void openlog(const char *ident, int option, int facility);
   void syslog(int priority, const char *format, ...);
   void closelog(void);

Or you can type 'man syslog' on the command line and get all the info :-)

Update: you will need permissions to edit syslog's configuration file to send message to a separate log file, otherwise they will end up in the default location (probably /var/log/syslog).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!