Gemmi C++ API
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
gemmi::Logger Struct Reference

Passes messages (including warnings/errors) to a callback function. More...

#include <logger.hpp>

Public Member Functions

void suspend ()
 suspend() and resume() are used internally to avoid duplicate messages when the same function is called (internally) multiple times.
 
void resume ()
 
template<int N, class... Args>
void level (Args const &... args) const
 Send a message without any prefix on with a numeric threshold N.
 
template<class... Args>
void debug (Args const &... args) const
 Send a debug message.
 
template<class... Args>
void mesg (Args const &... args) const
 Send a message without any prefix.
 
template<class... Args>
void note (Args const &... args) const
 Send a note (a notice, a significant message).
 
template<class... Args>
GEMMI_COLD void err (Args const &... args) const
 Send a warning/error (see Quirk above).
 

Static Public Member Functions

static void to_stderr (const std::string &s)
 to be used as: logger.callback = Logger::to_stderr;
 
static void to_stdout (const std::string &s)
 to be used as: logger.callback = Logger::to_stdout;
 

Public Attributes

std::function< void(const std::string &)> callback
 A function that handles messages.
 
int threshold = 6
 Pass messages of this level and all lower (more severe) levels: 8=all, 6=all but debug, 5=notes and warnings, 3=warnings, 0=none.
 

Detailed Description

Passes messages (including warnings/errors) to a callback function.

Messages are passed as strings without a trailing newline. They have syslog-like severity levels: 8=debug, 6=info, 5=notice, 3=error, allowing the use of a threshold to filter them. Quirk: Errors double as both errors and warnings. Unrecoverable errors don't go through this class; Logger only handles errors that can be downgraded to warnings. If a callback is set, the error is passed as a warning message. Otherwise, it's thrown as std::runtime_error.

Definition at line 23 of file logger.hpp.

Member Function Documentation

◆ suspend()

void gemmi::Logger::suspend ( )
inline

suspend() and resume() are used internally to avoid duplicate messages when the same function is called (internally) multiple times.

Definition at line 32 of file logger.hpp.

◆ resume()

void gemmi::Logger::resume ( )
inline

Definition at line 33 of file logger.hpp.

◆ level()

template<int N, class... Args>
void gemmi::Logger::level ( Args const &...  args) const
inline

Send a message without any prefix on with a numeric threshold N.

Definition at line 36 of file logger.hpp.

◆ debug()

template<class... Args>
void gemmi::Logger::debug ( Args const &...  args) const
inline

Send a debug message.

Definition at line 42 of file logger.hpp.

◆ mesg()

template<class... Args>
void gemmi::Logger::mesg ( Args const &...  args) const
inline

Send a message without any prefix.

Definition at line 44 of file logger.hpp.

◆ note()

template<class... Args>
void gemmi::Logger::note ( Args const &...  args) const
inline

Send a note (a notice, a significant message).

Definition at line 46 of file logger.hpp.

◆ err()

template<class... Args>
GEMMI_COLD void gemmi::Logger::err ( Args const &...  args) const
inline

Send a warning/error (see Quirk above).

Definition at line 49 of file logger.hpp.

◆ to_stderr()

static void gemmi::Logger::to_stderr ( const std::string &  s)
inlinestatic

to be used as: logger.callback = Logger::to_stderr;

Definition at line 61 of file logger.hpp.

◆ to_stdout()

static void gemmi::Logger::to_stdout ( const std::string &  s)
inlinestatic

to be used as: logger.callback = Logger::to_stdout;

Definition at line 65 of file logger.hpp.

Member Data Documentation

◆ callback

std::function<void(const std::string&)> gemmi::Logger::callback

A function that handles messages.

Definition at line 25 of file logger.hpp.

◆ threshold

int gemmi::Logger::threshold = 6

Pass messages of this level and all lower (more severe) levels: 8=all, 6=all but debug, 5=notes and warnings, 3=warnings, 0=none.

Definition at line 28 of file logger.hpp.


The documentation for this struct was generated from the following file: