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>
304#define DRAIN_LOG(name) ' ', #name, '=', name
315 std::stringstream & message;
328 template <
typename ... TT>
329 Logger(
const char *filename,
const TT & ...args);
337 template <
typename ... TT>
338 Logger(
Log &log,
const char *filename,
const TT & ...args);
350 return (monitor.getVerbosity() >= l);
367 template <
int L,
typename ... TT>
370 static const Notification notif(__FUNCTION__, TextStyle::DIM);
371 initMessage<L>(notif);
378 template<
typename ... TT>
381 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::REVERSE, TextStyle::BOLD);
382 initMessage<LOG_EMERG>(notif);
388 template<
typename ... TT>
391 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::BOLD);
392 initMessage<LOG_ALERT>(notif);
398 template<
typename ... TT>
401 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE);
402 initMessage<LOG_CRIT>(notif);
415 template<
typename ... TT>
418 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::BOLD);
420 initMessage<LOG_ERR>(notif);
429 template<
typename ... TT>
433 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::BOLD);
434 initMessage<LOG_WARNING>(notif);
440 template<
int L=LOG_WARNING,
typename ... TT>
444 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
445 initMessage<L>(notif);
452 template<
int L=LOG_WARNING,
typename ... TT>
456 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
457 initMessage<L>(notif);
464 template<
int L=LOG_WARNING,
typename ... TT>
468 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::DIM, TextStyle::UNDERLINE);
469 initMessage<L>(notif);
475 template<
int L=LOG_WARNING,
typename ... TT>
478 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE);
479 initMessage<L>(notif);
488 template<
typename ... TT>
491 static const Notification notif(__FUNCTION__, TextStyle::BOLD);
492 initMessage<LOG_NOTICE>(notif);
499 template<
int L=LOG_NOTICE,
typename ... TT>
502 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
503 initMessage<L>(notif);
510 template<
int L=LOG_NOTICE,
typename ... TT>
513 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::OVERLINE);
514 initMessage<L>(notif);
520 template<
int L=LOG_NOTICE,
typename ... TT>
523 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM, TextStyle::UNDERLINE);
524 initMessage<L>(notif);
530 template<
int L=LOG_NOTICE,
typename ... TT>
533 static const Notification notif(__FUNCTION__, TextStyle::CYAN);
534 initMessage<L>(notif);
540 template<
int L=LOG_NOTICE,
typename ... TT>
542 Logger & experimental(
const TT &... args){
543 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE, TextStyle::DIM);
544 initMessage<L>(notif);
549 template<
int L=LOG_NOTICE,
typename ... TT>
551 Logger & advice(
const TT &... args){
552 static const Notification notif(__FUNCTION__, TextStyle::Colour::PURPLE);
553 initMessage<L>(notif);
561 template<
typename ... TT>
563 Logger & info(
const TT &... args){
564 static const Notification notif(__FUNCTION__, TextStyle::WHITE);
565 initMessage<LOG_INFO>(notif);
571 template<
int L=LOG_INFO,
typename ... TT>
573 Logger & ok(
const TT &... args){
574 static const Notification notif(__FUNCTION__, TextStyle::GREEN);
575 initMessage<L>(notif);
581 template<
int L=LOG_INFO,
typename ... TT>
585 static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::REVERSE, TextStyle::DIM);
586 initMessage<L>(notif);
595 template<
int L=LOG_INFO,
typename ... TT>
599 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::REVERSE, TextStyle::DIM);
600 initMessage<L>(notif);
609 template<
int L=LOG_INFO,
typename ... TT>
613 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE, TextStyle::DIM);
614 initMessage<L>(notif);
621 template<
int L=LOG_INFO,
typename ... TT>
625 static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::DIM);
626 initMessage<L>(notif);
633 template<
int L=LOG_INFO,
typename ... TT>
636 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::DIM, TextStyle::ITALIC);
637 initMessage<L>(notif);
643 template<
int L=LOG_INFO,
typename ... TT>
645 Logger & revised(
const TT &... args){
646 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::ITALIC);
647 initMessage<L>(notif);
665 template<
typename ... TT>
668 static const Notification notif(__FUNCTION__, TextStyle::DIM);
669 initMessage<LOG_DEBUG>(notif);
675 template<
typename ... TT>
678 static const Notification notif(__FUNCTION__, TextStyle::DIM, TextStyle::ITALIC);
679 initMessage<LOG_DEBUG+1>(notif);
684 template<
typename ... TT>
686 Logger & debug3(
const TT &... args){
687 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::DIM, TextStyle::ITALIC);
688 initMessage<LOG_DEBUG+2>(notif);
695 Logger & log(level_t level){
701 template<
typename ... TT>
703 Logger & operator()(
const TT &... args){
722 if (TIMING && !timing){
723 initTiming(this->prefix);
730 template<
typename ... TT>
732 if (TIMING && !timing){
741 time = monitor.getMilliseconds() - time;
742 std::cerr <<
"TIMING:" << MARKER <<
"</div> ";
745 std::cerr <<
"<b>" << (
static_cast<float>(time)/1000.0f) <<
"</b>" <<
"<br/>" <<
'\n';
768 if (level <= monitor.getVerbosity())
769 message << sstr.rdbuf();
775 if (level <= monitor.getVerbosity())
776 message << Type::call<simpleName>(type);
784 if (level <= monitor.getVerbosity())
795 monitor.flush(level, *notif_ptr, prefix, message);
801 monitor.flush(level, *notif_ptr, prefix, message);
810 message <<
" NOTE: Logger" << __FUNCTION__ <<
" flush with non-this Logger";
812 monitor.flush(level, *notif_ptr, prefix, message);
817 int getVerbosity()
const {
818 return monitor.getVerbosity();
830 const Notification * notif_ptr;
834 template<
typename ... TT>
835 void initTiming(
const TT &... args){
837 std::cerr <<
"TIMING:" << MARKER;
838 describeTiming(args...);
841 std::cerr <<
" <div>" <<
'\n';
842 time = monitor.getMilliseconds();
846 template<
typename T,
typename ... TT>
847 void describeTiming(
const T & arg,
const TT &... args){
849 describeTiming(args...);
853 void describeTiming(){
871 template<
typename ... TT>
874 void setPrefix(
const char * filename,
const TT &... args){
876 std::stringstream sstr;
880 if (*filename !=
'\0'){
882 const char * s2 = strrchr(filename,
'/');
889 const char * s3 = strrchr(s2,
'.');
895 sstr.write(s2,
size_t(s3-s2));
902 appendPrefix(sstr, args...);
918 void appendPrefix(std::stringstream & sstr){
921 template<
typename T,
typename ... TT>
922 void appendPrefix(std::stringstream & sstr,
const T & arg,
const TT &... args){
924 appendPrefix(sstr, args...);
928 Logger & initMessage(
const Notification & notif){
929 this->notif_ptr = & notif;
931 this->message.str(
"");
951 Logger & initMessage(level_t level);
964 template<
typename T,
typename ... TT>
966 Logger & flush(
const T & arg,
const TT &... rest){
975 Logger & flush(
const T & arg){
978 monitor.flush(level, *notif_ptr, prefix, message);
989 void append(
const T & arg){
1007void Logger::append(
const TextStyle::Colour & colour){
1012template <
typename ... TT>
1018 time(getLog().getMilliseconds()),
1023template <
typename ... TT>
1029 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:313
Logger & start(const TT &... args)
General.
Definition Log.h:369
Logger & operator<<(const std::ostream &sstr)
Send a longer [INFO] preceded with a time stamp.
Definition Log.h:766
Logger & discouraged(const TT &... args)
Warning on user's convention or action that can potentially cause errors or confusions.
Definition Log.h:442
Logger & pending(const TT &... args)
Report a conditional accept/reject, to be completed next.
Definition Log.h:597
Logger & operator<<(const Logger &l)
NEW: sending "mout" insread of "mout.endl" Handling flush operator.
Definition Log.h:807
bool isDebug(level_t l=0)
Returns true, if the debug level of the monitor is at least l.
Definition Log.h:359
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:431
Logger & success(const TT &... args)
Some processing step has completed with desired result.
Definition Log.h:623
Logger & alert(const TT &... args)
Quits immediately, dumps pending messages.
Definition Log.h:390
void setPrefix(const char *filename, const TT &... args)
Sets a label that starts every line in the log.
Definition Log.h:874
Logger & obsolete(const TT &... args)
Feature has been removed. Special type of Logger::warn().
Definition Log.h:466
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:667
Logger & quit(const TT &... args)
Quits immediately, dumps pending messages.
Definition Log.h:380
Logger & note(const TT &... args)
For top-level information.
Definition Log.h:490
Logger & hint(const TT &... args)
Like advice, but weaker.
Definition Log.h:635
void startTiming(const TT &... args)
Definition Log.h:731
void startTiming()
Send a short [INFO] preceded with a time stamp.
Definition Log.h:721
Logger & critical(const TT &... args)
Quits immediately, dumps pending messages.
Definition Log.h:400
Logger & special(const TT &... args)
Other useful information.
Definition Log.h:532
Logger & reject(const TT &... args)
Some input has been rejected, for example by a syntax.
Definition Log.h:611
Logger & fail(const TT &... args)
Possible error, but execution can continue. Special type of Logger::warn().
Definition Log.h:454
bool isLevel(level_t l)
Returns true, if the log monitor level is at least l.
Definition Log.h:349
Logger & attention(const TT &... args)
Possible error, but execution can continue. Special type of Logger::warn().
Definition Log.h:477
Logger(const char *filename, const TT &...args)
Start logging,.
Definition Log.h:1013
Logger & error(const TT &... args)
Echoes.
Definition Log.h:417
Logger & suspicious(const TT &... args)
A weak warning about something going possibly wrong.
Definition Log.h:501
Logger & accept(const TT &... args)
Some input has been accepted, for example by a syntax.
Definition Log.h:583
Logger & operator<<(oper op)
Handling flush operator.
Definition Log.h:800
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition Log.h:512
Logger & deprecating(const TT &... args)
Feature will be removed. Special type of Logger::note().
Definition Log.h:522
Logger & debug2(const TT &... args)
Debug information.
Definition Log.h:677
Definition StreamBuilder.h:53
Definition StringBuilder.h:58
Definition TextStyleVT100.h:45
Definition DataSelector.cpp:1277