From 5f1c68cc93a486fdb9dec66ab89dd5e42a6e66d2 Mon Sep 17 00:00:00 2001 From: nojhan Date: Mon, 29 Aug 2022 10:26:26 +0200 Subject: [PATCH] update doc --- docs/classclutchlog-members.html | 34 +- docs/classclutchlog.html | 16 +- docs/clutchlog_8h_source.html | 888 ++++++++++++++++--------------- docs/functions.html | 3 + docs/functions_func.html | 3 + docs/group__UseMacros.html | 18 +- docs/index.html | 67 +-- docs/search/all_6.js | 11 +- docs/search/all_7.js | 4 +- docs/search/all_8.js | 6 +- docs/search/all_9.js | 2 +- docs/search/all_a.js | 2 +- docs/search/all_b.js | 6 +- docs/search/all_c.js | 6 +- docs/search/classes_0.js | 2 +- docs/search/classes_1.js | 2 +- docs/search/classes_2.js | 2 +- docs/search/enums_0.js | 2 +- docs/search/enums_1.js | 2 +- docs/search/enums_2.js | 2 +- docs/search/enums_3.js | 2 +- docs/search/files_0.js | 2 +- docs/search/functions_0.js | 2 +- docs/search/functions_1.js | 10 +- docs/search/functions_2.js | 13 +- docs/search/functions_3.js | 4 +- docs/search/functions_4.js | 2 +- docs/search/functions_5.js | 2 +- docs/search/functions_6.js | 4 +- docs/search/functions_7.js | 2 +- docs/search/groups_0.js | 2 +- docs/search/groups_1.js | 2 +- docs/search/groups_2.js | 2 +- docs/search/groups_3.js | 2 +- docs/search/related_0.js | 2 +- 35 files changed, 582 insertions(+), 549 deletions(-) diff --git a/docs/classclutchlog-members.html b/docs/classclutchlog-members.html index 0c01984..e01e9f8 100644 --- a/docs/classclutchlog-members.html +++ b/docs/classclutchlog-members.html @@ -100,22 +100,24 @@ $(function() { info enum value (defined in clutchlog)clutchlog level enum nameclutchlog level_of(const std::string name)clutchloginline - line(std::string line)clutchloginline - locate(const level &stage, const std::string &file, const std::string &func, const size_t line) constclutchloginline - location(const std::string &in_file, const std::string &in_function=".*", const std::string &in_line=".*")clutchloginline - log(const level &stage, const std::string &what, const std::string &file, const std::string &func, size_t line) constclutchloginline - logger()clutchloginlinestatic - note enum value (defined in clutchlog)clutchlog - operator=(clutchlog const &)=delete (defined in clutchlog)clutchlog - out(std::ostream &out)clutchloginline - out()clutchloginline - progress enum value (defined in clutchlog)clutchlog - replace(const std::string &form, const std::string &mark, const std::string &tag) constclutchloginline - replace(const std::string &form, const std::string &mark, const size_t tag) constclutchloginline - style(level stage, FMT... styles)clutchloginline - style(level stage, fmt style)clutchloginline - style(level stage) constclutchloginline - threshold(level l)clutchloginline + levels() constclutchloginline + line(std::string line)clutchloginline + locate(const level &stage, const std::string &file, const std::string &func, const size_t line) constclutchloginline + location(const std::string &in_file, const std::string &in_function=".*", const std::string &in_line=".*")clutchloginline + log(const level &stage, const std::string &what, const std::string &file, const std::string &func, size_t line) constclutchloginline + logger()clutchloginlinestatic + note enum value (defined in clutchlog)clutchlog + operator=(clutchlog const &)=delete (defined in clutchlog)clutchlog + out(std::ostream &out)clutchloginline + out()clutchloginline + progress enum value (defined in clutchlog)clutchlog + replace(const std::string &form, const std::string &mark, const std::string &tag) constclutchloginline + replace(const std::string &form, const std::string &mark, const size_t tag) constclutchloginline + style(level stage, FMT... styles)clutchloginline + style(level stage, fmt style)clutchloginline + style(level stage) constclutchloginline + threshold(level l)clutchloginline + threshold(const std::string &l)clutchloginline threshold() constclutchloginline warning enum value (defined in clutchlog)clutchlog xdebug enum value (defined in clutchlog)clutchlog diff --git a/docs/classclutchlog.html b/docs/classclutchlog.html index 25ca974..9064078 100644 --- a/docs/classclutchlog.html +++ b/docs/classclutchlog.html @@ -109,12 +109,23 @@ std::ostream &   void threshold (level l) - Set the log level below which logs are not printed.
+ 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.
@@ -143,9 +154,6 @@ void 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
scope_t locate (const level &stage, const std::string &file, const std::string &func, const size_t line) const diff --git a/docs/clutchlog_8h_source.html b/docs/clutchlog_8h_source.html index b5de815..082740e 100644 --- a/docs/clutchlog_8h_source.html +++ b/docs/clutchlog_8h_source.html @@ -290,14 +290,14 @@ $(function() {
281  none
282  } style;
283 
-
285  fmt() : fore(fg::none), back(bg::none), style(typo::none) { }
+
285  fmt() : fore(fg::none), back(bg::none), style(typo::none) {}
286 
-
289  fmt( fg f, bg b = bg::none, typo s = typo::none) : fore(f), back(b), style(s) { }
-
290  fmt( fg f, typo s , bg b = bg::none) : fore(f), back(b), style(s) { }
-
291  fmt( bg b, fg f = fg::none, typo s = typo::none) : fore(f), back(b), style(s) { }
-
292  fmt( bg b, typo s , fg f = fg::none) : fore(f), back(b), style(s) { }
-
293  fmt(typo s, fg f = fg::none, bg b = bg::none) : fore(f), back(b), style(s) { }
-
294  fmt(typo s, bg b , fg f = fg::none) : fore(f), back(b), style(s) { }
+
289  fmt( fg f, bg b = bg::none, typo s = typo::none) : fore(f), back(b), style(s) {}
+
290  fmt( fg f, typo s , bg b = bg::none) : fore(f), back(b), style(s) {}
+
291  fmt( bg b, fg f = fg::none, typo s = typo::none) : fore(f), back(b), style(s) {}
+
292  fmt( bg b, typo s , fg f = fg::none) : fore(f), back(b), style(s) {}
+
293  fmt(typo s, fg f = fg::none, bg b = bg::none) : fore(f), back(b), style(s) {}
+
294  fmt(typo s, bg b , fg f = fg::none) : fore(f), back(b), style(s) {}
297  protected:
299  std::ostream& print_on( std::ostream& os) const
300  {
@@ -424,455 +424,460 @@ $(function() {
473 #endif
474 
476  void threshold(level l) {_stage = l;}
-
478  level threshold() const {return _stage;}
-
479 
-
481  void file(std::string file) {_in_file = file;}
-
483  void func(std::string func) {_in_func = func;}
-
485  void line(std::string line) {_in_line = line;}
-
486 
-
488  void location(
-
489  const std::string& in_file,
-
490  const std::string& in_function=".*",
-
491  const std::string& in_line=".*"
-
492  )
-
493  {
-
494  file(in_file);
-
495  func(in_function);
-
496  line(in_line);
-
497  }
-
498 
-
503  template<class ... FMT>
-
504  void style(level stage, FMT... styles) { this->style(stage,fmt(styles...)); }
-
506  void style(level stage, fmt style) { _level_fmt.at(stage) = style; }
-
508  fmt style(level stage) const { return _level_fmt.at(stage); }
-
509 
-
514  level level_of(const std::string name)
-
515  {
-
516  const auto ilevel = _word_level.find(name);
-
517  if( ilevel != std::end(_word_level)) {
-
518  return ilevel->second;
-
519  } else {
-
520  throw std::out_of_range("'" + name + "' is not a valid log level name");
-
521  }
-
522  }
-
523 
-
526  public:
+
478  void threshold(const std::string& l) {_stage = this->level_of(l);}
+
480  level threshold() const {return _stage;}
+
482  const std::map<std::string,level>& levels() const { return _word_level;}
+
483 
+
488  level level_of(const std::string name)
+
489  {
+
490  const auto ilevel = _word_level.find(name);
+
491  if( ilevel != std::end(_word_level)) {
+
492  return ilevel->second;
+
493  } else {
+
494  throw std::out_of_range("'" + name + "' is not a valid log level name");
+
495  }
+
496  }
+
497 
+
499  void file(std::string file) {_in_file = file;}
+
501  void func(std::string func) {_in_func = func;}
+
503  void line(std::string line) {_in_line = line;}
+
504 
+
506  void location(
+
507  const std::string& in_file,
+
508  const std::string& in_function=".*",
+
509  const std::string& in_line=".*"
+
510  )
+
511  {
+
512  file(in_file);
+
513  func(in_function);
+
514  line(in_line);
+
515  }
+
516 
+
521  template<class ... FMT>
+
522  void style(level stage, FMT... styles) { this->style(stage,fmt(styles...)); }
+
524  void style(level stage, fmt style) { _level_fmt.at(stage) = style; }
+
526  fmt style(level stage) const { return _level_fmt.at(stage); }
527 
-
531  struct scope_t {
-
534  bool matches;
-
536  level stage;
-
537 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
-
538 
-
539  size_t depth;
-
540 #endif
-
541 
-
542  bool there;
-
544  scope_t() :
-
545  matches(false),
-
546  stage(level::xdebug),
-
547 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
-
548  depth(0),
-
549 #endif
-
550  there(false)
-
551  {}
-
552  }; // scope_t
-
553 
-
554 
-
556  scope_t locate(
-
557  const level& stage,
-
558  const std::string& file,
-
559  const std::string& func,
-
560  const size_t line
-
561  ) const
-
562  {
-
563  scope_t scope; // False scope by default.
-
564 
-
565  /***** Log level stage *****/
-
566  // Test stage first, because it's fastest.
-
567  scope.stage = stage;
-
568  if(not (scope.stage <= _stage)) {
-
569  // Bypass useless computations if no match
-
570  // because of the stage.
-
571  return scope;
-
572  }
-
573 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
-
574  /***** Stack depth *****/
-
575  // Backtrace in second, quite fast.
-
576  size_t stack_depth;
-
577  void *buffer[max_buffer];
-
578  stack_depth = backtrace(buffer, max_buffer);
-
579  scope.depth = stack_depth;
-
580  if(not (scope.depth <= _depth + _strip_calls)) {
-
581  // Bypass if no match.
-
582  return scope;
-
583  }
-
584 #endif
-
585 
-
586  /***** Location *****/
-
587  // Location last, slowest.
-
588  std::ostringstream sline; sline << line;
-
589  scope.there =
-
590  std::regex_search(file, _in_file)
-
591  and std::regex_search(func, _in_func)
-
592  and std::regex_search(sline.str(), _in_line);
-
593 
-
594  // No need to retest stage and depth, which are true here.
-
595  scope.matches = scope.there;
-
596 
-
597  return scope;
-
598  } // locate
-
599 
-
607  std::string replace(
-
608  const std::string& form,
-
609  const std::string& mark,
-
610  const std::string& tag
-
611  ) const
-
612  {
-
613  // Useless debug code, unless something fancy would be done with name tags.
-
614  // std::regex re;
-
615  // try {
-
616  // re = std::regex(mark);
-
617  //
-
618  // } catch(const std::regex_error& e) {
-
619  // std::cerr << "ERROR with a regular expression \"" << mark << "\": ";
-
620  // switch(e.code()) {
-
621  // case std::regex_constants::error_collate:
-
622  // std::cerr << "the expression contains an invalid collating element name";
-
623  // break;
-
624  // case std::regex_constants::error_ctype:
-
625  // std::cerr << "the expression contains an invalid character class name";
-
626  // break;
-
627  // case std::regex_constants::error_escape:
-
628  // std::cerr << "the expression contains an invalid escaped character or a trailing escape";
-
629  // break;
-
630  // case std::regex_constants::error_backref:
-
631  // std::cerr << "the expression contains an invalid back reference";
-
632  // break;
-
633  // case std::regex_constants::error_brack:
-
634  // std::cerr << "the expression contains mismatched square brackets ('[' and ']')";
-
635  // break;
-
636  // case std::regex_constants::error_paren:
-
637  // std::cerr << "the expression contains mismatched parentheses ('(' and ')')";
-
638  // break;
-
639  // case std::regex_constants::error_brace:
-
640  // std::cerr << "the expression contains mismatched curly braces ('{' and '}')";
-
641  // break;
-
642  // case std::regex_constants::error_badbrace:
-
643  // std::cerr << "the expression contains an invalid range in a {} expression";
-
644  // break;
-
645  // case std::regex_constants::error_range:
-
646  // std::cerr << "the expression contains an invalid character range (e.g. [b-a])";
-
647  // break;
-
648  // case std::regex_constants::error_space:
-
649  // std::cerr << "there was not enough memory to convert the expression into a finite state machine";
-
650  // break;
-
651  // case std::regex_constants::error_badrepeat:
-
652  // std::cerr << "one of *?+{ was not preceded by a valid regular expression";
-
653  // break;
-
654  // case std::regex_constants::error_complexity:
-
655  // std::cerr << "the complexity of an attempted match exceeded a predefined level";
-
656  // break;
-
657  // case std::regex_constants::error_stack:
-
658  // std::cerr << "there was not enough memory to perform a match";
-
659  // break;
-
660  // default:
-
661  // std::cerr << "unknown error";
-
662  // }
-
663  // std::cerr << std::endl;
-
664  // throw;
-
665  // } // catch
-
666 
-
667  const std::regex re(mark);
-
668  return std::regex_replace(form, re, tag);
-
669  }
+
530  public:
+
531 
+
535  struct scope_t {
+
538  bool matches;
+
540  level stage;
+
541 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
+
542 
+
543  size_t depth;
+
544 #endif
+
545 
+
546  bool there;
+
548  scope_t() :
+
549  matches(false),
+
550  stage(level::xdebug),
+
551 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
+
552  depth(0),
+
553 #endif
+
554  there(false)
+
555  {}
+
556  }; // scope_t
+
557 
+
558 
+
560  scope_t locate(
+
561  const level& stage,
+
562  const std::string& file,
+
563  const std::string& func,
+
564  const size_t line
+
565  ) const
+
566  {
+
567  scope_t scope; // False scope by default.
+
568 
+
569  /***** Log level stage *****/
+
570  // Test stage first, because it's fastest.
+
571  scope.stage = stage;
+
572  if(not (scope.stage <= _stage)) {
+
573  // Bypass useless computations if no match
+
574  // because of the stage.
+
575  return scope;
+
576  }
+
577 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
+
578  /***** Stack depth *****/
+
579  // Backtrace in second, quite fast.
+
580  size_t stack_depth;
+
581  void *buffer[max_buffer];
+
582  stack_depth = backtrace(buffer, max_buffer);
+
583  scope.depth = stack_depth;
+
584  if(not (scope.depth <= _depth + _strip_calls)) {
+
585  // Bypass if no match.
+
586  return scope;
+
587  }
+
588 #endif
+
589 
+
590  /***** Location *****/
+
591  // Location last, slowest.
+
592  std::ostringstream sline; sline << line;
+
593  scope.there =
+
594  std::regex_search(file, _in_file)
+
595  and std::regex_search(func, _in_func)
+
596  and std::regex_search(sline.str(), _in_line);
+
597 
+
598  // No need to retest stage and depth, which are true here.
+
599  scope.matches = scope.there;
+
600 
+
601  return scope;
+
602  } // locate
+
603 
+
611  std::string replace(
+
612  const std::string& form,
+
613  const std::string& mark,
+
614  const std::string& tag
+
615  ) const
+
616  {
+
617  // Useless debug code, unless something fancy would be done with name tags.
+
618  // std::regex re;
+
619  // try {
+
620  // re = std::regex(mark);
+
621  //
+
622  // } catch(const std::regex_error& e) {
+
623  // std::cerr << "ERROR with a regular expression \"" << mark << "\": ";
+
624  // switch(e.code()) {
+
625  // case std::regex_constants::error_collate:
+
626  // std::cerr << "the expression contains an invalid collating element name";
+
627  // break;
+
628  // case std::regex_constants::error_ctype:
+
629  // std::cerr << "the expression contains an invalid character class name";
+
630  // break;
+
631  // case std::regex_constants::error_escape:
+
632  // std::cerr << "the expression contains an invalid escaped character or a trailing escape";
+
633  // break;
+
634  // case std::regex_constants::error_backref:
+
635  // std::cerr << "the expression contains an invalid back reference";
+
636  // break;
+
637  // case std::regex_constants::error_brack:
+
638  // std::cerr << "the expression contains mismatched square brackets ('[' and ']')";
+
639  // break;
+
640  // case std::regex_constants::error_paren:
+
641  // std::cerr << "the expression contains mismatched parentheses ('(' and ')')";
+
642  // break;
+
643  // case std::regex_constants::error_brace:
+
644  // std::cerr << "the expression contains mismatched curly braces ('{' and '}')";
+
645  // break;
+
646  // case std::regex_constants::error_badbrace:
+
647  // std::cerr << "the expression contains an invalid range in a {} expression";
+
648  // break;
+
649  // case std::regex_constants::error_range:
+
650  // std::cerr << "the expression contains an invalid character range (e.g. [b-a])";
+
651  // break;
+
652  // case std::regex_constants::error_space:
+
653  // std::cerr << "there was not enough memory to convert the expression into a finite state machine";
+
654  // break;
+
655  // case std::regex_constants::error_badrepeat:
+
656  // std::cerr << "one of *?+{ was not preceded by a valid regular expression";
+
657  // break;
+
658  // case std::regex_constants::error_complexity:
+
659  // std::cerr << "the complexity of an attempted match exceeded a predefined level";
+
660  // break;
+
661  // case std::regex_constants::error_stack:
+
662  // std::cerr << "there was not enough memory to perform a match";
+
663  // break;
+
664  // default:
+
665  // std::cerr << "unknown error";
+
666  // }
+
667  // std::cerr << std::endl;
+
668  // throw;
+
669  // } // catch
670 
-
672  std::string replace(
-
673  const std::string& form,
-
674  const std::string& mark,
-
675  const size_t tag
-
676  ) const
-
677  {
-
678  std::ostringstream stag; stag << tag;
-
679  return replace(form, mark, stag.str());
-
680  }
-
681 
-
683  std::string format(
-
684  std::string format,
-
685  const std::string& what,
-
686 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
-
687  const std::string& name,
-
688 #endif
-
689  const level& stage,
-
690  const std::string& file,
-
691  const std::string& func,
-
692  const size_t line
-
693 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
-
694  ,
-
695  const size_t depth
-
696 #endif
-
697  ) const
-
698  {
-
699  format = replace(format, "\\{msg\\}", what);
-
700  format = replace(format, "\\{file\\}", file);
-
701  format = replace(format, "\\{func\\}", func);
-
702  format = replace(format, "\\{line\\}", line);
-
703 
-
704  format = replace(format, "\\{level\\}", _level_word.at(stage));
-
705  std::string letter(1, _level_word.at(stage).at(0)); // char -> string
-
706  format = replace(format, "\\{level_letter\\}", letter);
+
671  const std::regex re(mark);
+
672  return std::regex_replace(form, re, tag);
+
673  }
+
674 
+
676  std::string replace(
+
677  const std::string& form,
+
678  const std::string& mark,
+
679  const size_t tag
+
680  ) const
+
681  {
+
682  std::ostringstream stag; stag << tag;
+
683  return replace(form, mark, stag.str());
+
684  }
+
685 
+
687  std::string format(
+
688  std::string format,
+
689  const std::string& what,
+
690 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
+
691  const std::string& name,
+
692 #endif
+
693  const level& stage,
+
694  const std::string& file,
+
695  const std::string& func,
+
696  const size_t line
+
697 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
+
698  ,
+
699  const size_t depth
+
700 #endif
+
701  ) const
+
702  {
+
703  format = replace(format, "\\{msg\\}", what);
+
704  format = replace(format, "\\{file\\}", file);
+
705  format = replace(format, "\\{func\\}", func);
+
706  format = replace(format, "\\{line\\}", line);
707 
-
708 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
-
709  format = replace(format, "\\{name\\}", name);
-
710  format = replace(format, "\\{depth\\}", depth - _strip_calls);
+
708  format = replace(format, "\\{level\\}", _level_word.at(stage));
+
709  std::string letter(1, _level_word.at(stage).at(0)); // char -> string
+
710  format = replace(format, "\\{level_letter\\}", letter);
711 
-
712  std::ostringstream chevrons;
-
713  for(size_t i = _strip_calls; i < depth; ++i) {
-
714  chevrons << _depth_mark;
-
715  }
-
716  format = replace(format, "\\{depth_marks\\}", chevrons.str());
-
717 #endif
-
718 
-
719  return _level_fmt.at(stage)(format);
-
720  }
-
721 
-
723  void log(
-
724  const level& stage,
-
725  const std::string& what,
-
726  const std::string& file, const std::string& func, size_t line
-
727  ) const
-
728  {
-
729  scope_t scope = locate(stage, file, func, line);
-
730 
-
731  if(scope.matches) {
-
732 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
-
733  *_out << format(_format_log, what, basename(getenv("_")),
-
734  stage, file, func,
-
735  line, scope.depth );
-
736 #else
-
737  *_out << format(_format_log, what,
+
712 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
+
713  format = replace(format, "\\{name\\}", name);
+
714  format = replace(format, "\\{depth\\}", depth - _strip_calls);
+
715 
+
716  std::ostringstream chevrons;
+
717  for(size_t i = _strip_calls; i < depth; ++i) {
+
718  chevrons << _depth_mark;
+
719  }
+
720  format = replace(format, "\\{depth_marks\\}", chevrons.str());
+
721 #endif
+
722 
+
723  return _level_fmt.at(stage)(format);
+
724  }
+
725 
+
727  void log(
+
728  const level& stage,
+
729  const std::string& what,
+
730  const std::string& file, const std::string& func, size_t line
+
731  ) const
+
732  {
+
733  scope_t scope = locate(stage, file, func, line);
+
734 
+
735  if(scope.matches) {
+
736 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
+
737  *_out << format(_format_log, what, basename(getenv("_")),
738  stage, file, func,
-
739  line );
-
740 
-
741 #endif
-
742  _out->flush();
-
743  } // if scopes.matches
-
744  }
-
745 
-
747  template<class In>
-
748  void dump(
-
749  const level& stage,
-
750  const In container_begin, const In container_end,
-
751  const std::string& file, const std::string& func, size_t line,
-
752  const std::string& filename_template = "dump_{n}.dat",
-
753  const std::string sep = dump_default_sep
-
754  ) const
-
755  {
-
756  scope_t scope = locate(stage, file, func, line);
-
757 
-
758  if(scope.matches) {
-
759  const std::string tag = "\\{n\\}";
-
760  const std::regex re(tag);
-
761  std::string outfile = "";
-
762 
-
763  // If the file name template has the {n} tag.
-
764  if(std::regex_search(filename_template, re)) {
-
765  // Increment n until a free one is found.
-
766  size_t n = 0;
-
767  do {
-
768  outfile = replace(filename_template, tag, n);
-
769  n++;
-
770  } while( fs::exists( outfile ) );
-
771 
-
772  } else {
-
773  // Use the parameter as is.
-
774  outfile = filename_template;
-
775  }
-
776 
-
777  std::ofstream fd(outfile);
-
778 
-
779  if(_format_dump.size() > 0) {
-
780 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
-
781  fd << format(_format_dump, "", basename(getenv("_")),
-
782  stage, file, func,
-
783  line, scope.depth );
-
784 #else
-
785  fd << format(_format_dump, "",
+
739  line, scope.depth );
+
740 #else
+
741  *_out << format(_format_log, what,
+
742  stage, file, func,
+
743  line );
+
744 
+
745 #endif
+
746  _out->flush();
+
747  } // if scopes.matches
+
748  }
+
749 
+
751  template<class In>
+
752  void dump(
+
753  const level& stage,
+
754  const In container_begin, const In container_end,
+
755  const std::string& file, const std::string& func, size_t line,
+
756  const std::string& filename_template = "dump_{n}.dat",
+
757  const std::string sep = dump_default_sep
+
758  ) const
+
759  {
+
760  scope_t scope = locate(stage, file, func, line);
+
761 
+
762  if(scope.matches) {
+
763  const std::string tag = "\\{n\\}";
+
764  const std::regex re(tag);
+
765  std::string outfile = "";
+
766 
+
767  // If the file name template has the {n} tag.
+
768  if(std::regex_search(filename_template, re)) {
+
769  // Increment n until a free one is found.
+
770  size_t n = 0;
+
771  do {
+
772  outfile = replace(filename_template, tag, n);
+
773  n++;
+
774  } while( fs::exists( outfile ) );
+
775 
+
776  } else {
+
777  // Use the parameter as is.
+
778  outfile = filename_template;
+
779  }
+
780 
+
781  std::ofstream fd(outfile);
+
782 
+
783  if(_format_dump.size() > 0) {
+
784 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
+
785  fd << format(_format_dump, "", basename(getenv("_")),
786  stage, file, func,
-
787  line );
-
788 #endif
-
789  fd << sep; // sep after comment line.
-
790  }
-
791 
-
792  std::copy(container_begin, container_end,
-
793  std::ostream_iterator<typename In::value_type>(fd, sep.c_str()));
-
794 
-
795  fd.close();
-
796  } // if scopes.matches
-
797  }
+
787  line, scope.depth );
+
788 #else
+
789  fd << format(_format_dump, "",
+
790  stage, file, func,
+
791  line );
+
792 #endif
+
793  fd << sep; // sep after comment line.
+
794  }
+
795 
+
796  std::copy(container_begin, container_end,
+
797  std::ostream_iterator<typename In::value_type>(fd, sep.c_str()));
798 
-
800 };
-
801 
-
804 #else // not WITH_CLUTCHLOG
+
799  fd.close();
+
800  } // if scopes.matches
+
801  }
+
802 
+
804 };
805 
-
806 
-
807 /**********************************************************************
-
808  * Fake implementation
-
809  **********************************************************************/
+
808 #else // not WITH_CLUTCHLOG
+
809 
810 
-
811 // Equivalent class with empty methods, will be optimized out
-
812 // while allowing to actually have calls implemented without WITH_CLUTCHLOG guards.
-
813 #pragma GCC diagnostic push
-
814 #pragma GCC diagnostic ignored "-Wreturn-type"
-
815 class clutchlog
-
816 {
-
817  public:
-
818  static clutchlog& logger() { }
-
819  enum level {critical=0, error=1, warning=2, progress=3, note=4, info=5, debug=6, xdebug=7};
-
820  class fmt {
-
821  public:
-
822  enum class fg { black, red, green, yellow, blue, magenta, cyan, white, none } fore;
-
823  enum class bg { black, red, green, yellow, blue, magenta, cyan, white, none } back;
-
824  enum class typo { reset, bold, underline, inverse, none } style;
-
825  fmt() : fore(fg::none), back(bg::none), style(typo::none) { }
-
826  fmt( fg f, bg b = bg::none, typo s = typo::none) : fore(f), back(b), style(s) { }
-
827  fmt( fg f, typo s , bg b = bg::none) : fore(f), back(b), style(s) { }
-
828  fmt( bg b, fg f = fg::none, typo s = typo::none) : fore(f), back(b), style(s) { }
-
829  fmt( bg b, typo s , fg f = fg::none) : fore(f), back(b), style(s) { }
-
830  fmt(typo s, fg f = fg::none, bg b = bg::none) : fore(f), back(b), style(s) { }
-
831  fmt(typo s, bg b , fg f = fg::none) : fore(f), back(b), style(s) { }
-
832  protected:
-
833  std::ostream& print_on(std::ostream&) const { }
-
834  public:
-
835  friend std::ostream& operator<<(std::ostream&, const fmt&) { }
-
836  std::string operator()(const std::string&) const { }
-
837  };
-
838  public:
-
839  clutchlog(clutchlog const&) = delete;
-
840  void operator=(clutchlog const&) = delete;
-
841  private:
-
842  clutchlog() {}
-
843  protected:
-
844  struct scope_t {};
-
845  scope_t locate(
-
846  const level&,
-
847  const std::string&,
-
848  const std::string&,
-
849  const size_t
-
850  ) const
-
851  { }
-
852  public:
-
853  void format(const std::string&) {}
-
854  std::string format() const {}
-
855 
-
856  void format_comment(const std::string&) {}
-
857  std::string format_comment() const {}
-
858 
-
859  void out(std::ostream&) {}
-
860  std::ostream& out() {}
-
861 
-
862 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
-
863  void depth(size_t) {}
-
864  size_t depth() const {}
+
811 /**********************************************************************
+
812  * Fake implementation
+
813  **********************************************************************/
+
814 
+
815 // Equivalent class with empty methods, will be optimized out
+
816 // while allowing to actually have calls implemented without WITH_CLUTCHLOG guards.
+
817 #pragma GCC diagnostic push
+
818 #pragma GCC diagnostic ignored "-Wreturn-type"
+
819 class clutchlog
+
820 {
+
821  public:
+
822  static clutchlog& logger() {}
+
823  enum level {critical=0, error=1, warning=2, progress=3, note=4, info=5, debug=6, xdebug=7};
+
824  class fmt {
+
825  public:
+
826  enum class fg { black, red, green, yellow, blue, magenta, cyan, white, none } fore;
+
827  enum class bg { black, red, green, yellow, blue, magenta, cyan, white, none } back;
+
828  enum class typo { reset, bold, underline, inverse, none } style;
+
829  fmt() : fore(fg::none), back(bg::none), style(typo::none) {}
+
830  fmt( fg f, bg b = bg::none, typo s = typo::none) : fore(f), back(b), style(s) {}
+
831  fmt( fg f, typo s , bg b = bg::none) : fore(f), back(b), style(s) {}
+
832  fmt( bg b, fg f = fg::none, typo s = typo::none) : fore(f), back(b), style(s) {}
+
833  fmt( bg b, typo s , fg f = fg::none) : fore(f), back(b), style(s) {}
+
834  fmt(typo s, fg f = fg::none, bg b = bg::none) : fore(f), back(b), style(s) {}
+
835  fmt(typo s, bg b , fg f = fg::none) : fore(f), back(b), style(s) {}
+
836  protected:
+
837  std::ostream& print_on(std::ostream&) const {}
+
838  public:
+
839  friend std::ostream& operator<<(std::ostream&, const fmt&) {}
+
840  std::string operator()(const std::string&) const {}
+
841  };
+
842  public:
+
843  clutchlog(clutchlog const&) = delete;
+
844  void operator=(clutchlog const&) = delete;
+
845  private:
+
846  clutchlog() {}
+
847  protected:
+
848  struct scope_t {};
+
849  scope_t locate(
+
850  const level&,
+
851  const std::string&,
+
852  const std::string&,
+
853  const size_t
+
854  ) const
+
855  {}
+
856  public:
+
857  void format(const std::string&) {}
+
858  std::string format() const {}
+
859 
+
860  void format_comment(const std::string&) {}
+
861  std::string format_comment() const {}
+
862 
+
863  void out(std::ostream&) {}
+
864  std::ostream& out() {}
865 
-
866  void depth_mark(std::string) {}
-
867  std::string depth_mark() const {}
-
868 #endif
+
866 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
+
867  void depth(size_t) {}
+
868  size_t depth() const {}
869 
-
870  void threshold(level) {}
-
871  level threshold() const {}
-
872 
-
873  void file(std::string) {}
-
874  void func(std::string) {}
-
875  void line(std::string) {}
-
876 
-
877 #pragma GCC diagnostic push
-
878 #pragma GCC diagnostic ignored "-Wunused-parameter"
-
879  void location(
-
880  const std::string&,
-
881  const std::string& in_function=".*",
-
882  const std::string& in_line=".*"
-
883  )
-
884  { }
-
885 #pragma GCC diagnostic pop
-
886  void style(level, fmt) { }
-
887  fmt style(level) const { }
-
888  level level_of(const std::string) { }
-
889  public:
-
890  std::string replace(
-
891  const std::string&,
-
892  const std::string&,
-
893  const std::string&
-
894  ) const
-
895  { }
-
896 
-
897  std::string replace(
+
870  void depth_mark(std::string) {}
+
871  std::string depth_mark() const {}
+
872 #endif
+
873 
+
874  void threshold(level) {}
+
875  void threshold(const std::string&) {}
+
876  level threshold() const {}
+
877  const std::map<std::string,level> levels() const {};
+
878  level level_of(const std::string) {}
+
879 
+
880  void file(std::string) {}
+
881  void func(std::string) {}
+
882  void line(std::string) {}
+
883 
+
884 #pragma GCC diagnostic push
+
885 #pragma GCC diagnostic ignored "-Wunused-parameter"
+
886  void location(
+
887  const std::string&,
+
888  const std::string& in_function=".*",
+
889  const std::string& in_line=".*"
+
890  )
+
891  {}
+
892 #pragma GCC diagnostic pop
+
893  void style(level, fmt) {}
+
894  fmt style(level) const {}
+
895  public:
+
896  std::string replace(
+
897  const std::string&,
898  const std::string&,
-
899  const std::string&,
-
900  const size_t
-
901  ) const
-
902  { }
-
903 
-
904  std::string format(
-
905  std::string,
-
906  const std::string&,
-
907 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
-
908  const std::string&,
-
909 #endif
-
910  const level&,
-
911  const std::string&,
+
899  const std::string&
+
900  ) const
+
901  {}
+
902 
+
903  std::string replace(
+
904  const std::string&,
+
905  const std::string&,
+
906  const size_t
+
907  ) const
+
908  {}
+
909 
+
910  std::string format(
+
911  std::string,
912  const std::string&,
-
913  const size_t
-
914 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
-
915  ,
-
916  const size_t
-
917 #endif
-
918  ) const
-
919  { }
-
920 
-
921  void log(
-
922  const level&,
-
923  const std::string&,
-
924  const std::string&, const std::string&, size_t
-
925  ) const
-
926  { }
-
927 
-
928  template<class In>
-
929  void dump(
-
930  const level&,
-
931  const In, const In,
-
932  const std::string&, const std::string&, size_t,
-
933  const std::string&,
-
934  const std::string
-
935  ) const
-
936  { }
-
937 };
-
938 #pragma GCC diagnostic pop
-
939 #endif // WITH_CLUTCHLOG
-
940 
-
941 #endif // __CLUTCHLOG_H__
+
913 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
+
914  const std::string&,
+
915 #endif
+
916  const level&,
+
917  const std::string&,
+
918  const std::string&,
+
919  const size_t
+
920 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
+
921  ,
+
922  const size_t
+
923 #endif
+
924  ) const
+
925  {}
+
926 
+
927  void log(
+
928  const level&,
+
929  const std::string&,
+
930  const std::string&, const std::string&, size_t
+
931  ) const
+
932  {}
+
933 
+
934  template<class In>
+
935  void dump(
+
936  const level&,
+
937  const In, const In,
+
938  const std::string&, const std::string&, size_t,
+
939  const std::string&,
+
940  const std::string
+
941  ) const
+
942  {}
+
943 };
+
944 #pragma GCC diagnostic pop
+
945 #endif // WITH_CLUTCHLOG
+
946 
+
947 #endif // __CLUTCHLOG_H__
-
void file(std::string file)
Set the regular expression filtering the file location.
Definition: clutchlog.h:481
+
void file(std::string file)
Set the regular expression filtering the file location.
Definition: clutchlog.h:499
#define CLUTCHDUMP_DEFAULT_FORMAT
Compile-time default format of the comment line in file dump.
Definition: clutchlog.h:187
fg
Foreground color codes.
Definition: clutchlog.h:250
static std::string dump_default_format
Default format of the comment line in file dump.
Definition: clutchlog.h:191
+
const std::map< std::string, level > & levels() const
Get the map of available log levels string representations toward their identifier....
Definition: clutchlog.h:482
void out(std::ostream &out)
Set the output stream on which to print.
Definition: clutchlog.h:459
fmt()
&#160;Empty constructor, only useful for a no-op formatter.
Definition: clutchlog.h:285
static clutchlog & logger()
Get the logger instance.
Definition: clutchlog.h:226
-
void line(std::string line)
Set the regular expression filtering the line location.
Definition: clutchlog.h:485
+
void line(std::string line)
Set the regular expression filtering the line location.
Definition: clutchlog.h:503
void format_comment(const std::string &format)
Set the template string for dumps.
Definition: clutchlog.h:454
typo
Typographic style codes.
Definition: clutchlog.h:276
#define CLUTCHDUMP_DEFAULT_SEP
Compile-time default item separator for dump.
Definition: clutchlog.h:195
static std::string default_depth_mark
Default mark for stack depth.
Definition: clutchlog.h:205
#define CLUTCHLOG_DEFAULT_FORMAT
Compile-time default format of the messages.
Definition: clutchlog.h:176
std::string format() const
Get the template string.
Definition: clutchlog.h:451
-
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:723
-
level level_of(const std::string name)
Return the log level tag corresponding to the given pre-configured name.
Definition: clutchlog.h:514
+
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:727
+
level level_of(const std::string name)
Return the log level tag corresponding to the given pre-configured name.
Definition: clutchlog.h:488
std::string _format_dump
Current format of the file output.
Definition: clutchlog.h:419
std::string operator()(const std::string &msg) const
Format the given string with the currently encoded format.
Definition: clutchlog.h:344
-
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 corre...
Definition: clutchlog.h:683
+
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 corre...
Definition: clutchlog.h:687
std::string _format_log
Current format of the standard output.
Definition: clutchlog.h:417
level
Available log levels.
Definition: clutchlog.h:233
-
level stage
Current log level.
Definition: clutchlog.h:536
+
level stage
Current log level.
Definition: clutchlog.h:540
#define CLUTCHLOG_DEFAULT_DEPTH_MARK
Compile-time default mark for stack depth.
Definition: clutchlog.h:202
friend std::ostream & operator<<(std::ostream &os, const fmt &fmt)
Output stream overload.
Definition: clutchlog.h:329
std::map< level, fmt > _level_fmt
Dictionary of level identifier to their format.
Definition: clutchlog.h:415
@@ -883,34 +888,35 @@ $(function() {
std::string format_comment() const
Get the template string for dumps.
Definition: clutchlog.h:456
#define CLUTCHLOG_STRIP_CALLS
Compile-time number of call stack levels to remove from depth display by default.
Definition: clutchlog.h:209
std::ostream * _out
Standard output.
Definition: clutchlog.h:421
-
void func(std::string func)
Set the regular expression filtering the function location.
Definition: clutchlog.h:483
-
void location(const std::string &in_file, const std::string &in_function=".*", const std::string &in_line=".*")
Set the regular expressions filtering the location.
Definition: clutchlog.h:488
-
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.
Definition: clutchlog.h:748
-
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.
Definition: clutchlog.h:672
+
void func(std::string func)
Set the regular expression filtering the function location.
Definition: clutchlog.h:501
+
void location(const std::string &in_file, const std::string &in_function=".*", const std::string &in_line=".*")
Set the regular expressions filtering the location.
Definition: clutchlog.h:506
+
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.
Definition: clutchlog.h:752
+
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.
Definition: clutchlog.h:676
Color and style formatter for ANSI terminal escape sequences.
Definition: clutchlog.h:247
std::regex _in_file
Current file location filter.
Definition: clutchlog.h:431
std::ostream & out()
Get the output stream on which to print.
Definition: clutchlog.h:461
-
std::string replace(const std::string &form, const std::string &mark, const std::string &tag) const
Replace mark by tag in form.
Definition: clutchlog.h:607
+
std::string replace(const std::string &form, const std::string &mark, const std::string &tag) const
Replace mark by tag in form.
Definition: clutchlog.h:611
static unsigned int default_strip_calls
Number of call stack levels to remove from depth display by default.
Definition: clutchlog.h:212
static std::string default_format
Default format of the messages.
Definition: clutchlog.h:180
enum clutchlog::fmt::fg fore
Foreground color.
-
bool there
Location is compatible.
Definition: clutchlog.h:542
-
Structure holding a location matching.
Definition: clutchlog.h:532
+
void threshold(const std::string &l)
Set the log level (below which logs are not printed) with a string.
Definition: clutchlog.h:478
+
bool there
Location is compatible.
Definition: clutchlog.h:546
+
Structure holding a location matching.
Definition: clutchlog.h:536
std::regex _in_func
Current function location filter.
Definition: clutchlog.h:433
-
void threshold(level l)
Set the log level below which logs are not printed.
Definition: clutchlog.h:476
-
void style(level stage, fmt style)
Set the style (color and typo) of the given log level, passing a fmt instance.
Definition: clutchlog.h:506
+
void threshold(level l)
Set the log level (below which logs are not printed) with an identifier.
Definition: clutchlog.h:476
+
void style(level stage, fmt style)
Set the style (color and typo) of the given log level, passing a fmt instance.
Definition: clutchlog.h:524
const std::map< level, std::string > _level_word
Dictionary of level identifier to their string representation.
Definition: clutchlog.h:411
-
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.
Definition: clutchlog.h:556
-
bool matches
Everything is compatible.
Definition: clutchlog.h:534
+
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.
Definition: clutchlog.h:560
+
bool matches
Everything is compatible.
Definition: clutchlog.h:538
static std::string dump_default_sep
Default item separator for dump.
Definition: clutchlog.h:198
-
level threshold() const
Get the log level below which logs are not printed.
Definition: clutchlog.h:478
+
level threshold() const
Get the log level below which logs are not printed.
Definition: clutchlog.h:480
std::ostream & print_on(std::ostream &os) const
Print the currently encoded format escape code on the given output stream.
Definition: clutchlog.h:299
std::map< std::string, level > _word_level
Dictionary of level string to their identifier.
Definition: clutchlog.h:413
-
void style(level stage, FMT... styles)
Set the style (color and typo) of the given log level.
Definition: clutchlog.h:504
-
scope_t()
Constructor.
Definition: clutchlog.h:544
+
void style(level stage, FMT... styles)
Set the style (color and typo) of the given log level.
Definition: clutchlog.h:522
+
scope_t()
Constructor.
Definition: clutchlog.h:548
#define CLUTCHLOG_HAVE_UNIX_SYSINFO
POSIX headers necessary for stack depth management are available.
Definition: clutchlog.h:32
Definition: clutchlog.h:165
-
fmt style(level stage) const
Get the configured fmt instance of the given log level.
Definition: clutchlog.h:508
+
fmt style(level stage) const
Get the configured fmt instance of the given log level.
Definition: clutchlog.h:526
bg
Background color codes.
Definition: clutchlog.h:263
enum clutchlog::fmt::bg back
Background color.
diff --git a/docs/functions.html b/docs/functions.html index 96724b1..02e0d5d 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -165,6 +165,9 @@ $(function() {
  • level_of() : clutchlog
  • +
  • levels() +: clutchlog +
  • line() : clutchlog
  • diff --git a/docs/functions_func.html b/docs/functions_func.html index 553b42d..ec981ba 100644 --- a/docs/functions_func.html +++ b/docs/functions_func.html @@ -84,6 +84,9 @@ $(function() {
  • level_of() : clutchlog
  • +
  • levels() +: clutchlog +
  • line() : clutchlog
  • diff --git a/docs/group__UseMacros.html b/docs/group__UseMacros.html index e8788ff..89ba5f5 100644 --- a/docs/group__UseMacros.html +++ b/docs/group__UseMacros.html @@ -353,12 +353,23 @@ std::ostream &   void clutchlog::threshold (level l) - Set the log level below which logs are not printed.
    + Set the log level (below which logs are not printed) with an identifier.
      + +void clutchlog::threshold (const std::string &l) + Set the log level (below which logs are not printed) with a string.
    level clutchlog::threshold () const  Get the log level below which logs are not printed.
      + +const std::map< std::string, level > & clutchlog::levels () const + Get the map of available log levels string representations toward their identifier. *‍/.
    +  +level clutchlog::level_of (const std::string name) + Return the log level tag corresponding to the given pre-configured name. More...
    void clutchlog::file (std::string file)  Set the regular expression filtering the file location.
    @@ -387,9 +398,6 @@ void fmt clutchlog::style (level stage) const  Get the configured fmt instance of the given log level.
      -level clutchlog::level_of (const std::string name) - Return the log level tag corresponding to the given pre-configured name. More...
    -  @@ -819,7 +827,7 @@ template<class ... FMT>
    static clutchlog & logger()
    Get the logger instance.
    Definition: clutchlog.h:226
    #define CLUTCHDUMP_DEFAULT_SEP
    Compile-time default item separator for dump.
    Definition: clutchlog.h:195
    -
    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:723
    +
    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:727
    #define CLUTCHLOC
    Handy shortcuts to location.
    Definition: clutchlog.h:65
    Color and style formatter for ANSI terminal escape sequences.
    Definition: clutchlog.h:247
    diff --git a/docs/index.html b/docs/index.html index 222c5d4..a2c4991 100644 --- a/docs/index.html +++ b/docs/index.html @@ -70,17 +70,17 @@ $(function() {

    Low-level API