zoukankan      html  css  js  c++  java
  • 树莓派 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 );
        }
    }

  • 相关阅读:
    14.3 Go iris
    14.2 Go性能优化
    14.1 Go数据结构
    13.3 Go章节练习题
    13.2 Go练习题答案
    13.1 Go练习题
    12.1 Go nsq
    11.3 Go 开发博客
    11.2Go gin
    11.1 Go Http
  • 原文地址:https://www.cnblogs.com/suozhang/p/9407060.html
Copyright © 2011-2022 走看看