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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/**
* @file log.h
*
* @brief Simple log message
*
* This file is part of the bladeRF project:
* http://www.github.com/nuand/bladeRF
*
* Copyright (c) 2013 Nuand LLC.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef LOG_H__
#define LOG_H__
#include <stdio.h>
#include <inttypes.h>
#include "libbladeRF.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef SHORT_FILE_
# define THIS_FILE SHORT_FILE_
#else
#if 0
# warning "SHORT_FILE_ was not defined. Using __FILE__ instead."
#endif
# define THIS_FILE __FILE__
#endif
#define LOG_STRINGIFY__(x) #x
#define LOG_STRINGIFY_(x) LOG_STRINGIFY__(x)
#define LOG_EXPAND__(x) #x
#define LOG_EXPAND_(x) LOG_EXPAND__(x)
/**
* @defgroup LOG_MACROS Logging macros
* @{
*/
/** Logs a verbose message. Does not include function/line information */
#define log_verbose(...) \
LOG_WRITE(BLADERF_LOG_LEVEL_VERBOSE, "[VERBOSE", __VA_ARGS__)
/** Logs a debug message. Does not include function/line information */
#define log_debug(...) \
LOG_WRITE(BLADERF_LOG_LEVEL_DEBUG, "[DEBUG", __VA_ARGS__)
/** Logs an info message. Does not include function/line information*/
#define log_info(...) \
LOG_WRITE(BLADERF_LOG_LEVEL_INFO, "[INFO", __VA_ARGS__)
/** Logs a warning message. Includes function/line information */
#define log_warning(...) \
LOG_WRITE(BLADERF_LOG_LEVEL_WARNING, "[WARNING", __VA_ARGS__)
/** Logs an error message. Includes function/line information */
#define log_error(...) \
LOG_WRITE(BLADERF_LOG_LEVEL_ERROR, "[ERROR", __VA_ARGS__)
/** Logs a critical error message. Includes function/line information */
#define log_critical(...) \
LOG_WRITE(BLADERF_LOG_LEVEL_CRITICAL, "[CRITICAL", __VA_ARGS__)
/** @} */
#ifdef LOG_INCLUDE_FILE_INFO
# define LOG_WRITE(LEVEL, LEVEL_STRING, ...) \
do { log_write(LEVEL, LEVEL_STRING \
" @ " LOG_EXPAND_(THIS_FILE) \
":" LOG_STRINGIFY_(__LINE__) "] " \
__VA_ARGS__); \
} while (0)
#else
# define LOG_WRITE(LEVEL, LEVEL_STRING, ...) \
do { log_write(LEVEL, LEVEL_STRING "] " __VA_ARGS__); } while (0)
#endif
/**
* Writes a message to the logger with the specified log level. This function
* should only be invoked indirectly through one of the log_*
* convenience macros above to ensure consistent formatting of log messages.
*
* @param level The severity level of the message
* @param format The printf-style format string
* @param ... Optional values for format specifier substitution
*/
#ifdef LOGGING_ENABLED
void log_write(bladerf_log_level level, const char *format, ...);
#else
#define log_write(level, format, ...) do {} while(0)
#endif
/**
* Sets the filter level for displayed log messages. Messages that are at
* or above the specified log level will be written to the log output, while
* messages with a lower log level will be suppressed. This function returns
* the previous log level.
*
* @param level The new log level filter value
*/
#ifdef LOGGING_ENABLED
void log_set_verbosity(bladerf_log_level level);
#else
#define log_set_verbosity(level) do {} while (0)
#endif
/**
* @brief Gets the current filter level for displayed log messages.
*
* @return bladerf_log_level
*/
#ifdef LOGGING_ENABLED
bladerf_log_level log_get_verbosity();
#else
#define log_get_verbosity(...) BLADERF_LOG_LEVEL_SILENT
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
|