Log Class Reference
|
Ratpac-two
|
#include <Log.hh>
Detailed Description
Logging of informational, warning, and error messages.
Log is a singleton which handles all the message reporting to the user, ensuring that messages are displayed and sent to a log file on disk as needed. You should not use cerr and cout!
Initialization
In the main() function, Log::Init() is called to open the log file and set the verbosity levels for display to the screen and for writing to disk. The levels are (in ascending verbosity):
- Log::WARN: Something has gone wrong.
- Log::INFO: Short information messages about what the program is currently doing.
- Log::DETAIL: Longer messages describing the settings being used. This should be sufficient to know what the program did and what information it used.
- Log::DEBUG: Very long messages relevant only for troubleshooting a software malfunction.
By default, WARN and INFO are shown to the screen, and WARN, INFO, and DETAIL are written to disk. Messages with a verbosity higher than the current setting are discarded.
Usage
To send messages to the logging system, there are 4 global ostream-like objects: warn, info, detail, debug. You can send strings, numbers, etc to them using the << operator:
info << "Adding FitCentroid to event loop.\n"; warn << "No seed found for fit, using default.\n"; detail << "Fit converged in " << iterations << " iterations.\n"; debug << "Hit tube list: \n";
You do not need if-statements to check the current log level, as this will be done for you. Note that while these objects behave much like the ostream cout and cerr, they are not subclasses of ostream. For example @c endl does not work on these objects. You should use @c "\n" or @c newline instead. (For the curious, these are STLplus textio objects.) @section Die When Really Bad Stuff Happens If your code encounters a major problem, it is best to bail out immediately and tell the user why. For this purpose, use the Die() method:
Log::Die("Could not open " + filename + " for input.");
This will print that message to the "warn" log stream and then
terminate the program. It is generally best to use Die() if you
want to make very certain the user sees your error. Warnings that do not
terminate the program are usually not noticed in the flood of
output that is sent to the screen.
@section Assert Good for sanity checks
Works like standard assert(), but lets you print something to the user
before dying if condition fails.
REVISION HISTORY
2017-06-08: M Smiley - Resolve memory leak induced by
keeping log in buffer during simulation
The documentation for this class was generated from the following file:
- /home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/core/include/RAT/Log.hh
Generated by