-
Notifications
You must be signed in to change notification settings - Fork 3
Examples CApi
Eduard Mishkurov edited this page Jun 3, 2026
·
3 revisions
This example shows how to use logme from a pure C translation unit.
- Including the common public entry point
Logme/Logme.hfrom C code - Creating a channel from C
- Attaching console and file backends from C
- Using printf-style C logging macros
- Logging to the default channel, a named channel, and a subsystem
- Using a C override object for per-call output changes and rate/repetition limits
- Flushing and shutting down logme from C
- The C API intentionally supports a smaller feature set than the C++ API.
- C logging macros are printf-style only. The C++ stream-style syntax is not available in C.
- Channel and subsystem routing use explicit C macro variants such as
LogmeI_Ch,LogmeE_Sid, andLogmeW_ChSid. -
LogmeCOverrideis mutable because repetition and frequency limits keep state between calls. Keep it alive for as long as the call site needs that state.
2026-06-03 16:33:08:211 D main(): C debug message: 1
2026-06-03 16:33:08:211 main(): C info message: text
2026-06-03 16:33:08:211 W main(): C warning in a named channel
2026-06-03 16:33:08:211 E Error: main(): C error with subsystem
2026-06-03 16:33:08:211 C Critical: main(): C critical message
2026-06-03 16:33:08:211 main(): conditional C message
2026-06-03 16:33:08:211 this C override message is printed once
Repository folder: examples/CApi
#include <Logme/LogmeC.h>
int main(void)
{
LogmeSetChannelLevel(NULL, LOGME_C_ENUM_VALUE(LEVEL_DEBUG));
LogmeCreateChannel("c-channel", LOGME_C_ENUM_VALUE(LEVEL_DEBUG));
LogmeRemoveChannelBackends("c-channel");
LogmeAddConsoleBackend("c-channel", 0);
LogmeAddFileBackend("c-channel", "c-api-example.log", 1, 1024 * 1024, 0, 3);
LogmeD("C debug message: %d", 1);
LogmeI("C info message: %s", "text");
LogmeW_Ch("c-channel", "C warning in a named channel");
LogmeE_Sid("CAPI", "C error with subsystem");
LogmeC_ChSid("c-channel", "CAPI", "C critical message");
LogmeI_If(1, "conditional C message");
static LogmeCOverride onceOverride = LOGME_C_OVERRIDE_INIT;
onceOverride.MaxRepetitions = 1;
onceOverride.Remove.Value = 0;
onceOverride.Remove.Method = 1;
LogmeI_Ovr(&onceOverride, "this C override message is printed once");
LogmeI_Ovr(&onceOverride, "this C override message is suppressed");
LogmeFlushChannel("c-channel");
LogmeShutdown();
return 0;
}Previous: CallbackBackend | Next: Channels
logme — flexible runtime logging system
Home · Getting Started · Architecture · Output · Backends · Configuration
GitHub: https://github.com/efmsoft/logme
- Home
- Getting Started
- Why logme?
- Core Concepts
- Logging Macros
- Fatal Handling
- Crash Logging
- glog Compatibility
- C API
- Choosing Logging Macros
- Function tracing
- Trace Points
- Override Scopes
- Advanced Features
- Collapse Logging
- Feature Map
- Overview
- Console Backend
- Debugger Backend
- File Backend
- File Rotation & Retention
- Buffer Backend
- Ring Buffer Backend
- SharedFile Backend
- Callback Backend
- Windows Event Log Backend
- Custom Backends
- Runtime Control
- Configuration
- Configuration JSON
- Control Server
- Environment Control
- Control Policies
- Trace Points
- Message Filtering