Add debug logging facility

This commit is contained in:
Jonathan Müller 2017-04-06 12:09:29 +02:00
commit da5b46fdb7
4 changed files with 27 additions and 0 deletions

View file

@ -66,6 +66,7 @@ namespace cppast
/// The severity of a [cppast::diagnostic]().
enum class severity
{
debug, //< A debug diagnostic that is just for debugging purposes.
warning, //< A warning that doesn't impact AST generation.
error, //< A non-critical error that does impact AST generation but not critically.
critical, //< A critical error where AST generation isn't possible.
@ -77,6 +78,8 @@ namespace cppast
{
switch (s)
{
case severity::debug:
return "debug";
case severity::warning:
return "warning";
case severity::error:

View file

@ -43,10 +43,23 @@ namespace cppast
return error_;
}
/// \effects Sets whether or not the logger prints debugging diagnostics.
void set_verbose(bool value) noexcept
{
verbose_ = value;
}
/// \returns Whether or not the logger prints debugging diagnostics.
bool is_verbose() const noexcept
{
return verbose_;
}
private:
virtual bool do_log(const char* source, const diagnostic& d) const = 0;
mutable std::atomic<bool> error_;
bool verbose_ = false;
};
/// A [cppast::diagnostic_logger]() that logs to `stderr`.