Redirecting standard output to syslog

前端 未结 5 1190
半阙折子戏
半阙折子戏 2021-01-01 20:57

I\'m planning to package OpenTibia Server for Debian. One of the things I want to do is add startup via /etc/init.d and daemonization of the otserv

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 21:23

    I just wrote some code that will do this. It's using ASL instead of syslog, and it's using kevents, so you may need to port it to different APIs for your system (syslog instead of ASL and poll/select instead of kevent)

    http://cgit.freedesktop.org/xorg/app/xinit/tree/launchd/console_redirect.c

    Furthermore, I basically added this to libsystem_asl on Mountain Lion. Check out the man page for asl_log_descriptor.

    Example:

    #include 
    #include 
    #include 
    #include 
    
    int main() {
        asl_log_descriptor(NULL, NULL, ASL_LEVEL_INFO, STDOUT_FILENO, ASL_LOG_DESCRIPTOR_WRITE);
        asl_log_descriptor(NULL, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO, ASL_LOG_DESCRIPTOR_WRITE);
        fprintf(stdout, "This is written to stdout which will be at log level info.");
        fprintf(stderr, "This is written to stderr which will be at log level notice.");
        return 0;
    }
    

提交回复
热议问题