clutchlog  0.5.0
Classes | List of all members
clutchlog Class Reference

Single class that holds everything. More...

#include <clutchlog.h>

Classes

class  fmt
 Color and style formatter for ANSI terminal escape sequences. More...
 
struct  scope_t
 Structure holding a location matching. More...
 

Public Member Functions

Configuration accessors
void format (const std::string &format)
 Set the template string.
 
std::string format () const
 Get the template string.
 
void format_comment (const std::string &format)
 Set the template string for dumps.
 
std::string format_comment () const
 Get the template string for dumps.
 
void out (std::ostream &out)
 Set the output stream on which to print.
 
std::ostream & out ()
 Get the output stream on which to print.
 
void threshold (level l)
 Set the log level below which logs are not printed.
 
level threshold () const
 Get the log level below which logs are not printed.
 
void file (std::string file)
 Set the regular expression filtering the file location.
 
void func (std::string func)
 Set the regular expression filtering the function location.
 
void line (std::string line)
 Set the regular expression filtering the line location.
 
void location (const std::string &in_file, const std::string &in_function=".*", const std::string &in_line=".*")
 Set the regular expressions filtering the location.
 
template<class ... FMT>
void style (level stage, FMT... styles)
 Set the style (color and typo) of the given log level. More...
 
void style (level stage, fmt style)
 Set the style (color and typo) of the given log level, passing a fmt instance.
 
fmt style (level stage) const
 Get the configured fmt instance of the given log level.
 
level level_of (const std::string name)
 Return the log level tag corresponding to the given pre-configured name. More...
 
Low-level API
std::string replace (const std::string &form, const std::string &mark, const std::string &tag) const
 Replace mark by tag in form. More...
 
std::string replace (const std::string &form, const std::string &mark, const size_t tag) const
 Replace mark by tag in form, converting tag to its string representation first.
 
std::string format (std::string format, const std::string &what, const level &stage, const std::string &file, const std::string &func, const size_t line) const
 Substitute all tags in the format string with the corresponding information and apply the style corresponding to the log level.
 
void log (const level &stage, const std::string &what, const std::string &file, const std::string &func, size_t line) const
 Print a log message IF the location matches the given one.
 
template<class In >
void dump (const level &stage, const In container_begin, const In container_end, const std::string &file, const std::string &func, size_t line, const std::string &filename_template="dump_{n}.dat", const std::string sep=CLUTCHDUMP_DEFAULT_SEP) const
 Dump a serializable container after a comment line with log information.
 

High-level API

enum  level {
  critical =0, error =1, warning =2, progress =3,
  note =4, info =5, debug =6, xdebug =7
}
 Available log levels.
 
static clutchloglogger ()
 Get the logger instance. More...
 

Internal details

const size_t _strip_calls
 
const std::map< level, std::string > _level_word
 
std::map< std::string, level_word_level
 
std::map< level, fmt_level_fmt
 
std::string _format_log
 
std::string _format_dump
 
std::ostream * _out
 
level _stage
 
std::regex _in_file
 
std::regex _in_func
 
std::regex _in_line
 
 clutchlog (clutchlog const &)=delete
 
void operator= (clutchlog const &)=delete
 
scope_t locate (const level &stage, const std::string &file, const std::string &func, const size_t line) const
 Gather information on the current location of the call.
 

Detailed Description

Single class that holds everything.

This is a Singleton class.

Member Function Documentation

◆ level_of()

level clutchlog::level_of ( const std::string  name)
inline

Return the log level tag corresponding to the given pre-configured name.

Note
This is case sensitive, see the pre-configured _level_word.

◆ logger()

static clutchlog& clutchlog::logger ( )
inlinestatic

Get the logger instance.

◆ replace()

std::string clutchlog::replace ( const std::string &  form,
const std::string &  mark,
const std::string &  tag 
) const
inline

Replace mark by tag in form.

log.replace("{greet} {world}", "\\{greet\\}", "hello");
// returns "hello {world}"

◆ style()

template<class ... FMT>
void clutchlog::style ( level  stage,
FMT...  styles 
)
inline

Set the style (color and typo) of the given log level.

This version accept style arguments as if they were passed to clutchlog::fmt.


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