File: Logger.h

package info (click to toggle)
soapysdr 0.8.1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 948 kB
  • sloc: cpp: 5,378; ansic: 471; python: 311; sh: 21; makefile: 18
file content (97 lines) | stat: -rw-r--r-- 3,286 bytes parent folder | download | duplicates (4)
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
///
/// \file SoapySDR/Logger.h
///
/// Logger API for SoapySDR devices.
/// Implementations should use the logger rather than stdio.
/// The default log handler prints to stderr.
///
/// \copyright
/// Copyright (c) 2014-2015 Josh Blum
/// SPDX-License-Identifier: BSL-1.0
///

#pragma once
#include <SoapySDR/Config.h>
#include <stdarg.h>

/*!
 * The available priority levels for log messages.
 *
 * The default log level threshold is SOAPY_SDR_INFO.
 * Log messages with lower priorities are dropped.
 *
 * The default threshold can be set via the
 * SOAPY_SDR_LOG_LEVEL environment variable.
 * Set SOAPY_SDR_LOG_LEVEL to the string value:
 * "WARNING", "ERROR", "DEBUG", etc...
 * or set it to the equivalent integer value.
 */
typedef enum
{
    SOAPY_SDR_FATAL    = 1, //!< A fatal error. The application will most likely terminate. This is the highest priority.
    SOAPY_SDR_CRITICAL = 2, //!< A critical error. The application might not be able to continue running successfully.
    SOAPY_SDR_ERROR    = 3, //!< An error. An operation did not complete successfully, but the application as a whole is not affected.
    SOAPY_SDR_WARNING  = 4, //!< A warning. An operation completed with an unexpected result.
    SOAPY_SDR_NOTICE   = 5, //!< A notice, which is an information with just a higher priority.
    SOAPY_SDR_INFO     = 6, //!< An informational message, usually denoting the successful completion of an operation.
    SOAPY_SDR_DEBUG    = 7, //!< A debugging message.
    SOAPY_SDR_TRACE    = 8, //!< A tracing message. This is the lowest priority.
    SOAPY_SDR_SSI      = 9, //!< Streaming status indicators such as "U" (underflow) and "O" (overflow).
} SoapySDRLogLevel;

//! Compile-time detection macro for SSI feature
#define SOAPY_SDR_SSI SOAPY_SDR_SSI

#ifdef __cplusplus
extern "C" {
#endif

/*!
 * Send a message to the registered logger.
 * \param logLevel a possible logging level
 * \param message a logger message string
 */
SOAPY_SDR_API void SoapySDR_log(const SoapySDRLogLevel logLevel, const char *message);

/*!
 * Send a message to the registered logger.
 * \param logLevel a possible logging level
 * \param format a printf style format string
 * \param argList an argument list for the formatter
 */
SOAPY_SDR_API void SoapySDR_vlogf(const SoapySDRLogLevel logLevel, const char *format, va_list argList);

/*!
 * Send a message to the registered logger.
 * \param logLevel a possible logging level
 * \param format a printf style format string
 */
static inline void SoapySDR_logf(const SoapySDRLogLevel logLevel, const char *format, ...)
{
    va_list argList;
    va_start(argList, format);
    SoapySDR_vlogf(logLevel, format, argList);
    va_end(argList);
}

/*!
 * Typedef for the registered log handler function.
 */
typedef void (*SoapySDRLogHandler)(const SoapySDRLogLevel logLevel, const char *message);

/*!
 * Register a new system log handler.
 * Platforms should call this to replace the default stdio handler.
 * Passing `NULL` restores the default.
 */
SOAPY_SDR_API void SoapySDR_registerLogHandler(const SoapySDRLogHandler handler);

/*!
 * Set the log level threshold.
 * Log messages with lower priority are dropped.
 */
SOAPY_SDR_API void SoapySDR_setLogLevel(const SoapySDRLogLevel logLevel);

#ifdef __cplusplus
}
#endif