Search code examples
c++loggingglog

How to re-initialize GoogleLogging?


I write logging results of working on a data file with my program in a file, which also contains the name of the data file in the log file name, and for reproducibility the data file content is also logged. If the data file is correct, it works OK. If the data file is bad, then the further work is refused; it works fine. In my GUI environment, the user might have a second attempt, and second time provides a correct data file, under a different name. However, the second reading aborts the program, because in the block

  google::SetLogDestination(0, LogFileName.c_str() );
  google::InitGoogleLogging(FileName);

the initialization command occurs second time. How can I restart, terminate, reinitalize, close, or whatever called, the logging?


Solution

  • Normally, the logging is for the whole program. So, it might log hundreds of interactions with the users (some of which are refused/don't work/etc). You should move these commands to a place where they get invoked once at program startup. They should not be invoked on a per attempt/per user basis.

    See docs : http://rpg.ifi.uzh.ch/docs/glog.html

    There are no functions to restart, terminate, reinitalize, or close. You can flush to disk if you are having trouble with buffering, but it sounds like you just didn't understand how the library was intended to be used.