Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ Loggy Public

simple, lightweight header-only logging library made at 2 am with 'Monday'

FigmaFan/Loggy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Header-only C++17 Build License Platform PRs Welcome

Loggy

Loggy is a feature-rich, header-only, RAII-based logging library for modern C++ projects. It provides a thread-safe, customizable logging interface that outputs to the console and a log file. Designed for developer sanity and zero-dependency deployment, Loggy is activated only in debug builds by default.


🔧 Features

  • Header-only: Drop-in header, no external dependencies.
  • RAII & Singleton: Automatic init/deinit, but also supports manual instantiation.
  • Thread-Safe: Uses std::mutex to avoid race conditions.
  • Multiple Log Levels: DEBUG, INFO, WARN, ERR, FATAL
  • Customizable Timestamp Format: Choose your own time representation.
  • Console Output with Colors: Cross-platform color-coded logs.
  • Optional Console Allocation (Windows): Dynamically attach a console window in GUI apps.
  • Log File Output: Log file path is user-defined; supports log rotation at 5MB.
  • Custom Log Handlers: Hook in your own logging backend.
  • Thread ID in Output: Know who did the thing.
  • Auto-Flush Mode: Optional immediate flushing to log file/console.

💻 Requirements

  • C++17 or later

📦 Integration

1. Include the Header

#include "Loggy.h"

2. (Optional) Initialize Console

Logger::instance().initializeConsole("My Custom Console Title");
Logger::instance().enableConsoleOutput(true);

3. Configure (Optional)

Logger::instance().setLogPath("logs/app.log");
Logger::instance().setTimestampFormat("%d-%m-%Y %H:%M:%S");
Logger::instance().setLogLevel(LogLevel::DEBUG);
Logger::instance().enableAutoFlush(true);

4. Log Messages

LOG(LogLevel::INFO, "App initialized.");
LOG(LogLevel::DEBUG, "User input: ", inputValue);

5. Custom Log Handler (Optional)

Logger::instance().setCustomLogHandler([](const std::string& msg) {
    // Send to remote service, overlay, etc.
    std::cerr << "[Custom] " << msg << std::endl;
});

🧪 Example

#include "Loggy.h"
#include <stdexcept>

int main() {
#ifdef _DEBUG
    Logger::instance().initializeConsole("MyApp [DEBUG]");
    Logger::instance().enableConsoleOutput(true);
    Logger::instance().setLogPath("Main.log");

    LOG(LogLevel::INFO, "Application started");
    int value = 42;
    LOG(LogLevel::DEBUG, "Value: ", value);

    try {
        throw std::runtime_error("Something exploded!");
    } catch (const std::exception& ex) {
        LOG(LogLevel::ERR, "Caught exception: ", ex.what());
    }
#endif
    return 0;
}

🚨 Note on Release Builds

By default, logging is disabled in release builds. Define LOGGY_DISABLE_LOGGING to explicitly suppress logging, or remove it to force logging even outside debug mode.


🧼 Default Behavior Summary

  • Console logging is enabled manually.
  • File output truncates Main.log by default unless changed.
  • All logs are timestamped and thread-safe.
  • All macros are no-ops in release unless you override.

Enjoy your logs. Or at least understand them. That's progress.

About

simple, lightweight header-only logging library made at 2 am with 'Monday'

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages