|
OpenZGY/C++ API and Internals (ALPHA)
Access seismic data stored in ZGY format.
|
#include <logger.h>
Public Types | |
| typedef std::function< bool(int, const std::string &)> | LoggerFn |
Static Public Member Functions | |
| static int | getVerboseFromEnv (const char *envname) |
| static bool | logger (const LoggerFn &logger, int priority, const std::string &str=std::string()) |
| static bool | logger (const LoggerFn &logger, int priority, const std::ios &ss) |
| static LoggerFn | emptyCallback () |
| static LoggerFn | standardCallback (int level, const std::string &prefix, const std::string &suffix) |
Logging framework.
The actual logger is a simple functor that will be invoked whenever the code wants to output a debug message. The functor may or may not output the message somewhere. The return value indicates whether the message was or should have been output. If called with an empty message don't output anything but still return the bool should_be_output.
The logger can be stored in a global variable or be passed around as function arguments or class members.
The callback is guaranteed to not be empty. Attempts to set an empty callback should cause a dummy callback with no output to be set.
Simple use:
Advanced use if message may be expensive to compute:
The functor is allowed to lie. Specifically, when the second form is used there will be code that is never executed unless the user turns on a huge amount of logging. It is useful to run some of the tests with a logger that discards all the output but claims it was or would be shown. Then run the same test with no logging, and verify there was no observed difference. This strategy also does wonders for the code coverage.
LoggerBase contains static convenience functions only. It is possible to avoid this class and use the logger functor directly if it is desirable to limit dependencies.
Need to be exported because it is used by the Python wrapper.
|
static |
To be used instead of an empty functor, so the code knows it is always safe to call the logger. All output is discarded.
|
static |
Invoke the specified logger function with a stringstream argument.
Example usage:
if (logger(priority)) logger(priority, std::stringstream() << "Hello" << ", world.");
|
static |
Invoke the specified logger function with a string argument. This isn't much different from invoking the callback directly. But it makes debugging slightly simpler to have an easy place to set a breakpoint. It also adds more symmetry with respect to the stringstream version, which does add value.
|
static |
Convert an old style integer level to a logger that outputs to std::cerr all messages of the specified priority level and below.
Level 42 is treated specially. It causes all logging code to be executed but nothing will actually be output.
Level < 0 will never show anything. Not even messages with pri < 0.
Suggested use of priority levels: -1 => Serious errors, always show unless messages disbled completely. 0 => Shown during normal execution. Also in production mode. 1+ => For debugging and testing.
1.8.17