~ruther/CTU-FEE-B0B35APO-Semestral-project

ref: 4c2fc8e87b643bedf604ca9854273fa5a073dcb4 CTU-FEE-B0B35APO-Semestral-project/lib-pheripherals/include/logger.h -rw-r--r-- 3.2 KiB
4c2fc8e8 — František Boháček fix: text viewer wrong character 3 years ago
                                                                                
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef __LOGGER_H__
#define __LOGGER_H__

#include <stdio.h>

#define DEBUG_PREFIX "[DEBG]"
#define INFO_PREFIX "[INFO]"
#define WARN_PREFIX "[WARN]"
#define ERROR_PREFIX "[ERRO]"

typedef enum LogLevel {
  LOG_DEBUG = 1,
  LOG_INFO = 2,
  LOG_WARN = 3,
  LOG_ERROR = 4,
} LogLevel;

typedef struct logger_t logger_t;

struct logger_t {
  FILE *debugFile;
  FILE *infoFile;
  FILE *warningFile;
  FILE *errorFile;

  LogLevel minimalLevel;

  logger_t *childLogger; // Duplicate logs to this logger
};

/**
 * @brief Create logger_t
 *
 * @param minimalLevel minimal level to log, levels below this one will not be
 * logged
 * @param debugFile file to output debug level to
 * @param infoFile file to output input level to
 * @param warningFile file to output warning level to
 * @param errorFile file to output error level to
 * @param childLogger child logger that will be called every log to use for
 * duplicating to another file
 * @return logger_t
 */
logger_t logger_create(LogLevel minimalLevel, FILE *debugFile, FILE *infoFile,
                       FILE *warningFile, FILE *errorFile,
                       logger_t *childLogger);
/**
 * @brief Log given message
 *
 * @param logger
 * @param level level of log
 * @param file name of file __FILE__
 * @param function name of function __FUNCTION__
 * @param line number of line __LINE__
 * @param message message with format like printf
 * @param ... arguments to printf
 */
void logger_log(logger_t *logger, LogLevel level, const char *file,
                const char *function, int line, const char *const message, ...);

/**
 * @brief Log given debug message
 *
 * @param logger
 * @param file name of file __FILE__
 * @param function name of function __FUNCTION__
 * @param line number of line __LINE__
 * @param message message with format like printf
 * @param ... arguments to printf
 */
void logger_debug(logger_t *logger, const char *file, const char *function,
                  int line, const char *const message, ...);

/**
 * @brief Log given info message
 *
 * @param logger
 * @param file name of file __FILE__
 * @param function name of function __FUNCTION__
 * @param line number of line __LINE__
 * @param message message with format like printf
 * @param ... arguments to printf
 */
void logger_info(logger_t *logger, const char *file, const char *function,
                 int line, const char *const message, ...);

/**
 * @brief Log given warn message
 *
 * @param logger
 * @param file name of file __FILE__
 * @param function name of function __FUNCTION__
 * @param line number of line __LINE__
 * @param message message with format like printf
 * @param ... arguments to printf
 */
void logger_warn(logger_t *logger, const char *file, const char *function,
                 int line, const char *const message, ...);

/**
 * @brief Log given error message
 *
 * @param logger
 * @param file name of file __FILE__
 * @param function name of function __FUNCTION__
 * @param line number of line __LINE__
 * @param message message with format like printf
 * @param ... arguments to printf
 */
void logger_error(logger_t *logger, const char *file, const char *function,
                  int line, const char *const message, ...);

#endif //__LOGGER_H__
Do not follow this link