indentlog: strongly-typed fucntion_style enum

This commit is contained in:
Roland Conybeare 2023-09-18 13:24:41 -04:00
commit 5c60277610
5 changed files with 31 additions and 25 deletions

View file

@ -27,7 +27,7 @@ main(int argc, char ** argv) {
log_config::min_log_level = log_level::info;
log_config::time_enabled = true;
log_config::time_local_flag = true;
log_config::style = FS_Streamlined;
log_config::style = function_style::streamlined;
log_config::indent_width = 4;
log_config::max_indent_width = 30;
log_config::location_tab = 80;

View file

@ -26,8 +26,7 @@ private:
int
main(int argc, char ** argv) {
//log_config::style = FS_Pretty;
log_config::style = FS_Streamlined;
log_config::style = function_style::streamlined;
log_config::min_log_level = log_level::info;
scope log(XO_ENTER0(info));
@ -37,15 +36,15 @@ main(int argc, char ** argv) {
double x = 3.0;
double r = 0.0;
log_config::style = FS_Pretty;
log_config::style = function_style::pretty;
r = quadratic(x);
log_config::style = FS_Streamlined;
log_config::style = function_style::streamlined;
r = quadratic(x);
log_config::style = FS_Simple;
log_config::style = function_style::simple;
r = quadratic(x);
}

View file

@ -6,15 +6,22 @@
#include <cstdint>
namespace xo {
enum function_style {
/* literal: print given name, no alterations */
FS_Literal,
/* pretty: print name, surrounded by [] */
FS_Pretty,
/* streamlined: remove extraneous detail, try to print something like class::method */
FS_Streamlined,
/* simple: remove everything except function/method name */
FS_Simple
enum class function_style : std::uint8_t {
/* literal: print supplied text, no alterations */
literal,
/* pretty: print name, surrounded by []
* [double Quadratic::operator()(double) const]
*/
pretty,
/* streamlined: remove extraneous detail,
* try to print something like class::method
* Quadratic::operator()
*/
streamlined,
/* simple: remove everything except function/method name
* operator()
*/
simple
};
/* Tag to drive header-only expression */
@ -245,23 +252,23 @@ namespace xo {
/* set text color */
switch(fn.style()) {
case FS_Literal:
case function_style::literal:
os << with_color(fn.colorspec(), fn.pretty());
break;
case FS_Pretty:
case function_style::pretty:
os << "[" << with_color(fn.colorspec(), fn.pretty()) << "]";
break;
case FS_Simple:
os << color_on(fn.colorspec());
function_name::print_simple(os, fn.pretty());
os << color_off();
break;
case FS_Streamlined:
case function_style::streamlined:
/* omit namespace qualifiers and template arguments */
os << color_on(fn.colorspec());
function_name::print_streamlined(os, fn.pretty());
os << color_off();
break;
case function_style::simple:
os << color_on(fn.colorspec());
function_name::print_simple(os, fn.pretty());
os << color_off();
break;
}
return os;

View file

@ -76,7 +76,7 @@ namespace xo {
template <typename Tag>
function_style
log_config_impl<Tag>::style = FS_Streamlined;
log_config_impl<Tag>::style = function_style::streamlined;
template <typename Tag>
color_spec_type

View file

@ -56,7 +56,7 @@ namespace xo {
/* threshold level for logging -- write messages with severity >= this level */
log_level log_level_ = log_level::error;
/* FS_Pretty | FS_Streamlined | FS_Simple */
function_style style_ = FS_Pretty;
function_style style_ = function_style::pretty;
std::string_view name1_ = "<.name1>";
std::string_view name2_ = "<.name2>";
/* __FILE__ */
@ -168,7 +168,7 @@ namespace xo {
/* send indented output to this streambuf (e.g. std::clog.rdbuf()) */
std::streambuf * dest_sbuf_ = std::clog.rdbuf();
/* style for displaying .name1 */
function_style style_ = FS_Pretty;
function_style style_ = function_style::pretty;
/* name of this scope (part 1) */
std::string_view name1_ = "<name1>";
/* name of this scope (part 2) */