Timber is a lightweight, portable logging library for embedded systems written in pure C, with an optional C++ wrapper for Arduino compatibility.
It is inspired by the excellent Timber library for Android, but is not affiliated with or directly related to it.
Timber is designed to work across multiple platforms.
- Pure C core (portable across embedded platforms)
- Arduino-friendly C++ wrapper
- Custom output function support
- Optional timestamps
- Optional ANSI colors
- No dynamic memory allocation
- Minimal overhead
Install via Arduino Library Manager or clone into your libraries folder:
Documents/Arduino/libraries/Timber
Include in your sketch:
#include <timber.h>Add the library and include:
#include "timber.h"Then configure output and time functions.
Default output uses Serial.
#include <timber.h>
void setup()
{
Serial.begin(115200);
Timber.i("System started");
Timber.w("Low memory");
Timber.e("Failed to connect");
}
void loop()
{
}#include "timber.h"
uint32_t my_time()
{
return millis();
}
void my_output(
timber_level_t level,
uint32_t timestamp,
const char *msg)
{
printf("%s", msg);
}
int main()
{
timber_set_output(my_output);
timber_set_time_func(my_time);
timber_i("Hello world");
return 0;
}Routes log output to any interface (UART, USB, BLE, file, etc.)
Arduino example:
void myOutput(
timber_level_t level,
uint32_t timestamp,
const char *msg)
{
Serial.write(msg);
}
Timber.setOutput(myOutput);uint32_t myTime()
{
return millis();
}
Timber.setTimeFunc(myTime);Timber.enableColors(true);
Timber.enableColors(false);Timber.enableTimestamp(true);
Timber.enableTimestamp(false);Timber.enableNewline(true);
Timber.enableNewline(false);TIMBER_LEVEL_DEBUG
TIMBER_LEVEL_INFO
TIMBER_LEVEL_WARNING
TIMBER_LEVEL_ERROR
TIMBER_LEVEL_VERBOSE
TIMBER_LEVEL_WTF
TIMBER_LEVEL_NONE
Timber.d("Debug message");
Timber.i("Info message");
Timber.w("Warning message");
Timber.e("Error message");
Timber.v("Verbose message");Formatted logging:
Timber.i("Value: %d", value);timber_d("Debug message");
timber_i("Info message");
timber_w("Warning message");
timber_e("Error message");
timber_v("Verbose message");
timber_wtf("Critical error");Formatted logging:
timber_i("Temperature: %d C", temp);typedef void (*timber_output_func_t)(
timber_level_t level,
uint32_t timestamp,
const char *message
);Change buffer size using defines
#define TIMBER_BUFFER_SIZE 1024- Platform-independent
- Zero heap usage
- Minimal footprint
- Maximum flexibility
- Arduino compatibility
- Embedded-first architecture
