• 树莓派 log 日志 打印到 TXT


    #include<stdio.h>
    
    #include <stdarg.h>
    
    #include <unistd.h>
    
    #include <stdint.h>
    
    #include <stdarg.h>
    
    #include <fcntl.h>
    
    #include <time.h>
    
    int vAppLogPrintf( uint8_t *buff, uint32_t len )
    {
            
        int f_log;
        
        f_log = open( "log.txt", O_CREAT|O_RDWR, 0755 );
    
        if( f_log < 0 )
        {
            return -1;
        } 
    
        //将文件写入指针 移动到文件结尾
        lseek( f_log, 0, SEEK_END );
        
        //将消息缓冲区 写入到文件
        write( f_log, buff, len );
        
        close( f_log );
        
        return 0;
    
    }
    
    int appLogPrintf(const char *fmt, ...)
    {
        va_list args;
        int r,printed_len;
        static char printk_buf[1024];
    
        va_start(args, fmt);
        /* Emit the output into the temporary buffer */
        printed_len = vsnprintf(printk_buf, sizeof(printk_buf), fmt, args);
        va_end(args);
    
        return vAppLogPrintf( printk_buf, printed_len );
    
    }
    
    int main( int argc, char **argv )
    {
        time_t systemTimeNow;
        
        for( ;; )
        {
                
            systemTimeNow = time( NULL );/* 获取当前系统时间 */
        
            appLogPrintf( "hello,world,%s
    ", ctime( &systemTimeNow ) );
            
            printf( "hello,world,%s
    ", ctime( &systemTimeNow ) );
            
            sleep( 1 );
        }
    }

  • 相关阅读:
    面试题汇总--1
    行内元素与块级元素
    前端面试题整理---JS基础
    springmvc处理一个请求的全流程
    反射+动态代理+类加载+JVM
    json注解及序列化
    加密
    Thread setUncaughtExceptionHandler
    RunTime.getRunTime().addShutdownHook 添加钩子
    MySQL日志
  • 原文地址:https://www.cnblogs.com/suozhang/p/9407060.html
Copyright © 2020-2023  润新知