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>
303 #define DRAIN_LOG_VAR(name) '#', #name, '=', name
312 std::stringstream & message;
325 template <
typename ... TT>
326 Logger(
const char *filename,
const TT & ...args);
334 template <
typename ... TT>
335 Logger(
Log &log,
const char *filename,
const TT & ...args);
347 return (monitor.getVerbosity() >= l);
364 template <
int L,
typename ... TT>
367 static const Notification notif(__FUNCTION__, TextStyle::DIM);
368 initMessage<L>(notif);
375 template<
typename ... TT>
378 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::REVERSE, TextStyle::BOLD);
379 initMessage<LOG_EMERG>(notif);
385 template<
typename ... TT>
388 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::BOLD);
389 initMessage<LOG_ALERT>(notif);
395 template<
typename ... TT>
398 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE);
399 initMessage<LOG_CRIT>(notif);
412 template<
typename ... TT>
415 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::BOLD);
417 initMessage<LOG_ERR>(notif);
426 template<
typename ... TT>
430 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::BOLD);
431 initMessage<LOG_WARNING>(notif);
437 template<
int L=LOG_WARNING,
typename ... TT>
441 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
442 initMessage<L>(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::PURPLE, TextStyle::DIM, TextStyle::UNDERLINE);
466 initMessage<L>(notif);
472 template<
int L=LOG_WARNING,
typename ... TT>
475 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE, TextStyle::DIM);
476 initMessage<L>(notif);
485 template<
typename ... TT>
488 static const Notification notif(__FUNCTION__, TextStyle::BOLD);
489 initMessage<LOG_NOTICE>(notif);
496 template<
int L=LOG_NOTICE,
typename ... TT>
499 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
500 initMessage<L>(notif);
507 template<
int L=LOG_NOTICE,
typename ... TT>
510 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::OVERLINE);
511 initMessage<L>(notif);
517 template<
int L=LOG_NOTICE,
typename ... TT>
520 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM, TextStyle::UNDERLINE);
521 initMessage<L>(notif);
527 template<
int L=LOG_NOTICE,
typename ... TT>
530 static const Notification notif(__FUNCTION__, TextStyle::CYAN);
531 initMessage<L>(notif);
537 template<
int L=LOG_NOTICE,
typename ... TT>
539 Logger & experimental(
const TT &... args){
540 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE);
541 initMessage<L>(notif);
546 template<
int L=LOG_NOTICE,
typename ... TT>
548 Logger & advice(
const TT &... args){
549 static const Notification notif(__FUNCTION__, TextStyle::UNDERLINE);
550 initMessage<L>(notif);
558 template<
typename ... TT>
560 Logger & info(
const TT &... args){
561 static const Notification notif(__FUNCTION__, TextStyle::WHITE);
562 initMessage<LOG_INFO>(notif);
568 template<
int L=LOG_INFO,
typename ... TT>
570 Logger & ok(
const TT &... args){
571 static const Notification notif(__FUNCTION__, TextStyle::GREEN);
572 initMessage<L>(notif);
578 template<
int L=LOG_INFO,
typename ... TT>
582 static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::REVERSE, TextStyle::DIM);
583 initMessage<L>(notif);
592 template<
int L=LOG_INFO,
typename ... TT>
596 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::REVERSE, TextStyle::DIM);
597 initMessage<L>(notif);
606 template<
int L=LOG_INFO,
typename ... TT>
610 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE, TextStyle::DIM);
611 initMessage<L>(notif);
618 template<
int L=LOG_INFO,
typename ... TT>
622 static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::DIM);
623 initMessage<L>(notif);
630 template<
int L=LOG_INFO,
typename ... TT>
633 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::DIM, TextStyle::UNDERLINE);
634 initMessage<L>(notif);
640 template<
int L=LOG_INFO,
typename ... TT>
642 Logger & revised(
const TT &... args){
643 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
644 initMessage<L>(notif);
676 template<
typename ... TT>
679 static const Notification notif(__FUNCTION__, TextStyle::DIM);
680 initMessage<LOG_DEBUG>(notif);
686 template<
typename ... TT>
689 static const Notification notif(__FUNCTION__, TextStyle::DIM, TextStyle::ITALIC);
690 initMessage<LOG_DEBUG+1>(notif);
695 template<
typename ... TT>
697 Logger & debug3(
const TT &... args){
698 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::DIM, TextStyle::ITALIC);
699 initMessage<LOG_DEBUG+2>(notif);
715 Logger & log(level_t level){
721 template<
typename ... TT>
723 Logger & operator()(
const TT &... args){
742 if (TIMING && !timing){
743 initTiming(this->prefix);
750 template<
typename ... TT>
752 if (TIMING && !timing){
761 time = monitor.getMilliseconds() - time;
762 std::cerr <<
"TIMING:" << MARKER <<
"</div> ";
765 std::cerr <<
"<b>" << (
static_cast<float>(time)/1000.0f) <<
"</b>" <<
"<br/>" <<
'\n';
788 if (level <= monitor.getVerbosity())
789 message << sstr.rdbuf();
798 if (level <= monitor.getVerbosity())
809 monitor.flush(level, *notif_ptr, prefix, message);
815 monitor.flush(level, *notif_ptr, prefix, message);
824 message <<
" NOTE: Logger" << __FUNCTION__ <<
" flush with non-this Logger";
826 monitor.flush(level, *notif_ptr, prefix, message);
831 int getVerbosity()
const {
832 return monitor.getVerbosity();
844 const Notification * notif_ptr;
848 template<
typename ... TT>
849 void initTiming(
const TT &... args){
851 std::cerr <<
"TIMING:" << MARKER;
852 describeTiming(args...);
855 std::cerr <<
" <div>" <<
'\n';
856 time = monitor.getMilliseconds();
860 template<
typename T,
typename ... TT>
861 void describeTiming(
const T & arg,
const TT &... args){
863 describeTiming(args...);
867 void describeTiming(){
885 template<
typename ... TT>
888 void setPrefix(
const char * filename,
const TT &... args){
890 std::stringstream sstr;
894 if (*filename !=
'\0'){
896 const char * s2 = strrchr(filename,
'/');
903 const char * s3 = strrchr(s2,
'.');
909 sstr.write(s2,
size_t(s3-s2));
916 appendPrefix(sstr, args...);
932 void appendPrefix(std::stringstream & sstr){
935 template<
typename T,
typename ... TT>
936 void appendPrefix(std::stringstream & sstr,
const T & arg,
const TT &... args){
938 appendPrefix(sstr, args...);
942 Logger & initMessage(
const Notification & notif){
943 this->notif_ptr = & notif;
945 this->message.str(
"");
965 Logger & initMessage(level_t level);
978 template<
typename T,
typename ... TT>
980 Logger & flush(
const T & arg,
const TT &... rest){
989 Logger & flush(
const T & arg){
992 monitor.flush(level, *notif_ptr, prefix, message);
1001 template<
typename T>
1003 void append(
const T & arg){
1021 void Logger::append(
const TextStyle::Colour & colour){
1026 template <
typename ... TT>
1032 time(getLog().getMilliseconds()),
1037 template <
typename ... TT>
1043 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:310
Logger & deprecating(const TT &... args)
Feature will be removed. Special type of Logger::note().
Definition: Log.h:519
Logger & pending(const TT &... args)
Report a conditional accept/reject, to be completed next.
Definition: Log.h:594
Logger & success(const TT &... args)
Some processing step has completed with desired result.
Definition: Log.h:620
Logger & error(const TT &... args)
Echoes.
Definition: Log.h:414
bool isDebug(level_t l=0)
Returns true, if the debug level of the monitor is at least l.
Definition: Log.h:356
Logger & accept(const TT &... args)
Some input has been accepted, for example by a syntax.
Definition: Log.h:580
Logger & critical(const TT &... args)
Quits immediately, dumps pending messages.
Definition: Log.h:397
Logger & attention(const TT &... args)
Possible error, but execution can continue. Special type of Logger::warn().
Definition: Log.h:474
Logger & quit(const TT &... args)
Quits immediately, dumps pending messages.
Definition: Log.h:377
Logger & special(const TT &... args)
Other useful information.
Definition: Log.h:529
Logger & fail(const TT &... args)
Possible error, but execution can continue. Special type of Logger::warn().
Definition: Log.h:451
Logger & operator<<(const Logger &l)
NEW: sending "mout" insread of "mout.endl" Handling flush operator.
Definition: Log.h:821
Logger & reject(const TT &... args)
Some input has been rejected, for example by a syntax.
Definition: Log.h:608
void setPrefix(const char *filename, const TT &... args)
Sets a label that starts every line in the log.
Definition: Log.h:888
void startTiming(const TT &... args)
Definition: Log.h:751
void startTiming()
Send a short [INFO] preceded with a time stamp.
Definition: Log.h:741
Logger & operator<<(oper op)
Handling flush operator.
Definition: Log.h:814
bool isLevel(level_t l)
Returns true, if the log monitor level is at least l.
Definition: Log.h:346
Logger & alert(const TT &... args)
Quits immediately, dumps pending messages.
Definition: Log.h:387
Logger & obsolete(const TT &... args)
Feature has been removed. Special type of Logger::warn().
Definition: Log.h:463
Logger(const char *filename, const TT &...args)
Start logging,.
Definition: Log.h:1027
Logger & operator<<(const std::ostream &sstr)
Send a longer [INFO] preceded with a time stamp.
Definition: Log.h:786
Logger & discouraged(const TT &... args)
Warning on user's convention or action that can potentially cause errors or confusions.
Definition: Log.h:439
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition: Log.h:509
Logger & note(const TT &... args)
For top-level information.
Definition: Log.h:487
Logger & start(const TT &... args)
General.
Definition: Log.h:366
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:428
Logger & debug(const TT &... args)
Public, yet typically used "internally", when TIMING=true.
Definition: Log.h:678
Logger & hint(const TT &... args)
Like advice, but weaker.
Definition: Log.h:632
Logger & suspicious(const TT &... args)
A weak warning about something going possibly wrong.
Definition: Log.h:498
Logger & debug2(const TT &... args)
Debug information.
Definition: Log.h:688
Definition: StreamBuilder.h:59
Definition: StringBuilder.h:58
Definition: TextStyleVT100.h:45
Definition: DataSelector.cpp:1277