clutchlog Class Reference
Main class

The single class which holds everything. More...

`#include <clutchlog.h>`

## Detailed Description

The single class which holds everything.

This is a Singleton class.

Definition at line 177 of file clutchlog.h.

## 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 | filehash_styles (std::vector< fmt > styles)
| Set the candidate styles for value-dependant file name formatting. More...
void | funchash_styles (std::vector< fmt > styles)
| Set the candidate styles for value-dependant function name formatting. More...
void | depth_styles (std::vector< fmt > styles)
| Set the styles for value-dependant depth formatting. More...
void | threshold (level l)
| Set the log level (below which logs are not printed) with an identifier.
void | threshold (const std::string &l)
| Set the log level (below which logs are not printed) with a string.
level | threshold () const
| Get the log level below which logs are not printed.
const std::map< std::string, level > & | levels () const
| Get the map of available log levels string representations toward their identifier. *‍/.
level | level_of (const std::string name)
| Return the log level tag corresponding to the given pre-configured name. More...
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.
Low-level API
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.
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 row, 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=dump_default_sep) const
| Dump a serializable container after a comment line with log information.

## Static Protected Attributes

Default configuration members
static std::string | default_format = CLUTCHLOG_DEFAULT_FORMAT
| Default format of the messages.
static std::string | dump_default_format = CLUTCHDUMP_DEFAULT_FORMAT
| Default format of the comment line in file dump.
static std::string | dump_default_sep = CLUTCHDUMP_DEFAULT_SEP
| Default item separator for dump.
static std::string | default_depth_mark = CLUTCHLOG_DEFAULT_DEPTH_MARK
| Default mark for stack depth.
static unsigned int | default_strip_calls = CLUTCHLOG_STRIP_CALLS
| Number of call stack levels to remove from depth display by default.
static char | default_hfill_char = CLUTCHLOG_DEFAULT_HFILL_MARK
| Default character used as a filling for right-align the right part of messages with "{hfill}".
static size_t | default_hfill_max = CLUTCHLOG_DEFAULT_HFILL_MAX
| Default maximum width (number of characters) for which to fill for right-aligning the right part of messages (using "{hfill}").
static size_t | default_hfill_min = CLUTCHLOG_DEFAULT_HFILL_MIN
| Default minimum width (number of characters) at which to fill for right-aligning the right part of messages (using "{hfill}").

## Classes

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

## 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 clutchlog & | logger ()
| Get the logger instance. More...

## Internal details

size_t | _strip_calls
| Current number of call stack levels to remove from depth display.
const std::map< level, std::string > | _level_word
| Dictionary of level identifier to their string representation.
std::map< std::string, level > | _word_level
| Dictionary of level string to their identifier.
std::map< level, std::string > | _level_short
| dictionary of level identifier to their 4-letters representation.
std::map< level, fmt > | _level_fmt
| Dictionary of level identifier to their format.
std::string | _format_log
| Current format of the standard output.
std::string | _format_dump
| Current format of the file output.
std::ostream * | _out
| Standard output.
level | _stage
| Current log level.
std::regex | _in_file
| Current file location filter.
std::regex | _in_func
| Current function location filter.
std::regex | _in_line
| Current line location filter.
std::vector< fmt > | _filehash_fmts
| List of candidate format objects for value-dependant file name styling.
std::vector< fmt > | _funchash_fmts
| List of candidate format objects for value-dependant function name styling.
| clutchlog (clutchlog const &)=delete
void | operator= (clutchlog const &)=delete
| clutchlog ()

## Member Function Documentation

## logger()

static clutchlog& clutchlog::logger | ( |  | ) |

inlinestatic

Get the logger instance.

auto& log = clutchlog::logger();

Definition at line 296 of file clutchlog.h.

## filehash_styles()

void clutchlog::filehash_styles | ( | std::vector< fmt > | styles | ) |

inline

Set the candidate styles for value-dependant file name formatting.

Style will be chosen based on the hash value of the filename among the candidate ones.

See the `{filehash_fmt}` template tag.

Definition at line 1028 of file clutchlog.h.

References _filehash_fmts.

## funchash_styles()

void clutchlog::funchash_styles | ( | std::vector< fmt > | styles | ) |

inline

Set the candidate styles for value-dependant function name formatting.

Style will be chosen based on the hash value of the filename among the candidate ones.

See the `{funchash_fmt}` template tag.

Definition at line 1036 of file clutchlog.h.

References _funchash_fmts.

## depth_styles()

void clutchlog::depth_styles | ( | std::vector< fmt > | styles | ) |

inline

Set the styles for value-dependant depth formatting.

The given list should be ordered, styles will be applied for the corresponding depth level. If the actual depth is larger than the number of styles, the last one is used.

See the `{depth_fmt}` template tag.

Definition at line 1045 of file clutchlog.h.

## 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`.

Definition at line 1060 of file clutchlog.h.

References _word_level.

Referenced by threshold().

## 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`.

Definition at line 1094 of file clutchlog.h.

References style().

Referenced by style().

## 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}"

Definition at line 1183 of file clutchlog.h.

Referenced by dump(), format(), and replace().

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

- clutchlog.h

clutchlog::log
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.
Definition: clutchlog.h:1356
clutchlog::logger
static clutchlog & logger()
Get the logger instance.
Definition: clutchlog.h:296