| + logger

巧用'|' 和 logger 方便快捷实现日志功能

main.c

#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
        int i = 0;
        while(1)
        {
                printf("hello world %d\n", i++);
                fflush(stdout);
                sleep(1);
        }
        return 0;
}

正常启动时,程序输出打印到标准输出;使用 | logger -t a.out 后 ,程序输出打印到logger日志文件中,可使用logread命令查看。

 

posted @ 2018-08-13 18:26  liyongjun  阅读(232)  评论(0编辑  收藏  举报