52#if __cplusplus < 201703L
53#ifndef DRAIN_NULLPTR_STREAM_COMPAT
54#define DRAIN_NULLPTR_STREAM_COMPAT
55inline std::ostream &
operator<<(std::ostream & os, std::nullptr_t) {
56 return os << static_cast<const void *>(
nullptr);
61#include "StringBuilder.h"
63#include "TextStyleVT100.h"
115 template <
typename ... T>
116 Notification(
const std::string & key,
const T &... args){
121 std::stringstream sstr;
123 vt100.append(sstr, args...);
124 vt100color = sstr.str();
132 std::string vt100color;
167 typedef std::map<int,std::string> status_dict_t;
170 static status_dict_t statusDict;
180 Log(std::ostream & ostr=std::cerr,
int verbosityLevel=LOG_WARNING) : ostrPtr(&ostr), verbosityLevel(verbosityLevel)
187 Log(
const Log &m) : ostrPtr(m.ostrPtr), verbosityLevel(m.verbosityLevel) {
203 void setOstr(std::ostream & ostr){
214 void setOstr(
const std::string & filename){
221 ofstr.open(filename, std::ios::out);
227 if (ofstr.is_open()){
235 void setVerbosity(
level_t level){
236 verbosityLevel = level;
239 void setVerbosity(
const std::string & level);
242 int getVerbosity()
const {
243 return verbosityLevel;
246 void flush(
level_t level,
const std::string & prefix,
const std::stringstream & sstr);
249 void flush(
level_t level,
const Notification & notif,
const std::string & prefix,
const std::stringstream & sstr);
253 long getRelativeMilliseconds(){
254 return getMilliseconds() - millisecondsStart;
258 long getMilliseconds(){
260 gettimeofday(&time, NULL);
261 return (time.tv_sec * 1000) + (time.tv_usec / 1000);
266 millisecondsStart = getMilliseconds();
277 std::ostream *ostrPtr = & std::cerr;
281 level_t verbosityLevel = LOG_NOTICE;
283 long millisecondsStart = 0;
308 template<
typename T,
typename ... TT>
317#define DRAIN_LOG(name) ' ', #name, '=', name
328 std::stringstream & message;
339 template <
typename ... TT>
340 Logger(
const char *filename,
const TT & ...args);
346 template <
typename ... TT>
347 Logger(
Log &log,
const char *filename,
const TT & ...args);
359 return (monitor.getVerbosity() >= l);
376 template <
int L,
typename ... TT>
379 static const Notification notif(__FUNCTION__, TextStyle::DIM);
380 initMessage<L>(notif);
387 template<
typename ... TT>
390 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::REVERSE, TextStyle::BOLD);
391 initMessage<LOG_EMERG>(notif);
397 template<
typename ... TT>
400 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::BOLD);
401 initMessage<LOG_ALERT>(notif);
407 template<
typename ... TT>
410 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE);
411 initMessage<LOG_CRIT>(notif);
424 template<
typename ... TT>
427 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::BOLD);
429 initMessage<LOG_ERR>(notif);
438 template<
typename ... TT>
442 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::BOLD);
443 initMessage<LOG_WARNING>(notif);
449 template<
int L=LOG_WARNING,
typename ... TT>
453 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
454 initMessage<L>(notif);
461 template<
int L=LOG_WARNING,
typename ... TT>
465 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
466 initMessage<L>(notif);
473 template<
int L=LOG_WARNING,
typename ... TT>
477 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::DIM, TextStyle::UNDERLINE);
478 initMessage<L>(notif);
484 template<
int L=LOG_WARNING,
typename ... TT>
487 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE);
488 initMessage<L>(notif);
497 template<
typename ... TT>
500 static const Notification notif(__FUNCTION__, TextStyle::BOLD);
501 initMessage<LOG_NOTICE>(notif);
508 template<
int L=LOG_NOTICE,
typename ... TT>
511 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
512 initMessage<L>(notif);
519 template<
int L=LOG_NOTICE,
typename ... TT>
522 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::BOLD);
523 initMessage<L>(notif);
529 template<
int L=LOG_NOTICE,
typename ... TT>
532 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM, TextStyle::UNDERLINE);
533 initMessage<L>(notif);
539 template<
int L=LOG_NOTICE,
typename ... TT>
542 static const Notification notif(__FUNCTION__, TextStyle::CYAN);
543 initMessage<L>(notif);
549 template<
int L=LOG_NOTICE,
typename ... TT>
551 Logger & experimental(
const TT &... args){
552 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE, TextStyle::DIM);
553 initMessage<L>(notif);
558 template<
int L=LOG_NOTICE,
typename ... TT>
560 Logger & advice(
const TT &... args){
561 static const Notification notif(__FUNCTION__, TextStyle::Colour::PURPLE);
562 initMessage<L>(notif);
570 template<
typename ... TT>
572 Logger & info(
const TT &... args){
573 static const Notification notif(__FUNCTION__, TextStyle::WHITE);
574 initMessage<LOG_INFO>(notif);
580 template<
int L=LOG_INFO,
typename ... TT>
582 Logger & ok(
const TT &... args){
583 static const Notification notif(__FUNCTION__, TextStyle::GREEN);
584 initMessage<L>(notif);
590 template<
int L=LOG_INFO,
typename ... TT>
594 static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::REVERSE, TextStyle::DIM);
595 initMessage<L>(notif);
604 template<
int L=LOG_INFO,
typename ... TT>
608 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::REVERSE, TextStyle::DIM);
609 initMessage<L>(notif);
618 template<
int L=LOG_INFO,
typename ... TT>
622 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE, TextStyle::DIM);
623 initMessage<L>(notif);
630 template<
int L=LOG_INFO,
typename ... TT>
634 static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::DIM);
635 initMessage<L>(notif);
642 template<
int L=LOG_INFO,
typename ... TT>
645 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::DIM, TextStyle::ITALIC);
646 initMessage<L>(notif);
652 template<
int L=LOG_INFO,
typename ... TT>
654 Logger & revised(
const TT &... args){
655 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::ITALIC);
656 initMessage<L>(notif);
674 template<
typename ... TT>
677 static const Notification notif(__FUNCTION__, TextStyle::DIM);
678 initMessage<LOG_DEBUG>(notif);
684 template<
typename ... TT>
687 static const Notification notif(__FUNCTION__, TextStyle::DIM, TextStyle::ITALIC);
688 initMessage<LOG_DEBUG+1>(notif);
693 template<
typename ... TT>
695 Logger & debug3(
const TT &... args){
696 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::DIM, TextStyle::ITALIC);
697 initMessage<LOG_DEBUG+2>(notif);
704 Logger & log(level_t level){
710 template<
typename ... TT>
712 Logger & operator()(
const TT &... args){
731 if (TIMING && !timing){
732 initTiming(this->prefix);
739 template<
typename ... TT>
741 if (TIMING && !timing){
750 time = monitor.getMilliseconds() - time;
751 std::cerr <<
"TIMING:" << MARKER <<
"</div> ";
754 std::cerr <<
"<b>" << (
static_cast<float>(time)/1000.0f) <<
"</b>" <<
"<br/>" <<
'\n';
777 if (level <= monitor.getVerbosity())
778 message << sstr.rdbuf();
784 if (level <= monitor.getVerbosity()){
785 message << Type::call<simpleName>(type);
794 if (level <= monitor.getVerbosity())
802 if (level <= monitor.getVerbosity())
803 message << static_cast<const void *>(
nullptr);
813 monitor.flush(level, *notif_ptr, prefix, message);
819 monitor.flush(level, *notif_ptr, prefix, message);
828 message <<
" NOTE: Logger" << __FUNCTION__ <<
" flush with non-this Logger";
830 monitor.flush(level, *notif_ptr, prefix, message);
835 int getVerbosity()
const {
836 return monitor.getVerbosity();
848 const Notification * notif_ptr;
852 template<
typename ... TT>
853 void initTiming(
const TT &... args){
855 std::cerr <<
"TIMING:" << MARKER;
856 describeTiming(args...);
859 std::cerr <<
" <div>" <<
'\n';
860 time = monitor.getMilliseconds();
864 template<
typename T,
typename ... TT>
865 void describeTiming(
const T & arg,
const TT &... args){
867 describeTiming(args...);
871 void describeTiming(){
888 template<
typename ... TT>
891 void setPrefix(
const char * filename,
const TT &... args){
893 std::stringstream sstr;
897 if (*filename !=
'\0'){
899 const char * s2 = strrchr(filename,
'/');
906 const char * s3 = strrchr(s2,
'.');
912 sstr.write(s2,
size_t(s3-s2));
919 appendPrefix(sstr, args...);
935 void appendPrefix(std::stringstream &){
938 template<
typename T,
typename ... TT>
939 void appendPrefix(std::stringstream & sstr,
const T & arg,
const TT &... args){
941 appendPrefix(sstr, args...);
945 Logger & initMessage(
const Notification & notif){
946 this->notif_ptr = & notif;
948 this->message.str(
"");
968 Logger & initMessage(level_t level);
981 template<
typename T,
typename ... TT>
983 Logger & flush(
const T & arg,
const TT &... rest){
992 Logger & flush(
const T & arg){
995 monitor.flush(level, *notif_ptr, prefix, message);
1004 template<
typename T>
1006 void append(
const T & arg){
1027void Logger::append(
const TextStyle::Colour & colour){
1032template <
typename ... TT>
1038 time(getLog().getMilliseconds()),
1043template <
typename ... TT>
1049 time(log.getMilliseconds()),
DOC: Add class description.
Definition Log.h:301
Handler for notifications sent by a Logger.
Definition Log.h:159
unsigned short level_t
Log verbosity level type.
Definition Log.h:164
Log(std::ostream &ostr=std::cerr, int verbosityLevel=LOG_WARNING)
Definition Log.h:180
void close()
Closes internal ofstr, if used. External ofstream will not be closed.
Definition Log.h:226
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:326
Logger & start(const TT &... args)
General.
Definition Log.h:378
Logger & operator<<(const std::ostream &sstr)
Send a longer [INFO] preceded with a time stamp.
Definition Log.h:775
Logger & discouraged(const TT &... args)
Warning on user's convention or action that can potentially cause errors or confusions.
Definition Log.h:451
Logger & pending(const TT &... args)
Report a conditional accept/reject, to be completed next.
Definition Log.h:606
Logger & operator<<(const Logger &l)
NEW: sending "mout" insread of "mout.endl" Handling flush operator.
Definition Log.h:825
bool isDebug(level_t l=0)
Returns true, if the debug level of the monitor is at least l.
Definition Log.h:368
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:440
Logger & success(const TT &... args)
Some processing step has completed with desired result.
Definition Log.h:632
Logger & alert(const TT &... args)
Quits immediately, dumps pending messages.
Definition Log.h:399
Logger & operator<<(oper)
Handling flush operator.
Definition Log.h:818
void setPrefix(const char *filename, const TT &... args)
Sets a label that starts every line in the log.
Definition Log.h:891
Logger & obsolete(const TT &... args)
Feature has been removed. Special type of Logger::warn().
Definition Log.h:475
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:676
Logger & quit(const TT &... args)
Quits immediately, dumps pending messages.
Definition Log.h:389
Logger & note(const TT &... args)
For top-level information.
Definition Log.h:499
Logger & hint(const TT &... args)
Like advice, but weaker.
Definition Log.h:644
void startTiming(const TT &... args)
Definition Log.h:740
void startTiming()
Send a short [INFO] preceded with a time stamp.
Definition Log.h:730
Logger & critical(const TT &... args)
Quits immediately, dumps pending messages.
Definition Log.h:409
Logger & special(const TT &... args)
Other useful information.
Definition Log.h:541
Logger & reject(const TT &... args)
Some input has been rejected, for example by a syntax.
Definition Log.h:620
Logger & fail(const TT &... args)
Possible error, but execution can continue. Special type of Logger::warn().
Definition Log.h:463
bool isLevel(level_t l)
Returns true, if the log monitor level is at least l.
Definition Log.h:358
Logger & attention(const TT &... args)
Possible error, but execution can continue. Special type of Logger::warn().
Definition Log.h:486
Logger(const char *filename, const TT &...args)
Start logging,.
Definition Log.h:1033
Logger & error(const TT &... args)
Echoes.
Definition Log.h:426
Logger & suspicious(const TT &... args)
A weak warning about something going possibly wrong.
Definition Log.h:510
Logger & accept(const TT &... args)
Some input has been accepted, for example by a syntax.
Definition Log.h:592
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition Log.h:521
Logger & operator<<(std::nullptr_t)
nullptr_t overload: avoids ambiguous operator<< in C++14.
Definition Log.h:801
Logger & deprecating(const TT &... args)
Feature will be removed. Special type of Logger::note().
Definition Log.h:531
Logger & debug2(const TT &... args)
Debug information.
Definition Log.h:686
Definition StreamBuilder.h:54
Definition StringBuilder.h:58
Definition TextStyleVT100.h:51
std::ostream & operator<<(std::ostream &ostr, const PlainData< DT > &d)
Definition Data.h:631
DOC: Add class description.
Definition Log.h:107