Logging library for C++ with the following features:
- You can create your own log handler class, thereby overriding the destination of the log file, etc.
- You can create your own log layout class, thereby changing the log message format
Fuck knows why I did it, but it seems to work.
- C++17 or higher
- CMake >= 3.16
Two logger creation with different location but with same format and terminal output.
#include <ut/logger/logger.h>
#include <ut/logger/defaultmessagelayout.h>
#include <ut/logger/filerotateloggerhandler.h>
#include <ut/logger/terminalloggerhandler.h>
using UT::Logger;
int main(int argc, char* argv[]) {
// Logger handler with file rotation
auto commonFRLoggerHandler = std::shared_ptr<UT::FileRotateLoggerHandler>(new UT::FileRotateLoggerHandler());
commonFRLoggerHandler->setLogPath("log/common.log");
commonFRLoggerHandler->setMaxLogBytes(100);
commonFRLoggerHandler->setMaxLogs(3);
auto customFRLoggerHandler = std::shared_ptr<UT::FileRotateLoggerHandler>(new UT::FileRotateLoggerHandler());
customFRLoggerHandler->setLogPath("log/custom.log");
customFRLoggerHandler->setMaxLogBytes(100);
customFRLoggerHandler->setMaxLogs(3);
// Terminal logger handler
auto terminalLoggerHandler = std::shared_ptr<UT::TerminalLoggerHandler>(new UT::TerminalLoggerHandler());
auto messageLayout = std::shared_ptr<UT::DefaultMessageLayout>(new UT::DefaultMessageLayout);
// Register logger
Logger::create("common", messageLayout, { commonFRLoggerHandler, terminalLoggerHandler });
Logger::create("custom", messageLayout, { customFRLoggerHandler, terminalLoggerHandler });
Logger::write("common", "INFO", "Hello, World!");
Logger::write("custom", "ERR", "My error message");
return 0;
}
The library is licensed under GNU Lesser General Public License 3.0:
Copyright © 2023 Dmitry Plastinin
UT Logger is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as pubblished by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
UT Logger is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser Public License for more details