NVMLib
very early alpha
A library to optimally use a Hybrid RAM setup.
log.h
Go to the documentation of this file.
1
14
15
#ifndef __NVM_LOGGER__
16
#define __NVM_LOGGER__
17
18
#include <time.h>
19
#include <string.h>
20
#include "
globals.h
"
21
22
// === auxiliar functions
23
static
inline
char
*
timenow
();
24
25
#define _FILE strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__
26
27
#define NO_LOG 0x00
28
#define ERROR_LEVEL 0x01
29
#define INFO_LEVEL 0x02
30
#define DEBUG_LEVEL 0x03
31
32
#ifndef LOG_LEVEL
33
#define LOG_LEVEL DEBUG_LEVEL
34
#endif
35
36
#define PRINTFUNCTION(format, ...) fprintf(MAIN_LOG_FILE, format, __VA_ARGS__); fflush(MAIN_LOG_FILE)
37
38
#define LOG_FMT "%s | %-7s | %-15s | %s:%d | "
39
#define LOG_ARGS(LOG_TAG) timenow(), LOG_TAG, _FILE, __FUNCTION__, __LINE__
40
41
#define NEWLINE "\n"
42
43
#define ERROR_TAG "ERROR"
44
#define INFO_TAG "INFO"
45
#define DEBUG_TAG "DEBUG"
46
47
#if LOG_LEVEL >= DEBUG_LEVEL
48
#define LOG_DEBUG(message, args...) PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(DEBUG_TAG), ## args)
49
#else
50
#define LOG_DEBUG(message, args...)
51
#endif
52
53
#if LOG_LEVEL >= INFO_LEVEL
54
#define LOG_INFO(message, args...) PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(INFO_TAG), ## args)
55
#else
56
#define LOG_INFO(message, args...)
57
#endif
58
59
#if LOG_LEVEL >= ERROR_LEVEL
60
#define LOG_ERROR(message, args...) PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(ERROR_TAG), ## args)
61
#else
62
#define LOG_ERROR(message, args...)
63
#endif
64
65
#if LOG_LEVEL >= NO_LOGS
66
#define LOG_IF_ERROR(condition, message, args...) if (condition) PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(ERROR_TAG), ## args)
67
#else
68
#define LOG_IF_ERROR(condition, message, args...)
69
#endif
70
71
static
inline
char
*
timenow
() {
72
static
char
buffer[64];
73
time_t rawtime;
74
struct
tm *timeinfo;
75
76
time(&rawtime);
77
timeinfo = localtime(&rawtime);
78
79
strftime(buffer, 64,
"%Y-%m-%d %H:%M:%S"
, timeinfo);
80
81
return
buffer;
82
}
83
84
#endif // !__NVM_LOGGER__
timenow
static char * timenow()
Definition:
log.h:71
globals.h
src_c_new
log.h
Generated by
1.8.18