/
logging.h
71 lines (55 loc) · 2.55 KB
/
logging.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
66
67
68
69
/* tool to read power production data for SMA solar power convertors
Copyright flonatel GmbH & Co. KG, 2012
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef LOGGING_H
#define LOGGING_H
#include "pvlogger.h"
#include <stdio.h>
enum loglevel_enum {
ll_trace, ll_debug, ll_verbose, ll_info, ll_warning, ll_error,
ll_fatal
};
typedef enum loglevel_enum loglevel_t;
struct logging_struct
{
/* The file where to output logging. */
FILE * logfile;
/* Loglevel: Everything greater or equal this will be logged. */
loglevel_t loglevel;
};
typedef struct logging_struct logging_t;
typedef logging_t * logging_p;
logging_p logging_constructor(FILE * logfile);
void logging_set_loglevel(logging_p self, loglevel_t loglevel);
void logging_generic(logging_p self, loglevel_t level, char const * format, ...);
void logging_hex(logging_p self, loglevel_t level, char const * const desc,
void const * const data, unsigned long const len,
unsigned long const offset);
void logging_destructor(logging_p self);
/* The global log instance. */
extern logging_p logger;
/* Helper / Utilities */
#define log_trace(...) logging_generic(logger, ll_trace, __VA_ARGS__)
#define log_debug(...) logging_generic(logger, ll_debug, __VA_ARGS__)
#define log_verbose(...) logging_generic(logger, ll_verbose, __VA_ARGS__)
#define log_info(...) logging_generic(logger, ll_info, __VA_ARGS__)
#define log_warning(...) logging_generic(logger, ll_warning, __VA_ARGS__)
#define log_error(...) logging_generic(logger, ll_error, __VA_ARGS__)
#define log_fatal(...) logging_generic(logger, ll_fatal, __VA_ARGS__)
#define hlog_trace(dEsC, dAtA, lEn, oFfSeT) \
logging_hex(logger, ll_trace, dEsC, dAtA, lEn, oFfSeT)
#define hlog_debug(dEsC, dAtA, lEn, oFfSeT) \
logging_hex(logger, ll_debug, dEsC, dAtA, lEn, oFfSeT)
char const * const level2type(loglevel_t level);
/* This must be called before the first log. */
void log_init();
#endif