tpc_logger

Logging system for the TPC software.

The TPC Logger class provides a singleton for logging information within C++ code or in the python API. The class Logger contains an instance of spdlog::logger for both printing to the console (s_ConsoleLogger) and for logging to a file (s_FileLogger). There are four basic log levels:

Logger::info("Generic information...");
Logger::trace("Stack trace level of information...");
Logger::warn("Warning! Don't do what you're thinking of doing!");
Logger::error("ERROR! Program crashing!");

Installation

To install, simply download the repository and run the setup.py script:

python setup.py install

This will run cmake to compile the project and generate the python library. The default settings set the logger to only output to the log file, the console logger is turned off by default (CONSOLE_LOGGER=OFF). Unit tests are enabled by default, but can be turned off by swtiching BUILD_TESTS=OFF. To run the tests, either go to the “tests” directory and issue:

pytest .

or, go to the build directory (probably “build/temp.[environment]”) and issue,

ctest

C++ usage

To use within a C++ class, first include the header Logger.hh. You can then invoke the log level commands:

#include "Logger.hh"

// some condition causes an error
if (condition == true)
{
    Logger::error("ERROR! generic error message ...");
}

// store/print some generic info
Logger::info("Calling function foo()");
foo();

Python

Basic usage in python is to first import tpc_logger which returns an instance of the singleton class. Then, issue one of the four log level commands:

import tpc_logger as logger
import sys

# some condition causes an error
if (condition == True):
    logger.error("ERROR! generic error message ...")
    sys.exit()

# store/print some generic info
logger.info("Calling funcion bar()")
bar()

GitHub

View Github