Another portable, lightweight and hackable logging utility for C++.
Usage is extremely easy:
- Add
Logger.h
andLogger.cpp
files to your project. - Include the
Logger.h
in your project with#include "Logger.h"
. - Initialize the Logger by running
LOG_INITIALIZE("logfilenamehere.txt")
. - Write to the log by using
LOG() << "Your message here"
. - Somewhere near the end of your program, run
LOG_FINALIZE()
.
See demo.cpp
for a demo with more usage examples:
// must call this before using Logger
// if not called before using LOG(), then
// LOG() simply outputs to stdout/stderr
LOG_INITIALIZE("log.txt");
// write freely to log
LOG() << "Hello World! ";
LOG() << "Write to log freely...." << std::endl << std::endl;
// write debug message to log
// note that it automatically adds endl to the end
LOG(LDEBUG) << "Debug message. "
"This should not be printed since default minimum logging level is at INFO.";
// set minimum logging level to DEBUG
// any message with logging level >= DEBUG will be printed now
LOG_SET_LEVEL(LDEBUG);
// write to debug message to log
LOG(LDEBUG) << "Debug message. "
"This should be printed since default minimum logging level is now at DEBUG.";
// write normal message to log
LOG(LINFO) << "Normal message.";
// write warning message to log
LOG(LWARNING) << "Warning message.";
// write error message to log
LOG(LERROR) << "Error message.";
// must call this before exiting program
// to release the log file handler
LOG_FINALIZE();
This logging utility is also very hackable, i.e. you can customize it to your liking. Read the comments in the Logger class.
Optionally use doxygen to generate the documentation for the Logger class.