Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » C++ » C++ Projects » Logger in C++

C++ Project on Logger - How to design a logger framework?

This C++ project has three parts, first part has an application which just send logs to a logfile, second part is log framework itself which provides a method to log any message to logfile, and the last third part is an application which can be used to find the logs with different options. This project was compiled on Linux g++ compiler with the use of Makfile. Users download the project and modify according to their need. Please not this project is for educational purpose and can be improved in many ways. Please watch the video for more details.


Features of Application (Dummy App)

The purpose of this dummy application is just produce the logs and send them to logfile using logger framework's methods. In this application we have a single source file which is main.cpp, which has just a main() function which contains a for loop to log a block of messages to logfile vis logger method writeLog().

  • Genrates dummy log messages in a loop which run 100 times
  • Logs messages with log level ERROR
  • Logs messages with log level DEBUG
  • Seep for 2 seconds after logging a block of messages

Folder structure

We have a fodler 'Project' which contains all files and folders. For extract_logs application we have a separate folder 'logextract', and for logger framework the folder name is 'LogFramework'. Please note we have two make files, 'make_application' is used to build applicatino.out binary, and 'make_extract_logs' is use used to build 'extract_logs.out binary'.

Folder structure of C++ project on logger framework

Steps to build the dummy applcation


make -f make_application
how to build dummy app to generate logs

Features of Log framework

  • Framework based on singel design pattern
  • getLogHandler() function to get handle by passing log level
  • A single method to log messages to log file
  • Logger without any dynamic memory allocation

Features of LogExtract application

  • Find logs by debug level
  • Find logs by pid
  • Find logs by date
  • Find logs by date interval

Steps to build the LogExtract applcation


make -f make_extract_logs
how to build extract_log application to find logs

How to run application to generate dummy logs


./application.out
how to run dummy app to generate logs

Running extract_log application without passing arguments


./extract_logs.out
how to run dummy app to generate logs

Filter the logs by beginday and endday


./extract_logs.out -beginday 20220:08:10 -endday 2025:08:20
running extract_logs application by passing startday and endday

Filter the logs by Debug Level


./extract_logs.out -beginday 20220:08:10 -endday 2025:08:20
running extract_logs application by passing startday and endday

Source Code

Video on the Project