-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrmc_log.h
65 lines (54 loc) · 3.57 KB
/
rmc_log.h
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
// Copyright (C) 2018, Jaguar Land Rover
// This program is licensed under the terms and conditions of the
// Mozilla Public License, version 2.0. The full text of the
// Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
//
// Author: Magnus Feuer (mfeuer1@jaguarlandrover.com)
#ifndef __RMC_LOG_H__
#define __RMC_LOG_H__
#include <stdio.h>
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
#define RMC_LOG_LEVEL_NONE 0
#define RMC_LOG_LEVEL_FATAL 1
#define RMC_LOG_LEVEL_ERROR 2
#define RMC_LOG_LEVEL_WARNING 3
#define RMC_LOG_LEVEL_INFO 4
#define RMC_LOG_LEVEL_COMMENT 5
#define RMC_LOG_LEVEL_DEBUG 6
extern char* rmc_log_timestamp(char* target);
extern void rmc_log_set_start_time(void);
extern usec_timestamp_t rmc_log_get_start_time(void);
extern void rmc_log_use_color(int use_color);
extern int rmc_set_log_level(int log_level);
extern void rmc_log(int log_level, const char* func, const char* file, int line, uint16_t index, const char* fmt, ...);
extern const char* rmc_log_color_none();
extern const char* rmc_log_color_faint();
extern const char* rmc_log_color_green();
extern const char* rmc_log_color_blue();
extern const char* rmc_log_color_orange();
extern const char* rmc_log_color_red();
extern const char* rmc_log_color_flashing_red();
extern const char* rmc_index_color(int index);
extern int _rmc_log_level;
#ifndef RMC_NIL_INDEX
#define RMC_NIL_INDEX 0x7FFF
#endif
#define RMC_LOG_DEBUG(fmt, ...) { if (_rmc_log_level >= RMC_LOG_LEVEL_DEBUG) rmc_log(RMC_LOG_LEVEL_DEBUG, __FUNCTION__, __FILE__, __LINE__, RMC_NIL_INDEX, fmt, ##__VA_ARGS__ ); }
#define RMC_LOG_COMMENT(fmt, ...) { if (_rmc_log_level >= RMC_LOG_LEVEL_COMMENT) rmc_log(RMC_LOG_LEVEL_COMMENT, __FUNCTION__, __FILE__, __LINE__, RMC_NIL_INDEX, fmt, ##__VA_ARGS__ ); }
#define RMC_LOG_INFO(fmt, ...) { if (_rmc_log_level >= RMC_LOG_LEVEL_INFO) rmc_log(RMC_LOG_LEVEL_INFO, __FUNCTION__, __FILE__, __LINE__, RMC_NIL_INDEX, fmt, ##__VA_ARGS__); }
#define RMC_LOG_WARNING(fmt, ...) { if (_rmc_log_level >= RMC_LOG_LEVEL_WARNING) rmc_log(RMC_LOG_LEVEL_WARNING, __FUNCTION__, __FILE__, __LINE__, RMC_NIL_INDEX, fmt, ##__VA_ARGS__); }
#define RMC_LOG_ERROR(fmt, ...) { if (_rmc_log_level >= RMC_LOG_LEVEL_ERROR) rmc_log(RMC_LOG_LEVEL_ERROR, __FUNCTION__, __FILE__, __LINE__, RMC_NIL_INDEX, fmt, ##__VA_ARGS__); }
#define RMC_LOG_FATAL(fmt, ...) { if (_rmc_log_level >= RMC_LOG_LEVEL_FATAL) rmc_log(RMC_LOG_LEVEL_FATAL, __FUNCTION__, __FILE__, __LINE__, RMC_NIL_INDEX, fmt, ##__VA_ARGS__); }
#define RMC_LOG_INDEX_DEBUG(index, fmt, ...) { if (_rmc_log_level >= RMC_LOG_LEVEL_DEBUG) rmc_log(RMC_LOG_LEVEL_DEBUG, __FUNCTION__, __FILE__, __LINE__, index, fmt, ##__VA_ARGS__ ); }
#define RMC_LOG_INDEX_COMMENT(index, fmt, ...) { if (_rmc_log_level >= RMC_LOG_LEVEL_COMMENT) rmc_log(RMC_LOG_LEVEL_COMMENT, __FUNCTION__, __FILE__, __LINE__, index, fmt, ##__VA_ARGS__ ); }
#define RMC_LOG_INDEX_INFO(index, fmt, ...) { if (_rmc_log_level >= RMC_LOG_LEVEL_INFO) rmc_log(RMC_LOG_LEVEL_INFO, __FUNCTION__, __FILE__, __LINE__, index, fmt, ##__VA_ARGS__); }
#define RMC_LOG_INDEX_WARNING(index, fmt, ...) { if (_rmc_log_level >= RMC_LOG_LEVEL_WARNING) rmc_log(RMC_LOG_LEVEL_WARNING, __FUNCTION__, __FILE__, __LINE__, index, fmt, ##__VA_ARGS__); }
#define RMC_LOG_INDEX_ERROR(index, fmt, ...) { if (_rmc_log_level >= RMC_LOG_LEVEL_ERROR) rmc_log(RMC_LOG_LEVEL_ERROR, __FUNCTION__, __FILE__, __LINE__, index, fmt, ##__VA_ARGS__); }
#define RMC_LOG_INDEX_FATAL(index, fmt, ...) { if (_rmc_log_level >= RMC_LOG_LEVEL_FATAL) rmc_log(RMC_LOG_LEVEL_FATAL, __FUNCTION__, __FILE__, __LINE__, index, fmt, ##__VA_ARGS__); }
#ifdef __cplusplus
}
#endif
#endif // __RMC_LOG_H__