AVRly - AVR Development Resources
log_system.h
Go to the documentation of this file.
1
/******************************************************************************
2
@copyright Copyright © 2022 by Jason Duffy.
3
4
Permission is hereby granted, free of charge, to any person obtaining a copy
5
of this software and associated documentation files (the "Software"), to deal
6
in the Software without restriction, including without limitation the rights
7
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
copies of the Software, and to permit persons to whom the Software is
9
furnished to do so, subject to the following conditions:
10
11
The above copyright notice and this permission notice shall be included in all
12
copies or substantial portions of the Software.
13
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
SOFTWARE.
21
******************************************************************************/
22
23
/**
24
* @file log_system.h
25
* @ingroup log_system
26
* @author Jason Duffy
27
* @date 1st March 2022
28
* @brief Driver file providing logging functionality over USART, to print
29
* debug messages and values to a teminal program on your PC.
30
* @bug No known bugs.
31
*/
32
33
#ifndef LOG_SYSTEM_DOT_H
34
#define LOG_SYSTEM_DOT_H
35
36
/**
37
* Enumerated constants for the type of message to be logged.
38
*/
39
typedef
enum
40
{
41
NONE,
42
ERROR,
43
WARNING,
44
INFO,
45
DEBUG,
46
VERBOSE_DEBUG
47
}
log_type_t
;
48
49
50
/**
51
* Config object, to be instantiated in each file the log system is to be used,
52
* then pass it's address into the functions with names beginning with "log".
53
* p_system_tag is a string, and is used for the logsystem to report which file
54
* or subsystem the message came from, e.g. "Main".
55
* file_log_level is the maximum level you'd like logging output for a
56
* particular file.
57
*/
58
typedef
struct
59
{
60
const
char
*p_system_tag;
61
log_type_t
file_log_level;
62
}
log_system_config_t
;
63
64
65
/**
66
* Initialisation routine - call this function once at startup before using
67
* other functions. Log system will then be turned on by default - call
68
* log_global_off() if you do not wish it to be.
69
*/
70
void
init_log_system
(
void
);
71
72
73
/**
74
* Sends only the system tag, log level and message string.
75
* @param p_config is a pointer to the log_system config object. Instantiate
76
* the config object at the head of each file where logging is required and
77
* pass it's address into this function.
78
* @param level is the level status of the log message - see log_type_t for
79
* available options.
80
* @param msg is the message to be logged, enclose it in "" quotation marks.
81
*/
82
void
log_message
(
log_system_config_t
*p_config,
83
log_type_t
level,
84
const
char
*msg);
85
86
87
/**
88
* Sends a string, followed by an 8 bit value in decimal format.
89
* @param p_config is a pointer to the log_system config object. Instantiate
90
* the config object at the head of each file where logging is required and
91
* pass it's address into this function.
92
* @param level is the level status of the log message - see log_type_t for
93
* available options.
94
* @param msg is the message to be logged, enclose it in "" quotation marks.
95
* @param val is the numerical value to be logged - Acceptable values 0 - 255.
96
*/
97
void
log_message_with_dec_val
(
log_system_config_t
*p_config,
98
log_type_t
level,
99
const
char
*msg,
100
uint8_t val);
101
102
103
/**
104
* Sends a string, followed by an 8 bit value in binary format.
105
* @param p_config is a pointer to the log_system config object. Instantiate
106
* the config object at the head of each file where logging is required and
107
* pass it's address into this function.
108
* @param level is the level status of the log message - see log_type_t for
109
* available options.
110
* @param msg is the message to be logged, enclose it in "" quotation marks.
111
* @param val is the numerical value to be logged - Acceptable values 0 - 255.
112
*/
113
void
log_message_with_bin_val
(
log_system_config_t
*p_config,
114
log_type_t
level,
115
const
char
*msg,
116
uint8_t val);
117
118
119
/**
120
* Sends a string, followed by an 8 bit value in hexadecimal format.
121
* @param p_config is a pointer to the log_system config object. Instantiate
122
* the config object at the head of each file where logging is required and
123
* pass it's address into this function.
124
* @param level is the level status of the log message - see log_type_t for
125
* available options.
126
* @param msg is the message to be logged, enclose it in "" quotation marks.
127
* @param val is the numerical value to be logged - Acceptable values 0 - 255.
128
*/
129
void
log_message_with_hex_val
(
log_system_config_t
*p_config,
130
log_type_t
level,
131
const
char
*msg,
132
uint8_t val);
133
134
135
/**
136
* Sets maximum output level of logging required, to be used at file scope.
137
* @param p_config is a pointer to the log_system config object. Instantiate
138
* the config object at the head of each file where logging is required and
139
* pass it's address into this function.
140
* @param level is the maximum level required - see log_type_t for available
141
* options.
142
*/
143
void
log_set_file_max_output_level
(
log_system_config_t
*p_config,
144
log_type_t
level);
145
146
147
/**
148
* Sets maximum output level of logging required, has global effect.
149
* @param level is the maximum level required - see log_type_t for available
150
* options.
151
*/
152
void
log_set_global_max_output_level
(
log_type_t
level);
153
154
155
/**
156
* Turns logging system on globally.
157
*/
158
void
log_global_on
(
void
);
159
160
161
/**
162
* Turns logging system off globally.
163
*/
164
void
log_global_off
(
void
);
165
166
167
#endif
// LOG_SYSTEM_DOT_H
168
169
170
/*** end of file ***/
log_set_file_max_output_level
void log_set_file_max_output_level(log_system_config_t *p_config, log_type_t level)
Sets maximum output level of logging required, to be used at file scope.
Definition:
log_system.c:217
log_message_with_dec_val
void log_message_with_dec_val(log_system_config_t *p_config, log_type_t level, const char *msg, uint8_t val)
Sends a string, followed by an 8 bit value in decimal format.
Definition:
log_system.c:116
log_set_global_max_output_level
void log_set_global_max_output_level(log_type_t level)
Sets maximum output level of logging required, has global effect.
Definition:
log_system.c:229
log_global_on
void log_global_on(void)
Turns logging system on globally.
Definition:
log_system.c:133
init_log_system
void init_log_system(void)
Initialisation routine - call this function once at startup before using other functions.
Definition:
log_system.c:46
log_message_with_hex_val
void log_message_with_hex_val(log_system_config_t *p_config, log_type_t level, const char *msg, uint8_t val)
Sends a string, followed by an 8 bit value in hexadecimal format.
Definition:
log_system.c:193
log_global_off
void log_global_off(void)
Turns logging system off globally.
Definition:
log_system.c:139
log_message
void log_message(log_system_config_t *p_config, log_type_t level, const char *msg)
Sends only the system tag, log level and message string.
Definition:
log_system.c:93
log_type_t
log_type_t
Enumerated constants for the type of message to be logged.
Definition:
log_system.h:40
log_message_with_bin_val
void log_message_with_bin_val(log_system_config_t *p_config, log_type_t level, const char *msg, uint8_t val)
Sends a string, followed by an 8 bit value in binary format.
Definition:
log_system.c:167
log_system_config_t
Config object, to be instantiated in each file the log system is to be used, then pass it's address i...
Definition:
log_system.h:59
content
modules
debug-tools
log-system
example
log_system.h
Generated by
1.9.4