Merge branch 'master' of github.com:nojhan/clutchlog
This commit is contained in:
commit
0fc2b0cc23
2 changed files with 111 additions and 42 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef __CLUTCHLOG_H__
|
||||
#define __CLUTCHLOG_H__
|
||||
#pragma once
|
||||
#ifndef CLUTCHLOG_H
|
||||
#define CLUTCHLOG_H
|
||||
|
||||
/** @file */
|
||||
#include <ciso646>
|
||||
|
|
@ -257,10 +257,23 @@ class clutchlog
|
|||
#endif // CLUTCHLOG_HFILL_MARK
|
||||
//! Default character used as a filling for right-align the right part of messages with "{hfill}".
|
||||
static inline char default_hfill_char = CLUTCHLOG_HFILL_MARK;
|
||||
|
||||
|
||||
#if CLUTCHLOG_HAVE_UNIX_SYSIOCTL == 1
|
||||
#ifndef CLUTCHLOG_HFILL_MAX
|
||||
#define CLUTCHLOG_HFILL_MAX 300
|
||||
#endif
|
||||
#endif
|
||||
//! Default maximum number of character used as a filling for right-align the right part of messages with "{hfill}".
|
||||
static inline unsigned short default_hfill_max = CLUTCHLOG_HFILL_MAX;
|
||||
|
||||
// NOTE: there is no CLUTCHLOG_HFILL_STYLE for defaulting,
|
||||
// but you can still set `hfill_style(...)` on the logger singleton.
|
||||
/* @} */
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** @name High-level API
|
||||
* @{ */
|
||||
|
||||
|
|
@ -435,12 +448,16 @@ class clutchlog
|
|||
}),
|
||||
_format_log(clutchlog::default_format),
|
||||
_format_dump(clutchlog::dump_default_format),
|
||||
_hfill_char(clutchlog::default_hfill_char),
|
||||
#if CLUTCHLOG_HAVE_UNIX_SYSIOCTL
|
||||
_hfill_char(clutchlog::default_hfill_char),
|
||||
_hfill_fmt(fmt::fg::none),
|
||||
_hfill_max(clutchlog::default_hfill_max),
|
||||
#endif
|
||||
_out(&std::clog),
|
||||
#if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
|
||||
_depth(std::numeric_limits<size_t>::max() - _strip_calls),
|
||||
_depth_mark(clutchlog::default_depth_mark),
|
||||
#endif
|
||||
#if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
|
||||
_depth(std::numeric_limits<size_t>::max() - _strip_calls),
|
||||
_depth_mark(clutchlog::default_depth_mark),
|
||||
#endif
|
||||
_stage(level::error),
|
||||
_in_file(".*"),
|
||||
_in_func(".*"),
|
||||
|
|
@ -452,8 +469,8 @@ class clutchlog
|
|||
}
|
||||
#if CLUTCHLOG_HAVE_UNIX_SYSIOCTL
|
||||
struct winsize w;
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||
_nb_columns = w.ws_col;
|
||||
ioctl(STDERR_FILENO, TIOCGWINSZ, &w);
|
||||
_nb_columns = std::min(w.ws_col, default_hfill_max);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -470,16 +487,22 @@ class clutchlog
|
|||
std::string _format_log;
|
||||
/** Current format of the file output. */
|
||||
std::string _format_dump;
|
||||
/** Character for filling. */
|
||||
char _hfill_char;
|
||||
#if CLUTCHLOG_HAVE_UNIX_SYSIOCTL
|
||||
/** Character for filling. */
|
||||
char _hfill_char;
|
||||
/** Style of the filling. */
|
||||
fmt _hfill_fmt;
|
||||
/** Maximum number of fill char. */
|
||||
unsigned short _hfill_max;
|
||||
#endif
|
||||
/** Standard output. */
|
||||
std::ostream* _out;
|
||||
#if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
|
||||
/** Current stack depth (above which logs are not printed). */
|
||||
size_t _depth;
|
||||
/** Current depth mark. */
|
||||
std::string _depth_mark;
|
||||
#endif
|
||||
#if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
|
||||
/** Current stack depth (above which logs are not printed). */
|
||||
size_t _depth;
|
||||
/** Current depth mark. */
|
||||
std::string _depth_mark;
|
||||
#endif
|
||||
/** Current log level. */
|
||||
level _stage;
|
||||
/** Current file location filter. */
|
||||
|
|
@ -541,6 +564,20 @@ class clutchlog
|
|||
void hfill_mark(const char mark) {_hfill_char = mark;}
|
||||
//! Get the character for the stretching hfill marker.
|
||||
char hfill_mark() const {return _hfill_char;}
|
||||
//! Set the style for the stretching hfill marker, with a `fmt` object.
|
||||
void hfill_style(fmt style) {_hfill_fmt = style;}
|
||||
/** Set the style for the stretching hfill marker.
|
||||
*
|
||||
* This version accept style arguments as if they were passed to `clutchlog::fmt`.
|
||||
*/
|
||||
template<class ... FMT>
|
||||
void style(FMT... styles) { this->hfill_style(fmt(styles...)); }
|
||||
//! Get the character for the stretching hfill marker.
|
||||
fmt hfill_style() const {return _hfill_fmt;}
|
||||
//! Set the maximum number of hfill characters. */
|
||||
void hfill_max(const size_t nmax) {_hfill_max = nmax;}
|
||||
//! Get the maximum number of hfill characters. */
|
||||
unsigned short hfill_max() {return _hfill_max;}
|
||||
#endif
|
||||
|
||||
//! Set the log level (below which logs are not printed) with an identifier.
|
||||
|
|
@ -800,15 +837,19 @@ class clutchlog
|
|||
if(right_len+left_len > _nb_columns) {
|
||||
// The right part would go over the terminal width: add a new line.
|
||||
const std::string hfill(std::max((size_t)0, _nb_columns-right_len), _hfill_char);
|
||||
format = replace(format, "\\{hfill\\}", "\n"+hfill);
|
||||
const std::string hfill_styled = _hfill_fmt(hfill);
|
||||
format = replace(format, "\\{hfill\\}", "\n"+hfill_styled);
|
||||
} else {
|
||||
// There is some space in between left and right parts.
|
||||
const std::string hfill(std::max((size_t)0, _nb_columns - (right_len+left_len)), _hfill_char);
|
||||
format = replace(format, "\\{hfill\\}", hfill);
|
||||
const std::string hfill_styled = _hfill_fmt(hfill);
|
||||
format = replace(format, "\\{hfill\\}", hfill_styled);
|
||||
}
|
||||
} else {
|
||||
// We don't know the terminal width.
|
||||
format = replace(format, "\\{hfill\\}", _hfill_char);
|
||||
const std::string hfill(1, _hfill_char);
|
||||
const std::string hfill_styled = _hfill_fmt(hfill);
|
||||
format = replace(format, "\\{hfill\\}", hfill_styled);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -967,12 +1008,16 @@ class clutchlog
|
|||
#if CLUTCHLOG_HAVE_UNIX_SYSIOCTL == 1
|
||||
void hfill_mark(const char) {}
|
||||
char hfill_mark() const {}
|
||||
void hfill_fmt(fmt) {}
|
||||
fmt hfill_fmt() const {}
|
||||
void hfill_max(const size_t) {}
|
||||
unsigned short hfill_max() {}
|
||||
#endif
|
||||
|
||||
void threshold(level) {}
|
||||
void threshold(const std::string&) {}
|
||||
level threshold() const {}
|
||||
const std::map<std::string,level> levels() const {};
|
||||
const std::map<std::string,level> levels() const {}
|
||||
level level_of(const std::string) {}
|
||||
|
||||
void file(std::string) {}
|
||||
|
|
@ -988,6 +1033,8 @@ class clutchlog
|
|||
)
|
||||
{}
|
||||
#pragma GCC diagnostic pop
|
||||
template<class ... FMT>
|
||||
void style(level, FMT...) {}
|
||||
void style(level, fmt) {}
|
||||
fmt style(level) const {}
|
||||
public:
|
||||
|
|
@ -1042,4 +1089,4 @@ class clutchlog
|
|||
#pragma GCC diagnostic pop
|
||||
#endif // WITH_CLUTCHLOG
|
||||
|
||||
#endif // __CLUTCHLOG_H__
|
||||
#endif // CLUTCHLOG_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue