-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwrite_log.c
More file actions
29 lines (23 loc) · 745 Bytes
/
Copy pathwrite_log.c
File metadata and controls
29 lines (23 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "write_log.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LOGFILE "video.runlog"
#define LEV_NUM 5
#define MSG_BUF 1024
char *Level[LEV_NUM] = {"DEBUG","INFO","WARNING","ERROR","URGENT"};
void write_log(int lev,const char*func,const char* msg)
{
char buf[MSG_BUF] = {0};
if(lev>=LEV_NUM||strlen(msg)>=(MSG_BUF/2))
{
sprintf(buf,"%s '[%-s] [%-s] [%-s]' >> %s",
"date '+%Y-%m-%d %H:%M:%S'|xargs -i echo [{}]","URGENT","*NULL*","please check log LEVEL or MSG length!",LOGFILE);
}
else
{
sprintf(buf,"%s '[%-s] [%-s] [%-s]' >> %s",
"date '+%Y-%m-%d %H:%M:%S'|xargs -i echo [{}]",Level[lev],func,msg,LOGFILE);
}
system(buf);
}