Skip to content

Logging

Cisco edited this page Oct 4, 2025 · 1 revision

Dsicarded alternatives

We didn't consider using a specific library

  • Log4cpp has similar features to Java Log4J
  • Glog : no longer maintained
  • Abseil : c++17, not compatible yet looks interesting (custom sinks, structured logging, ..)
  • ng-log : c++14, not compatible

Although it could have proven relevant to use an existing tool, we deemed more interesting and flexible to write our own logger.

Custom logger

cf. Logger and LogManager

Features

  • level-controlled
    • debug for development
    • info, warning and error for production
  • file logging
  • specialized loggers to store in different files
  • singletons
  • macros to shorten call
  • setting a global minimal level

Log points

In the program flow, we want to log

  • Fatal errors -> ERROR
  • Raw messages being sent and received -> INFO
  • Result of various checks
    • syntaxically incorrect command

Classes like ReplyHandler were good points to centralize logging and prevent superfluous logging, which has a performance impact

Log format

  • time
  • log level (colorized)
  • message

Overloads to pass objects Catching the file and function

Sources

Integrate logging into your c++ project 12 logging best practices

Clone this wiki locally