Skip to content

odeviceblack/Logger-Library

Repository files navigation

Logger Library (C / C++ Android NDK)

Lightweight, modular logging library designed for Android NDK environments (armeabi-v7a / arm64-v8a), providing both C++ and C-compatible APIs with Android logcat integration.


📌 Overview

This library provides:

  • C++ object-oriented logging API
  • C ABI-compatible wrapper (stable interface)
  • Log levels with priority control (Info, Error, Debug, etc.)
  • Dynamic tag system
  • Callback hooks for external integration
  • va_list and variadic function support
  • Native Android logging via __android_log_write
  • Formatting via stb_sprintf (required)

🧱 Structure


logger.hpp / logger.cpp     → Core C++ implementation
logger_c.h / logger_c.cpp   → C ABI wrapper layer
stb_sprintf.h               → Required formatter backend


⚙️ Requirements

Mandatory dependency

  • stb_sprintf.h (formatting backend)

🚀 Usage (C++ API)

#include "logger.hpp"

Logger* log = Logger::GetLogger();

log->Info("Hello %s", "world");
log->Error("Error code: %d", 404);

log->SetTag("GameCore");
log->Print(LogP_Debug, "Debug value: %d", 123);

🚀 Usage (C API)

#include "logger_c.h"

LoggerC* log = logger_get_global();

logger_info(log, "Hello %s", "world");
logger_error(log, "Fatal error: %d", -1);

logger_set_tag(log, "Engine");
logger_print(log, LogP_Debug, "Value: %f", 3.14f);

🔗 Callback System

C++

logger->SetMessageCB(myCallback);
logger->SetTagCB(tagCallback);
logger->SetToggleCB(toggleCallback);

C

logger_set_message_cb(log, myCallback);
logger_set_tag_cb(log, tagCallback);
logger_set_toggle_cb(log, toggleCallback);

📱 Android Integration

The logger writes directly to Android logcat via:

#include <android/log.h>
__android_log_write(...)

🧠 Technical Characteristics

· Fixed stack buffer (2048 bytes)

· Formatting powered by stb_sprintf

· No STL dependency required

· Optional compile-time logging disable (NOLOGGING)

· C ABI stability via opaque pointer design

· Low overhead (no allocations in hot path)


⚠️ Notes

· stb_sprintf.h is required for compilation

· No fallback to standard vsnprintf is provided

· Designed for performance-sensitive runtime environments


📄 Licenses

STB_LICENSE

· File: stb_sprintf.h

· Author: Sean Barrett

· License: MIT / Public Domain

RUSJJ_LICENSE

· Files: logger.hpp, logger.cpp

· Author: Rusjj

. License: MIT

MY_LICENSE

· Files: logger_c.h, logger_c.cpp

· Author: DeviceBlack

. License: MIT


👤 Credits

· Sean Barrett — stb_sprintf.h

· Rusjj — original C++ logger implementation

· DeviceBlack — refactoring, fixes, C API wrapper

About

Lightweight, modular logging library designed for Android NDK environments (armeabi-v7a / arm64-v8a), providing both C++ and C-compatible APIs with Android logcat integration.

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
RUSJJ_LICENSE

Stars

Watchers

Forks

Packages

 
 
 

Contributors