34: std::ostream(std::cout.rdbuf())
74 options->
AddOptions(
"Logging options")(
"QwLog.color",
75 po::value<bool>()->default_value(
true),
76 "colored screen output");
77 options->
AddOptions(
"Logging options")(
"QwLog.logfile",
80 options->
AddOptions(
"Logging options")(
"QwLog.loglevel-file",
81 po::value<int>()->default_value(
kMessage),
82 "log level for file output");
83 options->
AddOptions(
"Logging options")(
"QwLog.loglevel-screen",
84 po::value<int>()->default_value(
kMessage),
85 "log level for screen output");
86 options->
AddOptions(
"Logging options")(
"QwLog.print-signature",
87 po::value<bool>()->default_bool_value(
false),
88 "print signature on error or warning");
89 options->
AddOptions(
"Logging options")(
"QwLog.debug-function",
90 po::value< std::vector<string> >()->multitoken(),
91 "print debugging output of function with signatures satisfying the specified regex");
109 if (options->
HasValue(
"QwLog.logfile"))
125 std::cout <<
"Debug regex list:" << std::endl;
144 if (std::regex_match(func_sig, regex)) {
162 std::ios_base::openmode flags = std::ios::out | mode;
163 fFile =
new std::ofstream(name.c_str(), flags);
192 const std::string func_sig)
210 *(
fScreen) <<
"Error (in " << func_sig <<
"): ";
220 *(
fScreen) <<
"Warning (in " << func_sig <<
"): ";
245 default: *(
fFile) <<
" ";
break;
303 *(
gQwLog.fScreen) << std::endl;
308 *(
gQwLog.fFile) << std::endl;
320 *(
gQwLog.fScreen) << std::flush;
323 *(
gQwLog.fFile) << std::flush;
332 time_t now = time(0);
334 struct tm *currentTime = localtime(&now);
335 strftime(
fTimeString, 128,
"%Y-%m-%d, %T", currentTime);
ANSI color codes and color management for terminal output.
An options class which parses command line, config file and environment.
A logfile class, based on an identical class in the Hermes analyzer.
A color changing class for the output stream.
Logging and output management system with configurable verbosity levels.
QwLogLevel fLogLevel
Log level of this stream.
void ProcessOptions(QwOptions *options)
Process class options for QwOptions.
std::map< std::string, bool > fIsDebugFunction
List of regular expressions for functions that will have increased log level.
bool fPrintFunctionSignature
Flag to print function signature on warning or error.
static bool fScreenInColor
bool fUseColor
Flag to disable color.
static bool fFileAtNewLine
Flags only relevant for current line, but static for use in static function.
QwLog & operator()(const QwLogLevel level, const std::string func_sig="<unknown>")
Set the stream log level.
QwLog & operator<<(const T &t)
Stream an object to the output stream.
void SetFileThreshold(int thr)
Set the file log level.
~QwLog() override
The destructor.
static const std::ios_base::openmode kTruncate
Log file open modes.
void SetScreenThreshold(int thr)
Set the screen log level.
QwLogLevel fScreenThreshold
Screen thresholds and stream.
static std::ostream & flush(std::ostream &)
Flush the streams.
const char * GetTime()
Get the local time.
static bool fScreenAtNewLine
static std::ostream & endl(std::ostream &)
End of the line.
void InitLogFile(const std::string name, const std::ios_base::openmode mode=kAppend)
Initialize the log file with name 'name'.
bool IsDebugFunction(const string func_name)
Determine whether the function name matches a specified list of regular expressions.
QwLogLevel fFileThreshold
File thresholds and stream.
static const std::ios_base::openmode kAppend
void SetScreenColor(bool flag)
Set the screen color mode.
static void DefineOptions(QwOptions *options)
Define available class options for QwOptions.
std::vector< std::string > fDebugFunctionRegexString
Command-line and configuration file options processor.
std::vector< T > GetValueVector(const std::string &key)
Get a list of templated values.
T GetValue(const std::string &key)
Get a templated value.
bool HasValue(const std::string &key)
Has this key been defined.
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.