50 #include "StringBuilder.h"
52 #include "TextStyleVT100.h"
103 template <
typename ... T>
104 Notification(
const std::string & key,
const T &... args){
109 std::stringstream sstr;
111 vt100.append(sstr, args...);
112 vt100color = sstr.str();
120 std::string vt100color;
155 typedef std::map<int,std::string> status_dict_t;
158 static status_dict_t statusDict;
168 Log(std::ostream & ostr=std::cerr,
int verbosityLevel=LOG_WARNING) : ostrPtr(&ostr), verbosityLevel(verbosityLevel)
175 Log(
const Log &m) : ostrPtr(m.ostrPtr), verbosityLevel(m.verbosityLevel) {
191 void setOstr(std::ostream & ostr){
202 void setOstr(
const std::string & filename){
209 ofstr.open(filename, std::ios::out);
215 if (ofstr.is_open()){
223 void setVerbosity(
level_t level){
224 verbosityLevel = level;
227 void setVerbosity(
const std::string & level);
230 int getVerbosity()
const {
231 return verbosityLevel;
234 void flush(
level_t level,
const std::string & prefix,
const std::stringstream & sstr);
237 void flush(
level_t level,
const Notification & notif,
const std::string & prefix,
const std::stringstream & sstr);
241 long getRelativeMilliseconds(){
242 return getMilliseconds() - millisecondsStart;
246 long getMilliseconds(){
248 gettimeofday(&time, NULL);
249 return (time.tv_sec * 1000) + (time.tv_usec / 1000);
254 millisecondsStart = getMilliseconds();
265 std::ostream *ostrPtr;
271 long millisecondsStart;
295 template<
typename T,
typename ... TT>
310 std::stringstream & message;
323 template <
typename ... TT>
324 Logger(
const char *filename,
const TT & ...args);
332 template <
typename ... TT>
333 Logger(
Log &log,
const char *filename,
const TT & ...args);
345 return (monitor.getVerbosity() >= l);
362 template <
int L,
typename ... TT>
365 static const Notification notif(__FUNCTION__, TextStyle::DIM);
366 initMessage<L>(notif);
373 template<
typename ... TT>
376 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::REVERSE, TextStyle::BOLD);
377 initMessage<LOG_EMERG>(notif);
383 template<
typename ... TT>
386 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::BOLD);
387 initMessage<LOG_ALERT>(notif);
393 template<
typename ... TT>
396 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE);
397 initMessage<LOG_CRIT>(notif);
410 template<
typename ... TT>
413 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::BOLD);
415 initMessage<LOG_ERR>(notif);
424 template<
typename ... TT>
428 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::BOLD);
429 initMessage<LOG_WARNING>(notif);
435 template<
int L=LOG_WARNING,
typename ... TT>
439 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
440 initMessage<L>(notif);
447 template<
int L=LOG_WARNING,
typename ... TT>
451 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
452 initMessage<L>(notif);
459 template<
int L=LOG_WARNING,
typename ... TT>
463 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::DIM, TextStyle::UNDERLINE);
464 initMessage<L>(notif);
470 template<
int L=LOG_WARNING,
typename ... TT>
473 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE, TextStyle::DIM);
474 initMessage<L>(notif);
483 template<
typename ... TT>
486 static const Notification notif(__FUNCTION__, TextStyle::BOLD);
487 initMessage<LOG_NOTICE>(notif);
494 template<
int L=LOG_NOTICE,
typename ... TT>
497 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
498 initMessage<L>(notif);
505 template<
int L=LOG_NOTICE,
typename ... TT>
508 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::OVERLINE);
509 initMessage<L>(notif);
515 template<
int L=LOG_NOTICE,
typename ... TT>
518 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM, TextStyle::UNDERLINE);
519 initMessage<L>(notif);
525 template<
int L=LOG_NOTICE,
typename ... TT>
528 static const Notification notif(__FUNCTION__, TextStyle::CYAN);
529 initMessage<L>(notif);
535 template<
int L=LOG_NOTICE,
typename ... TT>
537 Logger & experimental(
const TT &... args){
538 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE);
539 initMessage<L>(notif);
544 template<
int L=LOG_NOTICE,
typename ... TT>
546 Logger & advice(
const TT &... args){
547 static const Notification notif(__FUNCTION__, TextStyle::UNDERLINE);
548 initMessage<L>(notif);
556 template<
typename ... TT>
558 Logger & info(
const TT &... args){
559 static const Notification notif(__FUNCTION__, TextStyle::WHITE);
560 initMessage<LOG_INFO>(notif);
566 template<
int L=LOG_INFO,
typename ... TT>
568 Logger & ok(
const TT &... args){
569 static const Notification notif(__FUNCTION__, TextStyle::GREEN);
570 initMessage<L>(notif);
576 template<
int L=LOG_INFO,
typename ... TT>
580 static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::REVERSE, TextStyle::DIM);
581 initMessage<L>(notif);
590 template<
int L=LOG_INFO,
typename ... TT>
594 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::REVERSE, TextStyle::DIM);
595 initMessage<L>(notif);
604 template<
int L=LOG_INFO,
typename ... TT>
608 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE, TextStyle::DIM);
609 initMessage<L>(notif);
616 template<
int L=LOG_INFO,
typename ... TT>
620 static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::DIM);
621 initMessage<L>(notif);
628 template<
int L=LOG_INFO,
typename ... TT>
631 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::DIM, TextStyle::UNDERLINE);
632 initMessage<L>(notif);
638 template<
int L=LOG_INFO,
typename ... TT>
640 Logger & revised(
const TT &... args){
641 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
642 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);
713 Logger & log(level_t level){
719 template<
typename ... TT>
721 Logger & operator()(
const TT &... args){
740 if (TIMING && !timing){
741 initTiming(this->prefix);
748 template<
typename ... TT>
750 if (TIMING && !timing){
759 time = monitor.getMilliseconds() - time;
760 std::cerr <<
"TIMING:" << MARKER <<
"</div> ";
763 std::cerr <<
"<b>" << (
static_cast<float>(time)/1000.0f) <<
"</b>" <<
"<br/>" <<
'\n';
786 if (level <= monitor.getVerbosity())
787 message << sstr.rdbuf();
796 if (level <= monitor.getVerbosity())
807 monitor.flush(level, *notif_ptr, prefix, message);
813 monitor.flush(level, *notif_ptr, prefix, message);
822 message <<
" NOTE: Logger" << __FUNCTION__ <<
" flush with non-this Logger";
824 monitor.flush(level, *notif_ptr, prefix, message);
829 int getVerbosity()
const {
830 return monitor.getVerbosity();
842 const Notification * notif_ptr;
846 template<
typename ... TT>
847 void initTiming(
const TT &... args){
849 std::cerr <<
"TIMING:" << MARKER;
850 describeTiming(args...);
853 std::cerr <<
" <div>" <<
'\n';
854 time = monitor.getMilliseconds();
858 template<
typename T,
typename ... TT>
859 void describeTiming(
const T & arg,
const TT &... args){
861 describeTiming(args...);
865 void describeTiming(){
883 template<
typename ... TT>
886 void setPrefix(
const char * filename,
const TT &... args){
888 std::stringstream sstr;
892 if (*filename !=
'\0'){
894 const char * s2 = strrchr(filename,
'/');
901 const char * s3 = strrchr(s2,
'.');
907 sstr.write(s2,
size_t(s3-s2));
914 appendPrefix(sstr, args...);
930 void appendPrefix(std::stringstream & sstr){
933 template<
typename T,
typename ... TT>
934 void appendPrefix(std::stringstream & sstr,
const T & arg,
const TT &... args){
936 appendPrefix(sstr, args...);
940 Logger & initMessage(
const Notification & notif){
941 this->notif_ptr = & notif;
943 this->message.str(
"");
963 Logger & initMessage(level_t level);
976 template<
typename T,
typename ... TT>
978 Logger & flush(
const T & arg,
const TT &... rest){
987 Logger & flush(
const T & arg){
990 monitor.flush(level, *notif_ptr, prefix, message);
1001 void append(
const T & arg){
1019 void Logger::append(
const TextStyle::Colour & colour){
1024 template <
typename ... TT>
1030 time(getLog().getMilliseconds()),
1035 template <
typename ... TT>
1041 time(log.getMilliseconds()),
Handler for notifications sent by a Logger.
Definition: Log.h:147
unsigned short level_t
Log verbosity level type.
Definition: Log.h:152
Log(std::ostream &ostr=std::cerr, int verbosityLevel=LOG_WARNING)
Definition: Log.h:168
void close()
Closes internal ofstr, if used. External ofstream will not be closed.
Definition: Log.h:214
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & deprecating(const TT &... args)
Feature will be removed. Special type of Logger::note().
Definition: Log.h:517
Logger & pending(const TT &... args)
Report a conditional accept/reject, to be completed next.
Definition: Log.h:592
Logger & success(const TT &... args)
Some processing step has completed with desired result.
Definition: Log.h:618
Logger & error(const TT &... args)
Echoes.
Definition: Log.h:412
bool isDebug(level_t l=0)
Returns true, if the debug level of the monitor is at least l.
Definition: Log.h:354
Logger & accept(const TT &... args)
Some input has been accepted, for example by a syntax.
Definition: Log.h:578
Logger & critical(const TT &... args)
Quits immediately, dumps pending messages.
Definition: Log.h:395
Logger & attention(const TT &... args)
Possible error, but execution can continue. Special type of Logger::warn().
Definition: Log.h:472
Logger & quit(const TT &... args)
Quits immediately, dumps pending messages.
Definition: Log.h:375
Logger & special(const TT &... args)
Other useful information.
Definition: Log.h:527
Logger & fail(const TT &... args)
Possible error, but execution can continue. Special type of Logger::warn().
Definition: Log.h:449
Logger & operator<<(const Logger &l)
NEW: sending "mout" insread of "mout.endl" Handling flush operator.
Definition: Log.h:819
Logger & reject(const TT &... args)
Some input has been rejected, for example by a syntax.
Definition: Log.h:606
void setPrefix(const char *filename, const TT &... args)
Sets a label that starts every line in the log.
Definition: Log.h:886
void startTiming(const TT &... args)
Definition: Log.h:749
void startTiming()
Send a short [INFO] preceded with a time stamp.
Definition: Log.h:739
Logger & operator<<(oper op)
Handling flush operator.
Definition: Log.h:812
bool isLevel(level_t l)
Returns true, if the log monitor level is at least l.
Definition: Log.h:344
Logger & alert(const TT &... args)
Quits immediately, dumps pending messages.
Definition: Log.h:385
Logger & obsolete(const TT &... args)
Feature has been removed. Special type of Logger::warn().
Definition: Log.h:461
Logger(const char *filename, const TT &...args)
Start logging,.
Definition: Log.h:1025
Logger & operator<<(const std::ostream &sstr)
Send a longer [INFO] preceded with a time stamp.
Definition: Log.h:784
Logger & discouraged(const TT &... args)
Warning on user's convention or action that can potentially cause errors or confusions.
Definition: Log.h:437
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition: Log.h:507
Logger & note(const TT &... args)
For top-level information.
Definition: Log.h:485
Logger & start(const TT &... args)
General.
Definition: Log.h:364
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:426
Logger & debug(const TT &... args)
Public, yet typically used "internally", when TIMING=true.
Definition: Log.h:676
Logger & hint(const TT &... args)
Like advice, but weaker.
Definition: Log.h:630
Logger & suspicious(const TT &... args)
A weak warning about something going possibly wrong.
Definition: Log.h:496
Logger & debug2(const TT &... args)
Debug information.
Definition: Log.h:686
Definition: StreamBuilder.h:59
Definition: StringBuilder.h:58
Definition: TextStyleVT100.h:45
Definition: DataSelector.cpp:1277