-
Notifications
You must be signed in to change notification settings - Fork 11
/
logger.c
40 lines (35 loc) · 928 Bytes
/
logger.c
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
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <stdlib.h>
#include "logger.h"
#include "config.h"
#include <time.h>
int level_cfg;
int init_level_cfg() {
level_cfg = getConfigInt("logLevel");
return 0;
}
int recipeLog(int level, char *process, char *subProcess, char *activity, char *entry) {
if (level_cfg >= level) {
int hours, mins, secs, month, day, year;
time_t now;
time(&now);
struct tm* local = localtime(&now);
hours = local->tm_hour;
mins = local->tm_min;
secs = local->tm_sec;
day = local->tm_mday;
month = local->tm_mon + 1;
year = local->tm_year + 1900;
char date[100];
char data[200];
sprintf(date, "[%d-%02d-%02d %02d:%02d:%02d]", year, month, day, hours, mins, secs);
sprintf(data, "[%s][%s][%s][%s]\n", process, subProcess, activity, entry);
printf("%s", date);
printf("%s", data);
FILE* fp = fopen("recipes.log", "a");
fputs(date, fp);
fputs(data, fp);
fclose(fp);
}
return 0;
}