Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
macros.hpp File Reference

Zero-overhead logging macros with file/line capture. More...

Detailed Description

Zero-overhead logging macros with file/line capture.

This header names no device. Without SBL_LOG_OUTPUT and SBL_LOG_TIMESTAMP the logger writes nothing and stamps 0. Firmware includes <sbl/log.hpp>, which picks the build's sink and timestamp and then includes this.

Usage:

// Output sink and timestamp provider
struct MyOutput { static void write(const char* s) { ... } };
struct MyTime { static uint32_t now() { return millis(); } };
// Configure before including
#define SBL_LOG_OUTPUT MyOutput
#define SBL_LOG_TIMESTAMP MyTime
#define SBL_LOG_LEVEL SBL_LOG_LEVEL_DEBUG
SBL_LOG_INFO("Hello %s", "world");
SBL_LOG_ERROR("Failed with code %d", err);
Zero-overhead logging macros with file/line capture.
#define SBL_LOG_ERROR(...)
Main logging macros with compile-time level filtering.
Definition macros.hpp:77
uint32_t millis()
Definition timer.hpp:65

SBL_LOG_LEVEL is an integer, so the preprocessor can filter on it:

  • SBL_LOG_LEVEL_OFF (0): disable all logging
  • SBL_LOG_LEVEL_ERROR (1): errors only
  • SBL_LOG_LEVEL_WARN (2): warnings and above
  • SBL_LOG_LEVEL_INFO (3): info and above (default)
  • SBL_LOG_LEVEL_DEBUG (4): debug and above
  • SBL_LOG_LEVEL_TRACE (5): everything

Definition in file macros.hpp.

Go to the source code of this file.

Namespaces

namespace  sbl
 Root namespace for all Sound Byte Libs code.
 
namespace  sbl::log
 Logging.
 

Macros

#define SBL_LOG_LEVEL   3
 
#define SBL_LOG_LEVEL_OFF   0
 
#define SBL_LOG_LEVEL_ERROR   1
 
#define SBL_LOG_LEVEL_WARN   2
 
#define SBL_LOG_LEVEL_INFO   3
 
#define SBL_LOG_LEVEL_DEBUG   4
 
#define SBL_LOG_LEVEL_TRACE   5
 
#define SBL_LOG_OUTPUT   sbl::log::NullOutput
 
#define SBL_LOG_TIMESTAMP   sbl::log::NullTimestamp
 
#define SBL_LOG_ERROR(...)   SblLogger_::log(sbl::log::Level::Error, __FILE__, __LINE__, __VA_ARGS__)
 Main logging macros with compile-time level filtering.
 
#define SBL_LOG_WARN(...)   SblLogger_::log(sbl::log::Level::Warn, __FILE__, __LINE__, __VA_ARGS__)
 
#define SBL_LOG_INFO(...)   SblLogger_::log(sbl::log::Level::Info, __FILE__, __LINE__, __VA_ARGS__)
 
#define SBL_LOG_DEBUG(...)   SblLogger_::log(sbl::log::Level::Debug, __FILE__, __LINE__, __VA_ARGS__)
 
#define SBL_LOG_TRACE(...)   SblLogger_::log(sbl::log::Level::Trace, __FILE__, __LINE__, __VA_ARGS__)
 
#define SBL_LOG_ERROR_IF(cond, ...)
 Conditional logging (runtime condition, compile-time level check)
 
#define SBL_LOG_WARN_IF(cond, ...)
 
#define SBL_LOG_INFO_IF(cond, ...)
 
#define SBL_LOG_SIMPLE(lvl, ...)   ((void)0)
 Log without file/line (smaller output)
 

Typedefs

using SblLogger_ = sbl::log::Logger< SBL_LOG_OUTPUT, SBL_LOG_TIMESTAMP, sbl::log::detail::level_from_int(SBL_LOG_LEVEL)>
 

Macro Definition Documentation

◆ SBL_LOG_LEVEL

#define SBL_LOG_LEVEL   3

Definition at line 42 of file macros.hpp.

◆ SBL_LOG_LEVEL_OFF

#define SBL_LOG_LEVEL_OFF   0

Definition at line 46 of file macros.hpp.

◆ SBL_LOG_LEVEL_ERROR

#define SBL_LOG_LEVEL_ERROR   1

Definition at line 47 of file macros.hpp.

◆ SBL_LOG_LEVEL_WARN

#define SBL_LOG_LEVEL_WARN   2

Definition at line 48 of file macros.hpp.

◆ SBL_LOG_LEVEL_INFO

#define SBL_LOG_LEVEL_INFO   3

Definition at line 49 of file macros.hpp.

◆ SBL_LOG_LEVEL_DEBUG

#define SBL_LOG_LEVEL_DEBUG   4

Definition at line 50 of file macros.hpp.

◆ SBL_LOG_LEVEL_TRACE

#define SBL_LOG_LEVEL_TRACE   5

Definition at line 51 of file macros.hpp.

◆ SBL_LOG_OUTPUT

#define SBL_LOG_OUTPUT   sbl::log::NullOutput

Definition at line 55 of file macros.hpp.

◆ SBL_LOG_TIMESTAMP

#define SBL_LOG_TIMESTAMP   sbl::log::NullTimestamp

Definition at line 59 of file macros.hpp.

◆ SBL_LOG_ERROR

#define SBL_LOG_ERROR (   ...)    SblLogger_::log(sbl::log::Level::Error, __FILE__, __LINE__, __VA_ARGS__)

Main logging macros with compile-time level filtering.

These expand to nothing when the level is disabled, achieving zero overhead for disabled log levels.

Definition at line 77 of file macros.hpp.

◆ SBL_LOG_WARN

#define SBL_LOG_WARN (   ...)    SblLogger_::log(sbl::log::Level::Warn, __FILE__, __LINE__, __VA_ARGS__)

Definition at line 83 of file macros.hpp.

◆ SBL_LOG_INFO

#define SBL_LOG_INFO (   ...)    SblLogger_::log(sbl::log::Level::Info, __FILE__, __LINE__, __VA_ARGS__)

Definition at line 89 of file macros.hpp.

◆ SBL_LOG_DEBUG

#define SBL_LOG_DEBUG (   ...)    SblLogger_::log(sbl::log::Level::Debug, __FILE__, __LINE__, __VA_ARGS__)

Definition at line 95 of file macros.hpp.

◆ SBL_LOG_TRACE

#define SBL_LOG_TRACE (   ...)    SblLogger_::log(sbl::log::Level::Trace, __FILE__, __LINE__, __VA_ARGS__)

Definition at line 101 of file macros.hpp.

◆ SBL_LOG_ERROR_IF

#define SBL_LOG_ERROR_IF (   cond,
  ... 
)
Value:
do { \
if (cond) { \
SBL_LOG_ERROR(__VA_ARGS__); \
} \
} while (0)

Conditional logging (runtime condition, compile-time level check)

Definition at line 109 of file macros.hpp.

◆ SBL_LOG_WARN_IF

#define SBL_LOG_WARN_IF (   cond,
  ... 
)
Value:
do { \
if (cond) { \
SBL_LOG_WARN(__VA_ARGS__); \
} \
} while (0)

Definition at line 116 of file macros.hpp.

◆ SBL_LOG_INFO_IF

#define SBL_LOG_INFO_IF (   cond,
  ... 
)
Value:
do { \
if (cond) { \
SBL_LOG_INFO(__VA_ARGS__); \
} \
} while (0)

Definition at line 123 of file macros.hpp.

◆ SBL_LOG_SIMPLE

#define SBL_LOG_SIMPLE (   lvl,
  ... 
)    ((void)0)

Log without file/line (smaller output)

Definition at line 136 of file macros.hpp.

Typedef Documentation

◆ SblLogger_

using SblLogger_ = sbl::log::Logger<SBL_LOG_OUTPUT, SBL_LOG_TIMESTAMP, sbl::log::detail::level_from_int(SBL_LOG_LEVEL)>

Definition at line 68 of file macros.hpp.