-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint.h
More file actions
130 lines (115 loc) · 3.83 KB
/
Copy pathprint.h
File metadata and controls
130 lines (115 loc) · 3.83 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* @file print.h
* @brief Logging support functions
* @note Copyright (C) 2011 Richard Cochran <richardcochran@gmail.com>
*
* 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 2 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef HAVE_PRINT_H
#define HAVE_PRINT_H
#include <stdio.h>
#include <stdint.h>
#include <string.h>
/**
* Logging levels.
*/
#define LOG_EMERG 0
#define LOG_ALERT 1
#define LOG_CRIT 2
#define LOG_ERR 3
#define LOG_WARNING 4
#define LOG_NOTICE 5
#define LOG_INFO 6
#define LOG_DEBUG 7
#define LOG_DEBUG1 8
#define LOG_DEBUG2 9
#define PRINT_LEVEL_MIN LOG_EMERG
#define PRINT_LEVEL_MAX LOG_DEBUG2
void print_set_progname(const char *name);
void print_set_tag(const char *tag);
void print_set_syslog(int value);
void print_set_level(int level);
void print_set_verbose(int value);
extern void print(int level, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
/*
* Better check print log level before execution of print itself.
* Otherwise all arguments are evaluated and slow down the system.
* e.g. in 'unicast_service.c' unicast_service_clients()
* pid2str() is the killer
* pr_debug("%s wants 0x%x", pid2str(&client->portIdentity),
* client->message_types);
*/
extern int print_level;
static inline int print_get_level(void)
{
return print_level;
}
#define PRINT_CL(l, x...) /* PRINT Check Level */ \
do { \
if (print_get_level() >= l) \
print(l, x); \
} while (0)
#define pr_emerg(x...) PRINT_CL(LOG_EMERG, x)
#define pr_alert(x...) PRINT_CL(LOG_ALERT, x)
#define pr_crit(x...) PRINT_CL(LOG_CRIT, x)
#define pr_err(x...) PRINT_CL(LOG_ERR, x)
#define pr_warning(x...) PRINT_CL(LOG_WARNING, x)
#define pr_notice(x...) PRINT_CL(LOG_NOTICE, x)
#define pr_info(x...) PRINT_CL(LOG_INFO, x)
#define pr_debug(x...) PRINT_CL(LOG_DEBUG, x)
#define pl_info(lvl, x...) \
do { \
if (lvl >= print_level) \
print(LOG_INFO, "ptp4l " x); \
} while (0)
#define pl_warning(lvl, x...) \
do { \
if (lvl >= print_level) \
print(LOG_WARNING, "ptp4l " x); \
} while (0)
#define pl_err(lvl, x...) \
do { \
if (lvl >= print_level) \
print(LOG_ERR, "ptp4l " x); \
} while (0)
/**
* Tuning audit log - dedicated channel for recording tuning parameter changes.
* These are logged at LOG_NOTICE level with a consistent format for
* parsing by monitoring tools.
*
* Format: TUNE: <parameter_name> <old_value> -> <new_value>
*
* Examples:
* TUNE: numOffsetValues 10 -> 5
* TUNE: kp 0.700000 -> 0.500000
* TUNE: port[eth0] filter_length 8 -> 12
*/
#define pr_tune(param, old_val, new_val, fmt_spec) \
do { \
print(LOG_NOTICE, \
"TUNE: %s " fmt_spec " -> " fmt_spec, \
param, \
(old_val), \
(new_val)); \
} while (0)
/* For string-based parameters */
#define pr_tune_str(param, old_val, new_val) \
do { \
print(LOG_NOTICE, "ptp4l", \
"TUNE: " param " %s -> %s", \
(old_val), (new_val)); \
} while (0)
#endif