A lightweight terminal logger for embedded projects based on SEGGER RTT. The module provides simple logging macros for ERROR, WARN, INFO, and DEBUG, ANSI color output, and an optional timestamp supplied by the host application.
This repository contains:
Terminal/terminal.candTerminal/terminal.h- the application logging layer.SeggerRTT/SEGGER_RTT.c,SEGGER_RTT_printf.c,SEGGER_RTT.h- SEGGER RTT sources.Config/SEGGER_RTT_Conf.h- default RTT configuration.
- C/C++ compiler for the embedded target,
- SEGGER J-Link or another host tool that supports RTT,
- include paths enabled for
Terminal,SeggerRTT, andConfig.
The logger should not depend directly on any RTOS. The timestamp is provided through a callback passed during initialization. A FreeRTOS project can pass a function based on xTaskGetTickCount(), while a bare-metal project can pass a SysTick/HAL-based function.
Initialize the terminal once during application startup, before the first log call.
Use the logging macros from terminal.h:
#include "terminal.h"
TERMINAL_LOG_ERROR("Tag message", "Fmt message: %d", error_code);The time callback may be NULL; in that case the logger prints timestamp 0.
Defaults:
- builds with
NDEBUGsetLOG_LEVEL_NONE, - other builds set
LOG_LEVEL_DEBUG.
The repository should allow the parent project to override the log level. The default definition in terminal.h should be wrapped with #ifndef LOG_LEVEL:
#ifndef LOG_LEVEL
#ifdef NDEBUG
#define LOG_LEVEL LOG_LEVEL_NONE
#else
#define LOG_LEVEL LOG_LEVEL_DEBUG
#endif
#endifThen the level can be selected through compiler definitions:
target_compile_definitions(${PROJECT_NAME} PRIVATE LOG_LEVEL=LOG_LEVEL_INFO)Available levels:
#define LOG_LEVEL_NONE 0
#define LOG_LEVEL_ERROR 1
#define LOG_LEVEL_WARN 2
#define LOG_LEVEL_INFO 3
#define LOG_LEVEL_DEBUG 4