O2S C Library
1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1
#pragma once
2
3
/* ************************************************************************** */
4
/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
5
/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
6
/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
7
/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
8
/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
9
/* */
17
/* ************************************************************************** */
18
19
#include "
o2s/thread.h
"
// o2s_thread_name
20
21
#include <stdio.h>
// fprintf, stderr
22
23
#define LOG_LEVEL_NONE 0
24
#define LOG_LEVEL_FATAL 1
25
#define LOG_LEVEL_ERROR 2
26
#define LOG_LEVEL_WARNING 3
27
#define LOG_LEVEL_INFO 4
28
#define LOG_LEVEL_DEBUG 5
29
#define LOG_LEVEL_TRACE 6
30
33
#ifndef LOG_LEVEL
35
# define LOG_LEVEL LOG_LEVEL_INFO
36
#endif
37
38
#ifndef LOG_OUTPUT_FILE
40
# define LOG_OUTPUT_FILE stderr
41
#endif
43
44
#define log_log(LEVEL, COLOR, FORMAT, ...) \
45
fprintf(LOG_OUTPUT_FILE, \
46
"[\e[" COLOR "m" LEVEL "\e[0m %.8s \e[2m" __FILE__ \
47
":%s:%02i\e[0m] " FORMAT "\n", \
48
o2s_thread_name, \
49
__FUNCTION__, \
50
__LINE__, \
51
##__VA_ARGS__)
52
53
#if LOG_LEVEL >= LOG_LEVEL_TRACE
54
# define log_trace(...) log_log("TRACE", "0", __VA_ARGS__)
55
#else
57
# define log_trace(...)
58
#endif
59
60
#if LOG_LEVEL >= LOG_LEVEL_DEBUG
61
# define log_debug(...) log_log("DEBUG", "34", __VA_ARGS__)
62
#else
64
# define log_debug(...)
65
#endif
66
67
#if LOG_LEVEL >= LOG_LEVEL_INFO
69
# define log_info(...) log_log("INFO ", "1;32", __VA_ARGS__)
70
#else
71
# define log_info(...)
72
#endif
73
74
#if LOG_LEVEL >= LOG_LEVEL_WARNING
76
# define log_warning(...) log_log("WARN ", "1;33", __VA_ARGS__)
77
#else
78
# define log_warning(...)
79
#endif
80
81
#if LOG_LEVEL >= LOG_LEVEL_ERROR
83
# define log_error(...) log_log("ERROR", "1;31", __VA_ARGS__)
84
#else
85
# define log_error(...)
86
#endif
87
88
#if LOG_LEVEL >= LOG_LEVEL_FATAL
90
# define log_fatal(...) log_log("FATAL", "1;97;41", __VA_ARGS__)
91
#else
92
# define log_fatal(...)
93
#endif
thread.h
Thread-specific global and its setter.
include
o2s
log.h
Generated on
for O2S C Library by
1.14.0