当前位置:网站首页>Code debugging - print log output to file
Code debugging - print log output to file
2022-06-12 13:31:00 【Boring ah le】
1、 Output log to file function
void logprintf(const char *fmt, ...)// Custom variable parameter function
{
static int bLogFirstOpen = 0; // Static local variables defined in the function body , Its lifetime is the same as that of the global variable , Keep it throughout the program ;
// Its visibility is the same as that of local variables , Only inside this function can this variable be accessed through this variable name .
static char* Log_file = "./libskf_log.txt";// Log file name
char message[MAX_LOG_SIZE];
memset(message, 0, MAX_LOG_SIZE);
// current time .
time_t timer = time(NULL);
strftime(message, 23, "[%Y-%m-%d %H:%M:%S] ", localtime(&timer));// Current error time
va_list args;
va_start(args, fmt);// The first parameter : Variable parameter list the second : The type of variable parameter 、 Number and order
vsnprintf(message + 22, MAX_LOG_SIZE - 22, fmt, args);
va_end(args);
FILE * fd = 0;
if (bLogFirstOpen == 0)
{
fd = fopen(Log_file, "wt+");
bLogFirstOpen = 1;
}
else
{
fd = fopen(Log_file, "at+");
}
size_t len = strlen(message);
fwrite(message, 1, len, fd);
fclose(fd);
}
2、 usage
rv = SKF_MacFinal(hMac, encdata, &enclen);
if (rv != SAR_OK)
{
logprintf("SKF_MacFinal ERROR, errno[0x%08x]\n", rv);// Output error log to file
return -1;
}
边栏推荐
猜你喜欢

The goods are full. You must take this knowledge

镜像扫描工具预研

【刷题篇】超级洗衣机

leetcode 47. Permutations II full permutations II (medium)

【微信小程序开发】第1篇:开发工具安装及程序配置

leetcode 47. Permutations II 全排列 II(中等)

Implementing tensorflow deep learning framework similarflow with numpy

"New continent" of mobile application going to sea

Wechat web developer tools tutorial, web development issues

Pytoch official fast r-cnn source code analysis (I) -- feature extraction
随机推荐
Deploy opengauss database based on Huawei cloud Kunpeng elastic ECS [Gauss is not a mathematician this time]
AVFoundation
创新实训(十)高级界面美化
TCP的“非”可靠性
C language array and pointer
D1 哪吒开发板 了解基本的启动加载流程
1001:Hello,World
Further understanding of the network
Realization of Joseph Ring with one-way ring linked list
torch_ About the geometric Mini batch
基于华为云鲲鹏弹性云服务器ECS部署openGauss数据库【这次高斯不是数学家】
2062: [example 1.3] movie tickets
Application of bit operation in C language
Overview of embedded system 2- composition and application of embedded system
达梦数据库DM8 windows环境安装
hudi 键的生成(Key Generation)
import torch_geometric 的Data 查看
[embedded] serial communication and its case
2064: [example 2.1] exchange value
import torch_ Data view of geometric