SatCat5
log.h File Reference

Detailed Description

Diagnostic logging to UART and/or Ethernet ports.

Log objects are used for diagnostic logging, with a few simple formatting options. They are intended for simple debugging while being much lighter-weight than printf() or sprintf(). Log messages can be conveyed to a console, a UART, or even a network interface. Each Log message carries a priority code to allow filtering.

The objects in this file are used to generate log messages. For receiving messages,

See also
log_cbor.h or the "test/log_viewer" tool.

Each Log object formats and emits a single human-readable message. The Log object is ephemeral, with chaining for readable syntax. Additional "write" calls append information to the message; the final message is sent when the Log object falls out of scope.

Each of the three examples below produces the same formatted message:

void example1(u8 errcode) {
Log(satcat5::log::WARNING, "Oh noooo").write(errcode);
}
void example2(u8 errcode) {
Log(satcat5::log::WARNING).write("Oh noooo").write(errcode);
}
void example3(u8 errcode) {
Log log(satcat5::log::WARNING);
log.write("Oh noooo");
log.write(errcode);
}
The Log class creates and formats one log message.
Definition: log.h:195
Log & write(const char *str)
Formatting methods for various data types.
Definition: log.cc:198

When the Log object falls out of scope, the message contents are written to every object that defines the log::EventHandler interface.

Definition in file log.h.

#include <satcat5/list.h>
#include <satcat5/types.h>
Include dependency graph for log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  satcat5::log::EventHandler
 Defines the interface for accepting Log messages. More...
 
class  satcat5::log::ToWriteable
 Copy Log messages to any Writeable interface. More...
 
class  satcat5::log::LogBuffer
 Internal buffer used by the Log class. More...
 
class  satcat5::log::Log
 The Log class creates and formats one log message. More...
 

Macros

#define SATCAT5_LOG_MAXLEN   255
 
#define SATCAT5_LOG_CONCISE   1
 
#define SATCAT5_WELCOME_EMOJI   "\xf0\x9f\x9b\xb0\xef\xb8\x8f\xf0\x9f\x90\xb1\xf0\x9f\x95\x94"
 

Functions

const char * satcat5::log::priority_label (s8 priority)
 Convert priority code to a human-readable UTF-8 string. More...
 
bool satcat5::log::pre_test_reset ()
 Hard-reset of global variables at the start of each unit test. More...
 

Variables

constexpr s8 LOG_DEBUG = satcat5::log::DEBUG
 
constexpr s8 LOG_INFO = satcat5::log::INFO
 
constexpr s8 LOG_WARNING = satcat5::log::WARNING
 
constexpr s8 LOG_ERROR = satcat5::log::ERROR
 
constexpr s8 LOG_CRITICAL = satcat5::log::CRITICAL
 
constexpr s8 satcat5::log::DEBUG = -20
 Define basic priority codes for log messages. More...
 
constexpr s8 satcat5::log::INFO = -10
 Define basic priority codes for log messages. More...
 
constexpr s8 satcat5::log::WARNING = 0
 Define basic priority codes for log messages. More...
 
constexpr s8 satcat5::log::ERROR = +10
 Define basic priority codes for log messages. More...
 
constexpr s8 satcat5::log::CRITICAL = +20
 Define basic priority codes for log messages. More...
 

Function Documentation

◆ pre_test_reset()

bool satcat5::log::pre_test_reset ( )

Hard-reset of global variables at the start of each unit test.

(Unit test only, not recommended for use in production software.) This may leak memory but prevents cross-test contamination. Returns true if globals were already in the expected state.

Definition at line 26 of file log.cc.

◆ priority_label()

const char * satcat5::log::priority_label ( s8  priority)

Convert priority code to a human-readable UTF-8 string.

By default, the priority code is a UTF-8 emoji. For example, WARNING gets the "caution" sign and CRITICAL gets a skull and crossbones. To replace this with a fixed-width plaintext code, set SATCAT5_LOG_EMOJI = 0.

Definition at line 116 of file log.cc.

Variable Documentation

◆ CRITICAL

constexpr s8 satcat5::log::CRITICAL = +20
constexpr

Define basic priority codes for log messages.

Larger numeric codes indicate greater message priority.

Definition at line 113 of file log.h.

◆ DEBUG

constexpr s8 satcat5::log::DEBUG = -20
constexpr

Define basic priority codes for log messages.

Larger numeric codes indicate greater message priority.

Definition at line 109 of file log.h.

◆ ERROR

constexpr s8 satcat5::log::ERROR = +10
constexpr

Define basic priority codes for log messages.

Larger numeric codes indicate greater message priority.

Definition at line 112 of file log.h.

◆ INFO

constexpr s8 satcat5::log::INFO = -10
constexpr

Define basic priority codes for log messages.

Larger numeric codes indicate greater message priority.

Definition at line 110 of file log.h.

◆ WARNING

constexpr s8 satcat5::log::WARNING = 0
constexpr

Define basic priority codes for log messages.

Larger numeric codes indicate greater message priority.

Definition at line 111 of file log.h.