# clutchlog: clutchlog Class Reference

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 188 of file clutchlog.h.

## Public Member Functions

Configuration accessors
void | format (const std::string &format)
| Set the template string. More...
std::string | format () const
| Get the template string. More...
void | format_comment (const std::string &format)
| Set the template string for dumps. More...
std::string | format_comment () const
| Get the template string for dumps. More...
void | out (std::ostream &out)
| Set the output stream on which to print. More...
std::ostream & | out ()
| Get the output stream on which to print. More...
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. More...
void | threshold (const std::string &l)
| Set the log level (below which logs are not printed) with a string. More...
level | threshold () const
| Get the log level below which logs are not printed. More...
const std::map< std::string, level > & | levels () const
| Get the map of available log levels string representations toward their identifier. *‍/. More...
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. More...
void | func (std::string func)
| Set the regular expression filtering the function location. More...
void | line (std::string line)
| Set the regular expression filtering the line location. More...
void | location (const std::string &in_file, const std::string &in_function=".*", const std::string &in_line=".*")
| Set the regular expressions filtering the location. More...
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. More...
fmt | style (level stage) const
| Get the configured fmt instance of the given log level. More...
void | filename (filename f)
| Sets the file naming scheme. *‍/. More...
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. More...
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. More...
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. More...
void | log (const level &stage, const std::string &what, const std::string &file, const std::string &func, const size_t line, const size_t depth_delta=0) const
| Print a log message IF the location matches the given one. More...
template<class In >
void | dump (const level &stage, const In container_begin, const In container_end, const std::string &file, const std::string &func, const 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. More...

## Static Protected Attributes

Default configuration members
static std::string | default_format = CLUTCHLOG_DEFAULT_FORMAT
| Default format of the messages. More...
static std::string | dump_default_format = CLUTCHDUMP_DEFAULT_FORMAT
| Default format of the comment line in file dump. More...
static std::string | dump_default_sep = CLUTCHDUMP_DEFAULT_SEP
| Default item separator for dump. More...
static std::string | default_depth_mark = CLUTCHLOG_DEFAULT_DEPTH_MARK
| Default mark for stack depth. More...
static unsigned int | default_strip_calls = CLUTCHLOG_STRIP_CALLS
| Number of call stack levels to remove from depth display by default. More...
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}". More...
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}"). More...
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}"). More...

## 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. More...
enum | filename { path , base , dir , dirbase , stem , dirstem }
| Available filename rendering methods. More...
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. More...
const std::map< level, std::string > | _level_word
| Dictionary of level identifier to their string representation. More...
std::map< std::string, level > | _word_level
| Dictionary of level string to their identifier. More...
std::map< level, std::string > | _level_short
| dictionary of level identifier to their 4-letters representation. More...
std::map< level, fmt > | _level_fmt
| Dictionary of level identifier to their format. More...
std::string | _format_log
| Current format of the standard output. More...
std::string | _format_dump
| Current format of the file output. More...
std::ostream * | _out
| Standard output. More...
level | _stage
| Current log level. More...
std::regex | _in_file
| Current file location filter. More...
std::regex | _in_func
| Current function location filter. More...
std::regex | _in_line
| Current line location filter. More...
std::vector< fmt > | _filehash_fmts
| List of candidate format objects for value-dependant file name styling. More...
std::vector< fmt > | _funchash_fmts
| List of candidate format objects for value-dependant function name styling. More...
filename | _filename
| Filename rendering method. More...
| clutchlog (clutchlog const &)=delete
void | operator= (clutchlog const &)=delete
| clutchlog ()

## Constructor & Destructor Documentation

## clutchlog()

clutchlog::clutchlog | ( |  | ) |

inlineprivate

Definition at line 850 of file clutchlog.h.

## Member Function Documentation

## logger()

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

inlinestatic

Get the logger instance.

auto& log = clutchlog::logger();
clutchlog::log
void log(const level &stage, const std::string &what, const std::string &file, const std::string &func, const size_t line, const size_t depth_delta=0) const
Print a log message IF the location matches the given one.
Definition: clutchlog.h:1413
clutchlog::logger
static clutchlog & logger()
Get the logger instance.
Definition: clutchlog.h:307

Definition at line 307 of file clutchlog.h.

## format() [1/3]

void clutchlog::format | ( | const std::string & | format | ) |

inline

Set the template string.

Definition at line 986 of file clutchlog.h.

References _format_log, and format().

Referenced by format().

## format() [2/3]

std::string clutchlog::format | ( |  | ) | const

inline

Get the template string.

Definition at line 988 of file clutchlog.h.

References _format_log.

Referenced by dump(), format_comment(), and log().

## format_comment() [1/2]

void clutchlog::format_comment | ( | const std::string & | format | ) |

inline

Set the template string for dumps.

Definition at line 991 of file clutchlog.h.

References _format_dump, and format().

## format_comment() [2/2]

std::string clutchlog::format_comment | ( |  | ) | const

inline

Get the template string for dumps.

Definition at line 993 of file clutchlog.h.

References _format_dump.

## out() [1/2]

void clutchlog::out | ( | std::ostream & | out | ) |

inline

Set the output stream on which to print.

Definition at line 996 of file clutchlog.h.

References _out, and out().

Referenced by out().

## out() [2/2]

std::ostream & clutchlog::out | ( |  | ) |

inline

Get the output stream on which to print.

Definition at line 998 of file clutchlog.h.

References _out.

## 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 1047 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 1055 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 1064 of file clutchlog.h.

## threshold() [1/3]

void clutchlog::threshold | ( | level | l | ) |

inline

Set the log level (below which logs are not printed) with an identifier.

Definition at line 1067 of file clutchlog.h.

References _stage.

## threshold() [2/3]

void clutchlog::threshold | ( | const std::string & | l | ) |

inline

Set the log level (below which logs are not printed) with a string.

Definition at line 1069 of file clutchlog.h.

References _stage, and level_of().

## threshold() [3/3]

level clutchlog::threshold | ( |  | ) | const

inline

Get the log level below which logs are not printed.

Definition at line 1071 of file clutchlog.h.

References _stage.

## levels()

const std::map< std::string, level > & clutchlog::levels | ( |  | ) | const

inline

Get the map of available log levels string representations toward their identifier. *‍/.

Definition at line 1073 of file clutchlog.h.

References _word_level.

## 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 1079 of file clutchlog.h.

References _word_level.

Referenced by threshold().

## file()

void clutchlog::file | ( | std::string | file | ) |

inline

Set the regular expression filtering the file location.

Definition at line 1090 of file clutchlog.h.

References _in_file, and file().

Referenced by dump(), file(), format(), locate(), location(), and log().

## func()

void clutchlog::func | ( | std::string | func | ) |

inline

Set the regular expression filtering the function location.

Definition at line 1092 of file clutchlog.h.

References _in_func, and func().

Referenced by dump(), format(), func(), locate(), location(), and log().

## line()

void clutchlog::line | ( | std::string | line | ) |

inline

Set the regular expression filtering the line location.

Definition at line 1094 of file clutchlog.h.

References _in_line, and line().

Referenced by dump(), format(), line(), locate(), location(), and log().

## location()

void clutchlog::location | ( | const std::string & | in_file,
|  | const std::string & | in_function = `".*"`,
|  | const std::string & | in_line = `".*"`
| ) |  |

inline

Set the regular expressions filtering the location.

Definition at line 1097 of file clutchlog.h.

References file(), func(), and line().

## style() [1/3]

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 1113 of file clutchlog.h.

References style().

Referenced by style().

## style() [2/3]

void clutchlog::style | ( | level | stage,
|  | fmt | style
| ) |  |

inline

Set the style (color and typo) of the given log level, passing a `fmt` instance.

Definition at line 1115 of file clutchlog.h.

References _level_fmt, and style().

Referenced by style().

## style() [3/3]

fmt clutchlog::style | ( | level | stage | ) | const

inline

Get the configured fmt instance of the given log level.

Definition at line 1117 of file clutchlog.h.

References _level_fmt.

## filename()

void clutchlog::filename | ( | filename | f | ) |

inline

Sets the file naming scheme. *‍/.

Definition at line 1120 of file clutchlog.h.

References _filename.

## locate()

scope_t clutchlog::locate | ( | const level & | stage,
|  | const std::string & | file,
|  | const std::string & | func,
|  | const size_t | line
| ) |  | const

inline

Gather information on the current location of the call.

Definition at line 1154 of file clutchlog.h.

References _in_file, _in_func, _in_line, _stage, _strip_calls, file(), func(), line(), clutchlog::scope_t::matches, clutchlog::scope_t::stage, and clutchlog::scope_t::there.

Referenced by dump(), and log().

## replace() [1/2]

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 1205 of file clutchlog.h.

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

## replace() [2/2]

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

inline

Replace `mark` by `tag` in `form`, converting tag to its string representation first.

Definition at line 1270 of file clutchlog.h.

References replace().

## format() [3/3]

std::string clutchlog::format | ( | std::string | row,
|  | const std::string & | what,
|  | const level & | stage,
|  | const std::string & | file,
|  | const std::string & | func,
|  | const size_t | line
| ) |  | const

inline

Substitute all tags in the format string with the corresponding information and apply the style corresponding to the log level.

Definition at line 1281 of file clutchlog.h.

References _filehash_fmts, _filename, _funchash_fmts, _level_fmt, _level_short, _level_word, _strip_calls, file(), func(), line(), and replace().

## log()

void clutchlog::log | ( | const level & | stage,
|  | const std::string & | what,
|  | const std::string & | file,
|  | const std::string & | func,
|  | const size_t | line,
|  | const size_t | depth_delta = `0`
| ) |  | const

inline

Print a log message IF the location matches the given one.

Definition at line 1413 of file clutchlog.h.

References _format_log, _out, file(), format(), func(), line(), locate(), and clutchlog::scope_t::matches.

## dump()

template<class In >

void clutchlog::dump | ( | const level & | stage,
|  | const In | container_begin,
|  | const In | container_end,
|  | const std::string & | file,
|  | const std::string & | func,
|  | const size_t | line,
|  | const std::string & | filename_template = `"dump_{n}.dat"`,
|  | const std::string | sep = `dump_default_sep`
| ) |  | const

inline

Dump a serializable container after a comment line with log information.

Definition at line 1438 of file clutchlog.h.

References _format_dump, file(), format(), func(), line(), locate(), clutchlog::scope_t::matches, and replace().

## Member Data Documentation

## default_format

std::string clutchlog::default_format = CLUTCHLOG_DEFAULT_FORMAT

inlinestaticprotected

Default format of the messages.

Definition at line 224 of file clutchlog.h.

## dump_default_format

std::string clutchlog::dump_default_format = CLUTCHDUMP_DEFAULT_FORMAT

inlinestaticprotected

Default format of the comment line in file dump.

Definition at line 246 of file clutchlog.h.

## dump_default_sep

std::string clutchlog::dump_default_sep = CLUTCHDUMP_DEFAULT_SEP

inlinestaticprotected

Default item separator for dump.

Definition at line 253 of file clutchlog.h.

## default_depth_mark

std::string clutchlog::default_depth_mark = CLUTCHLOG_DEFAULT_DEPTH_MARK

inlinestaticprotected

Default mark for stack depth.

Definition at line 260 of file clutchlog.h.

## default_strip_calls

unsigned int clutchlog::default_strip_calls = CLUTCHLOG_STRIP_CALLS

inlinestaticprotected

Number of call stack levels to remove from depth display by default.

Definition at line 267 of file clutchlog.h.

## default_hfill_char

char clutchlog::default_hfill_char = CLUTCHLOG_DEFAULT_HFILL_MARK

inlinestaticprotected

Default character used as a filling for right-align the right part of messages with "{hfill}".

Definition at line 274 of file clutchlog.h.

## default_hfill_max

size_t clutchlog::default_hfill_max = CLUTCHLOG_DEFAULT_HFILL_MAX

inlinestaticprotected

Default maximum width (number of characters) for which to fill for right-aligning the right part of messages (using "{hfill}").

Definition at line 286 of file clutchlog.h.

## default_hfill_min

size_t clutchlog::default_hfill_min = CLUTCHLOG_DEFAULT_HFILL_MIN

inlinestaticprotected

Default minimum width (number of characters) at which to fill for right-aligning the right part of messages (using "{hfill}").

Definition at line 288 of file clutchlog.h.

## _strip_calls

size_t clutchlog::_strip_calls

protected

Current number of call stack levels to remove from depth display.

Definition at line 919 of file clutchlog.h.

Referenced by format(), and locate().

## _level_word

const std::map<level,std::string> clutchlog::_level_word

protected

Dictionary of level identifier to their string representation.

Definition at line 921 of file clutchlog.h.

Referenced by format().

## _word_level

std::map<std::string,level> clutchlog::_word_level

protected

Dictionary of level string to their identifier.

Definition at line 923 of file clutchlog.h.

Referenced by level_of(), and levels().

## _level_short

std::map<level,std::string> clutchlog::_level_short

protected

dictionary of level identifier to their 4-letters representation.

Definition at line 925 of file clutchlog.h.

Referenced by format().

## _level_fmt

std::map<level,fmt> clutchlog::_level_fmt

protected

Dictionary of level identifier to their format.

Definition at line 927 of file clutchlog.h.

Referenced by format(), and style().

## _format_log

std::string clutchlog::_format_log

protected

Current format of the standard output.

Definition at line 929 of file clutchlog.h.

Referenced by format(), and log().

## _format_dump

std::string clutchlog::_format_dump

protected

Current format of the file output.

Definition at line 931 of file clutchlog.h.

Referenced by dump(), and format_comment().

## _out

std::ostream* clutchlog::_out

protected

Standard output.

Definition at line 943 of file clutchlog.h.

Referenced by log(), and out().

## _stage

level clutchlog::_stage

protected

Current log level.

Definition at line 951 of file clutchlog.h.

Referenced by locate(), and threshold().

## _in_file

std::regex clutchlog::_in_file

protected

Current file location filter.

Definition at line 953 of file clutchlog.h.

Referenced by file(), and locate().

## _in_func

std::regex clutchlog::_in_func

protected

Current function location filter.

Definition at line 955 of file clutchlog.h.

Referenced by func(), and locate().

## _in_line

std::regex clutchlog::_in_line

protected

Current line location filter.

Definition at line 957 of file clutchlog.h.

Referenced by line(), and locate().

## _filehash_fmts

std::vector<fmt> clutchlog::_filehash_fmts

protected

List of candidate format objects for value-dependant file name styling.

Definition at line 960 of file clutchlog.h.

Referenced by filehash_styles(), and format().

## _funchash_fmts

std::vector<fmt> clutchlog::_funchash_fmts

protected

List of candidate format objects for value-dependant function name styling.

Definition at line 962 of file clutchlog.h.

Referenced by format(), and funchash_styles().

## _filename

filename clutchlog::_filename

protected

Filename rendering method.

Definition at line 977 of file clutchlog.h.

Referenced by filename(), and format().

## Member Enumeration Documentation

## level

enum clutchlog::level

Available log levels.

Definition at line 314 of file clutchlog.h.

## filename

enum clutchlog::filename

Available filename rendering methods.

Definition at line 317 of file clutchlog.h.

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

- clutchlog.h