Why Should Researchers use C++ Logging?
Most research and development occur in a haphazard manner and not investing time early on to adopt good development practices can increase the difficulty in extending research projects. Having a good C++ logging framework can help to reduce developing and debugging time significantly.
Why Not Use an Existing Log Framework?
Existing logging frameworks in C++ mostly target production systems (eg:- glog). Although glog provides many functionalities, since its over reliance on the google echo system, managing dependencies become extremely difficult. A researcher trying to develop a quick experiment will have to spend a significant amount of time skimming through multiple repositories and documentations to set up basic logging.
rlog: C++ Logging Designed for Research
rlog (Research Logging) was designed with research in mind. Therefore, the module is completely header based and it provides fast and easy integration with C++ projects. Drop the header files in the include directory and import the header files. Configuration is just as easy as that.
Configurable Log Outputs
rlog can be configured to use console output or file mode with just a few lines. Global configurations can be set through environment variables, meaning that log file names are available to all loggers. Also, since the logger is aware of the context, it can better provide contextual information such as the file from which the method is being called.
The example below explains how easy it is to set up logging in any context. Since configuration defaults to console mode, you can instantly view results.
#include <memory>
#include "include/log/logging.h"
using namespace Logging::LoggingInternals;
//
// The input of @Logger is,
// context: std::string :file from which the logger is called
//
std::unique_ptr<Logger> logger(new Logger(__FILE__));
logger->info("Hello!");
It’s also possible to configure log outputs to a file instead of directing them to the console.
#include <memory>
#include "include/log/logging.h"
using namespace Logging::LoggingInternals;
//
// The inputs are,
// context: std::string :file from which the logger is called
// filename: std::string :user specified log file name
// override: bool :whether to use the global log file or local log file
//
// Log severity and global log file name can be specified through env variables
// configured in @Env class. see @Env for configurations
//
std::unique_ptr<Logger> logger(new Logger(__FILE__, filename, 1));
logger->info("Aloha!");
How To Try it Out?
Head on to https://github.com/malithj/rlog and check the include directory. Furthermore, the readme also provides detailed instructions on decision decisions and configurations.
Contributing to rlog
If you are interested in contributing to a better C++ research logging framework, head on over to https://github.com/malithj/rlog and reach out to us.
Building Research Projects with “Research to Production” in mind