Steward
分享是一種喜悅、更是一種幸福
程式語言 - GNU - C/C++ - System Log
參考資訊:
https://github.com/pasce/daemon-skeleton-linux-c
main.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <sys/types.h> #include <sys/stat.h> #include <syslog.h> int main ( int argc, char **argv) { openlog ( "hello" , LOG_PID , LOG_DAEMON ); syslog ( LOG_NOTICE , "Hello, world!" ); closelog (); return 0; } |
執行
$ gcc main.c -o main $ ./main $ journalctl -q | grep -i hello May 18 10:24:13 debian hello[7323]: Hello, world!
P.S. Ubuntu系統下可以察看/var/log/syslog