当前位置:网站首页>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;
}
边栏推荐
- Deploy opengauss database based on Huawei cloud Kunpeng elastic ECS [Gauss is not a mathematician this time]
- How to balance multiple losses in deep learning?
- Record some settings for visual studio 2019
- 在 Debian 10 上独立安装MySQL数据库
- TCP的“非”可靠性
- xcode 调试openGLES
- C language [23] classic interview questions [2]
- Qualcomm platform development series (Protocol) QMI brief introduction and usage
- leetcode 47. Permutations II 全排列 II(中等)
- 2062: [example 1.3] movie tickets
猜你喜欢
FFmpeg 学习指南

How to balance multiple losses in deep learning?

高通平台开发系列讲解(协议篇)QMI简单介绍及使用方法

Script引入CDN链接提示net::ERR_FILE_NOT_FOUND问题

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

Script import CDN link prompt net:: err_ FILE_ NOT_ Found problem

Paw 高级使用指南
![2061: [example 1.2] trapezoidal area](/img/83/79b73ca10615c852768aba8d2a5049.jpg)
2061: [example 1.2] trapezoidal area

关于#SQLite写注册功能时,数据表查询出错#的问题,如何解决?

Chrome debugging tool
随机推荐
torch_ geometric message passing network
How to solve the problem of data table query error when SQLite writes the registration function?
创新实训(十)高级界面美化
多源BFS问题 模板(附题)
The goods are full. You must take this knowledge
list和dict的应用
Application of binary search -- finding the square root sqrt of a number
imagemagick:a gentle introduction to magick++
JVM runtime parameters
A brief introduction to Verilog mode
leetcode 47. Permutations II 全排列 II(中等)
Informatics Olympiad all in one 2059: [example 3.11] buy a pen
Innovation training (x) advanced interface beautification
Automatic Generation of Visual-Textual Presentation Layout
1005: estimation of the earth's population carrying capacity
2066: [example 2.3] buying books
Pytorch framework
"New continent" of mobile application going to sea
import torch_geometric 加载一些常见数据集
Django note 21: querying databases using native SQL