'log4cpp - usage inside an object instance

In a new project in my company I would like to use the logging framework log4cpp.

The problem is that I don't want to write a single logging file for the entire program, nor do I want to write a single logging file over the entire runtime of the program, but for the runtime of a single object of a class.

The program itself runs endlessly. The lifetime of an object does not. So with each call of the constructor I want to create a new log file, preferably with the pattern {application}_{unix_timestamp_constructor_call}.log, while the object is in use, write to this file in certain files and stop writing to this file when the destructor is called.

I have unfortunately only worked with a logging framework in C so far and am now wondering how best to integrate and organize this in C++. Starting from the fact that every logfile should have the same pattern.

Does anyone have a good starting point for me?

My program can be roughly imagined as follows:

// ...
// params like mutex or ethernet device ...
// methods like user input

int main() {
// ...
  while(!shutdown_) {
    MyObject* object = new MyObject(ethernet_device);
    MyObject.RunMeasuringSession(); // can run several hours
    delete object;
    GetNewUserInput(); // e. g. shutdown_ = true or new ethernet_device
  }
// ...
// ...
}

Kind regards

Matthias



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source