jeudi 26 avril 2018

Implement a logging class to act as std::cout

I want to create a Logger class which will act as std::cout.

I want to use it this way:

#include "utils/logger.h"

int main(void)
{
    utils::logger << "Hello world";

    return 0;
}

Ideally this class will forward all logs to syslog. And syslog levels will be available through helpers like utils::error or utils::critical.

I have found some interesting resources:

I know that this question seems to be already posted but I cannot make the links between all the responses.

  1. I know the Logger class will have to inherit from std::ostream and / or std::streambuf.
  2. How to use it directly (ie not instantiate any object in the main) ? I was thinking to do it globally in a utils/logger.cc file...
  3. How to create the helpers ? I heard that macros are bad in C++

If someone have some useful links, hints and tips or awesome library to share it would be very nice.

Aucun commentaire:

Enregistrer un commentaire