Plog - portable, simple and extensible C++ logging library
Pretty powerful logging library in about 1000 lines of code

- Introduction
- Integration
- Usage
- Advanced usage
- Architecture
- Miscellaneous notes
- Extending
- Samples
- License
- Version history
Introduction
Hello log!
Plog is a C++ logging library that is designed to be as simple, small and flexible as possible. It is created as an alternative to existing large libraries and provides some unique features as CSV log format and wide string support.
Here is a minimal hello log sample:
#include <plog/Log.h> // Step1: include the headers
#include "plog/Initializers/RollingFileInitializer.h"
int main()
{
plog::init(plog::debug, "Hello.txt"); // Step2: initialize the logger
// Step3: write log messages using a special macro
// There are several log macros, use the macro you liked the most
PLOGD << "Hello log!"; // short macro
PLOG_DEBUG << "Hello log!"; // long macro
PLOG(plog::debug) << "Hello log!"; // function-style macro
// Also you can use LOG_XXX macro but it may clash with other logging libraries
LOGD << "Hello log!"; // short macro
LOG_DEBUG << "Hello log!"; // long macro
LOG(plog::debug) << "Hello log!"; // function-style macro
return 0;
}
And its output:
2015-05-18 23:12:43.921 DEBUG [21428] [main@13] Hello log!
2015-05-18 23:12:43.968 DEBUG [21428] [main@14] Hello log!
2015-05-18 23:12:43.968 DEBUG [21428] [main@15] Hello log!
Features
- Very small (slightly more than 1000 LOC)
- Easy to use
- Headers only
- No 3rd-party dependencies
- Cross-platform: Windows, Linux, FreeBSD, macOS, Android, RTEMS, FreeRTOS (gcc, clang, msvc, mingw, mingw-w64, icc, c++builder)
- Thread and type safe
- Formatters: TXT, CSV, FuncMessage, MessageOnly
- Appenders: RollingFile, Console, ColorConsole, Android, EventLog, DebugOutput, DynamicAppender
- Automatic 'this' pointer capture (supported only on msvc)
- Lazy stream evaluation
- Unicode aware, files are stored in UTF-8, supports Utf8Everywhere
- Doesn't require C++11
- Extendable
- No
windows.hdependency - Can use UTC or local time
- Can print buffers in HEX or ASCII
- Can print
stdcontainers - Uses modern CMake
Integration
Plog is a header-only C++ library, making it extremely easy to integrate into any project. You do not need to build or link any binaries — just add the headers to your include path. Here are several recommended ways to add Plog to your project:
Copy the source
Simply copy the plog directory into your source tree. For example:
. <-- root of your solution
├── README.md
└── src
├── 3rd-party <-- directory for all 3rd-party dependencies
│ └── plog <-- plog is copied there
│ ├── include <-- add this to your include search path
│ │ └── plog
│ ├── LICENSE
│ └── README.md
├── proj1
└── proj2
Then, add src/3rd-party/plog/include to your project's include directories.
Git submodule
Add Plog as a git submodule to keep it up to date and track its version:
git submodule add https://github.com/SergiusTheBest/plog.git src/3rd-party/plog
git commit -m "Add plog as a submodule"
This approach allows you to easily update Plog and manage its version. Remember to add src/3rd-party/plog/include to your include path.
CMake integration
add_subdirectory
If you use CMake, you can add Plog directly to your build:
add_subdirectory(3rd-party/plog) # Adds plog to your CMake project
add_executable(myproj main.cpp)
target_link_libraries(myproj plog::plog) # Links and sets include path
FetchContent
Alternatively, use CMake's FetchContent to automatically download Plog at configure time:
include(FetchContent)
FetchContent_Declare(
plog
GIT_REPOSITORY https://github.com/SergiusTheBest/plog
GIT_TAG 1.1.10
GIT_SHALLOW true
)
FetchContent_MakeAvailable(plog) # Downloads and adds plog to your CMake project
add_executable(myproj main.cpp)
target_link_libraries(myproj plog::plog) # Links and sets include path
Package managers
Plog is also available via popular C++ package managers:
Refer to each package manager's documentation for the latest installation instructions and version details.
Usage
To start using plog you need to make 3 simple steps.
Step 1: Adding includes
At first your project needs to know about plog. For that you have to:
- Add
plog/includeto the project include paths - Add
#includeinto your cpp/h files (if you have precompiled headers it is a good place to add this include there)