Skip to content

Chanchal70021/ThreadSafeLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧡 ThreadSafeLogger

A modern, lightweight, thread-safe logging library in C++17 with:

  • βœ… Log level filtering (INFO, WARNING, ERROR)
  • βœ… Colored console output
  • βœ… Log file rotation based on file size
  • βœ… Customizable log file name
  • βœ… Graceful shutdown with background worker thread
  • βœ… Designed for multithreaded C++ applications

πŸ“Έ Demo Output

[2025-07-06 12:45:29] [INFO] Thread 1: Startup (white) [2025-07-06 12:45:29] [WARNING] Disk space low (yellow) [2025-07-06 12:45:29] [ERROR] Thread 1: Failure (red)


πŸš€ Features

Feature Description
🧡 Thread-safe logging Safe from race conditions using mutex + CV
πŸ”₯ Colored console output Uses ANSI escape codes for INFO, WARN, ERR
πŸͺ΅ Log level filtering Set a minimum level to control verbosity
πŸ’Ύ File logging All logs saved to a file (logs.txt)
πŸ“ Log file rotation Rotates logs automatically if size > 5MB
πŸ”§ Custom output file name Configure via logger.init()
βœ… Graceful shutdown Prevents logging after destruction

πŸ› οΈ Build & Run

βœ… Prerequisites

  • Windows with g++ (MinGW or MSYS2)
  • C++17 or higher

πŸ”§ Compile

g++ -std=c++17 -o logger_app main.cpp src/Logger.cpp

▢️ Run
.\logger_app.exe

πŸ“‚ Project Structure
ThreadSafeLogger/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Logger.cpp
β”‚   └── Logger.h
β”œβ”€β”€ main.cpp
β”œβ”€β”€ .gitignore
β”œβ”€β”€ README.md

πŸ“Œ Example Usage

Logger& logger = Logger::getInstance();
logger.init("app_logs.txt", LogLevel::INFO);

logger.log("App started", LogLevel::INFO);
logger.log("Low disk warning", LogLevel::WARNING);
logger.log("Fatal crash", LogLevel::ERROR);

logger.shutdown();

πŸ‘€ Author
Darelene
github.com/Chanchal70021a

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages