当前位置:网站首页>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;
}
边栏推荐
- Pytoch official fast r-cnn source code analysis (I) -- feature extraction
- torch_geometric message passing network
- 2068: [example 2.6] chicken and rabbit in the same cage
- Innovation training (XII) project summary
- Application of binary search -- finding the square root sqrt of a number
- Install MySQL database independently on Debian 10
- 微信web开发者工具使用教程,web开发问题
- Volume mount and mirror creation
- Chaotic engineering practice of distributed kV storage in station B
- 5V升压到12.6V的锂电池充电IC芯片方案FS4062B
猜你喜欢

torch_ About the geometric Mini batch

leetcode 47. Permutations II full permutations II (medium)

Actual combat | realizing monocular camera ranging by skillfully using pose solution

Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading

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

章鱼网络进展月报 | 2022.5.1-5.31

智能垃圾桶语音芯片应用设计方案介绍,WT588F02B-8S

Introduction to application design scheme of intelligent garbage can voice chip, wt588f02b-8s

Cocoapods的相关知识点

Innovation training (x) advanced interface beautification
随机推荐
干货满满,这些知识你必须拿下
章鱼网络进展月报 | 2022.5.1-5.31
The goods are full. You must take this knowledge
Rk3399 platform development series explanation (kernel debugging chapter) 2.50 use of systrace
How to adapt the page size when iframe is embedded in a web page
字节序数据读写
Paw 高级使用指南
Actual combat | realizing monocular camera ranging by skillfully using pose solution
Informatics Olympiad all in one 2059: [example 3.11] buy a pen
C language structure
Record some settings for visual studio 2019
Introduction to application design scheme of intelligent garbage can voice chip, wt588f02b-8s
Redis消息队列重复消费问题
Successfully rated Tencent t3-2, 10000 word parsing
FFmpeg 学习指南
leetcode 47. Permutations II 全排列 II(中等)
Application of list and Dict
Qualcomm platform development series (Protocol) QMI brief introduction and usage
Installation of pagoda
Volume mount and mirror creation