Loading...
Searching...
No Matches
Log.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31
32#ifndef DRAIN_LOG_H_
33#define DRAIN_LOG_H_
34
35#include <cstddef> // nullptr
36#include <stdlib.h>
37#include <sstream>
38#include <string>
39#include <iostream>
40#include <fstream>
41#include <stdexcept>
42
43//#include <ctime>
44#include <sys/time.h>
45#include <string.h> // strrchr()
46
47#include <syslog.h>
48#include <map>
49
50#include "StringBuilder.h"
51// #include "TextStyle.h"
52#include "TextStyleVT100.h"
53/*
54#define LOG_EMERG 0 // system is unusable //
55#define LOG_ALERT 1 // action must be taken immediately // RACK examples
56#define LOG_CRIT 2 // critical conditions //
57#define LOG_ERR 3 // error conditions // // File read/write failed
58#define LOG_WARNING 4 // warning conditions // // HDF5 empty or contains no relevant data
59#define LOG_NOTICE 5 // normal but significant condition // No volumes used for a composite
60#define LOG_INFO 6 // informational // // Read/Write File, start/end of operator
61#define LOG_DEBUG 7 // debug-level messages // Store variable
62 10 // Write control files (function input, output)
63 11 // Write intermediate results in files
64 15 // Debug 1D loops
65 20 // Debug 2D loops
66
67Compare with Python: https://docs.python.org/3/library/logging.html#logging-levels
68 */
69
70
71/*
72#ifdef __GNUC__
73 inline std::string className(const std::string & prettyFunction)
74 {
75 const size_t colons = prettyFunction.find("::");
76 if (colons == std::string::npos){
77 return "::";
78 }
79 else {
80 const size_t begin = prettyFunction.substr(0, colons).rfind(" ") + 1;
81 const size_t end = colons - begin;
82 return prettyFunction.substr(begin,end);
83 }
84}
85#define CLASSNAME className(__PRETTY_FUNCTION__)
86#else
87#define CLASSNAME __FILE__
88#endif
89*/
90
91namespace drain {
92
93// using namespace std;
94
96
97 /*
98 Notification(const std::string & key="", int vt100color=35){
99 set(key, vt100color);
100 };
101 */
102
103 template <typename ... T>
104 Notification(const std::string & key, const T &... args){
105
106 this->key = key;
107
108 TextStyleVT100 vt100;
109 std::stringstream sstr;
110 //vt100.write(sstr, args..., key);
111 vt100.append(sstr, args...);
112 vt100color = sstr.str();
113 };
114
115
116 //void set(const std::string & key, int vt100color);
117
118
119 std::string key;
120 std::string vt100color;
121
122};
123
124// extern unsigned int Debug; // getting obsolete
125
127class Logger;
128
130
147class Log {
148
149public:
150
152 typedef unsigned short level_t;
153
154 //typedef std::vector<Notification> notif_dict_t;
155 typedef std::map<int,std::string> status_dict_t;
156
157 const
158 static status_dict_t statusDict;
159
160 // experimental
161 int id = 0;
162
164
167 inline
168 Log(std::ostream & ostr=std::cerr, int verbosityLevel=LOG_WARNING) : ostrPtr(&ostr), verbosityLevel(verbosityLevel) // VT100(true),
169 {
170 resetTime();
171 //std::cerr << "start monitor, level=" << verbosityLevel << std::endl;
172 };
173
174 inline
175 Log(const Log &m) : ostrPtr(m.ostrPtr), verbosityLevel(m.verbosityLevel) { // VT100(m.VT100),
176 resetTime();
177 };
178
179 inline
180 ~Log(){
181 close(); // Note: external ofstream will not be closed.
182 /*
183 if (ostrPtr != nullptr){ // it never is...
184 ostrPtr->close();
185 }
186 */
187 }
188
189
190 inline
191 void setOstr(std::ostream & ostr){
192 /*
193 if (ostrPtr != nullptr){ // it never is...
194 ostrPtr->close();
195 }
196 */
197 close();
198 ostrPtr = &ostr;
199 }
200
201 inline
202 void setOstr(const std::string & filename){
203 /*
204 if (ostrPtr != nullptr){ // it never is...
205 ostrPtr->close();
206 }
207 */
208 close();
209 ofstr.open(filename, std::ios::out);
210 ostrPtr = &ofstr;
211 }
212
214 void close(){
215 if (ofstr.is_open()){
216 ostrPtr = nullptr; // or what, std::cerr ?
217 ofstr.close();
218 }
219 }
220
221 //
222 inline
223 void setVerbosity(level_t level){
224 verbosityLevel = level;
225 };
226
227 void setVerbosity(const std::string & level);
228
229 inline
230 int getVerbosity() const {
231 return verbosityLevel;
232 };
233
234 void flush(level_t level, const std::string & prefix, const std::stringstream & sstr);
235
236 //void flush(level_t level, const Notification & notif, const std::string & prefix, const std::ostream & sstr);
237 void flush(level_t level, const Notification & notif, const std::string & prefix, const std::stringstream & sstr);
238
239
240 inline
241 long getRelativeMilliseconds(){
242 return getMilliseconds() - millisecondsStart;
243 }
244
245 static inline
246 long getMilliseconds(){
247 timeval time;
248 gettimeofday(&time, NULL);
249 return (time.tv_sec * 1000) + (time.tv_usec / 1000);
250 }
251
252 inline
253 void resetTime(){
254 millisecondsStart = getMilliseconds();
255 };
256
257 static
258 bool USE_VT100; // = true;
259
260 // static
261 // const notif_dict_t & getDict();
262
263protected:
264
265 std::ostream *ostrPtr;
266
267 std::ofstream ofstr;
268
269 level_t verbosityLevel;
270
271 long millisecondsStart;
272
273 //drain::Dictionary<int, Notification> dict;
274
275};
276
277//extern Log monitor;
278
279Log & getLog();
280
281namespace image {
282
283Log & getImgLog();
284
285} // namespace image
286
287
288class DrainException : public std::runtime_error {
289
290public:
291
292
293
294 // Either this or previous is unneeded?
295 template<typename T,typename ... TT>
296 DrainException(const T &elem, const TT &... rest) : std::runtime_error(drain::StringBuilder<>(elem, rest...)){
297 }
298
299
300};
301
303// #define DRAIN_LOG(name) '#', #name, '=', name
304#define DRAIN_LOG(name) ' ', #name, '=', name
305
306
307
309
312//class Logger : public std::stringstream {
313class Logger : public StreamBuilder<0> {
314
315 std::stringstream & message;
316
317public:
318
319
320
321 typedef Log::level_t level_t;
322
324
328 template <typename ... TT>
329 Logger(const char *filename, const TT & ...args);
330 //Logger(const char *filename, const std::string & name = "");
331
333
337 template <typename ... TT>
338 Logger(Log &log, const char *filename, const TT & ...args); //const char *className = NULL);
339 //Logger(Log &log, const char *filename, const std::string & name = ""); //const char *className = NULL);
340
341 ~Logger();
342
344
348 inline
349 bool isLevel(level_t l){
350 return (monitor.getVerbosity() >= l);
351 };
352
354
358 inline
359 bool isDebug(level_t l=0){
360 return isLevel(LOG_DEBUG+l);
361 //return (monitor.getVerbosity() >= (LOG_DEBUG+l));
362 };
363
364
365
367 template <int L, typename ... TT>
368 inline
369 Logger & start(const TT &... args){
370 static const Notification notif(__FUNCTION__, TextStyle::DIM); //, TextStyle::BOLD
371 initMessage<L>(notif);
372 flush(args...);
373 return *this;
374 };
375
376
378 template<typename ... TT>
379 inline
380 Logger & quit(const TT &... args){
381 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::REVERSE, TextStyle::BOLD);
382 initMessage<LOG_EMERG>(notif);
383 flush(args...);
384 return *this;
385 };
386
388 template<typename ... TT>
389 inline
390 Logger & alert(const TT &... args){
391 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::BOLD);
392 initMessage<LOG_ALERT>(notif);
393 flush(args...);
394 return *this;
395 };
396
398 template<typename ... TT>
399 inline
400 Logger & critical(const TT &... args){
401 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE);
402 initMessage<LOG_CRIT>(notif);
403 flush(args...);
404 return *this;
405 };
406
408 /*
409 inline
410 Logger & error(){
411 return initMessage<LOG_ERR>();
412 };
413 */
414
415 template<typename ... TT>
416 inline
417 Logger & error(const TT &... args){
418 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::BOLD);
419 // error();
420 initMessage<LOG_ERR>(notif);
421 flush(args...);
422 return *this;
423 };
424
425
426 // LOG_WARNING
427
429 template<typename ... TT>
430 inline
431 Logger & warn(const TT &... args){
432 // warn();
433 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::BOLD);
434 initMessage<LOG_WARNING>(notif);
435 flush(args...);
436 return *this;
437 };
438
440 template<int L=LOG_WARNING,typename ... TT>
441 inline
442 Logger & discouraged(const TT &... args){
443 //static const Notification notif(__FUNCTION__, 35);
444 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
445 initMessage<L>(notif);
446 flush(args...);
447 return *this;
448 };
449
450
452 template<int L=LOG_WARNING,typename ... TT>
453 inline
454 Logger & fail(const TT &... args){
455 //static const Notification notif(__FUNCTION__, 33);
456 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
457 initMessage<L>(notif);
458 flush(args...);
459 return *this;
460 };
461
463 // Valid alternative should be displayed.
464 template<int L=LOG_WARNING,typename ... TT>
465 inline
466 Logger & obsolete(const TT &... args){
467 //static const Notification notif(__FUNCTION__, 35);
468 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::DIM, TextStyle::UNDERLINE);
469 initMessage<L>(notif);
470 flush(args...);
471 return *this;
472 };
473
475 template<int L=LOG_WARNING,typename ... TT>
476 inline
477 Logger & attention(const TT &... args){
478 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE); // , TextStyle::DIM); // 46);
479 initMessage<L>(notif);
480 flush(args...);
481 return *this;
482 };
483
484
485 // LOG_NOTICE
486
488 template<typename ... TT>
489 inline
490 Logger & note(const TT &... args){
491 static const Notification notif(__FUNCTION__, TextStyle::BOLD);
492 initMessage<LOG_NOTICE>(notif);
493 //initMessage<LOG_NOTICE>();
494 flush(args...);
495 return *this;
496 };
497
499 template<int L=LOG_NOTICE,typename ... TT>
500 inline
501 Logger & suspicious(const TT &... args){
502 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
503 initMessage<L>(notif);
504 flush(args...);
505 return *this;
506 };
507
508
510 template<int L=LOG_NOTICE,typename ... TT>
511 inline
512 Logger & unimplemented(const TT &... args){
513 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::BOLD); // , 35); // , TextStyle::OVERLINE
514 initMessage<L>(notif);
515 flush(args...);
516 return *this;
517 };
518
520 template<int L=LOG_NOTICE,typename ... TT>
521 inline
522 Logger & deprecating(const TT &... args){
523 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM, TextStyle::UNDERLINE); //33);
524 initMessage<L>(notif);
525 flush(args...);
526 return *this;
527 };
528
530 template<int L=LOG_NOTICE,typename ... TT>
531 inline
532 Logger & special(const TT &... args){
533 static const Notification notif(__FUNCTION__, TextStyle::CYAN); //36);
534 initMessage<L>(notif);
535 flush(args...);
536 return *this;
537 };
538
539
540 template<int L=LOG_NOTICE,typename ... TT>
541 inline
542 Logger & experimental(const TT &... args){
543 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE, TextStyle::DIM); // 94);
544 initMessage<L>(notif);
545 flush(args...);
546 return *this;
547 };
548
549 template<int L=LOG_NOTICE,typename ... TT>
550 inline
551 Logger & advice(const TT &... args){
552 static const Notification notif(__FUNCTION__, TextStyle::Colour::PURPLE);// 40); ,
553 initMessage<L>(notif);
554 flush(args...);
555 return *this;
556 };
557
558
559 // LOG_INFO
560
561 template<typename ... TT>
562 inline
563 Logger & info(const TT &... args){
564 static const Notification notif(__FUNCTION__, TextStyle::WHITE); //32);
565 initMessage<LOG_INFO>(notif);
566 // initMessage<LOG_INFO>();
567 flush(args...);
568 return *this;
569 };
570
571 template<int L=LOG_INFO,typename ... TT>
572 inline
573 Logger & ok(const TT &... args){
574 static const Notification notif(__FUNCTION__, TextStyle::GREEN); //32);
575 initMessage<L>(notif);
576 flush(args...);
577 return *this;
578 };
579
581 template<int L=LOG_INFO,typename ... TT>
582 inline
583 Logger & accept(const TT &... args){
584 //static const Notification notif(__FUNCTION__, 42);
585 static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::REVERSE, TextStyle::DIM);
586 initMessage<L>(notif);
587 flush(args...);
588 return *this;
589 };
590
592
595 template<int L=LOG_INFO,typename ... TT>
596 inline
597 Logger & pending(const TT &... args){
598 //static const Notification notif(__FUNCTION__, 42);
599 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::REVERSE, TextStyle::DIM);
600 initMessage<L>(notif);
601 flush(args...);
602 return *this;
603 };
604
606
609 template<int L=LOG_INFO,typename ... TT>
610 inline
611 Logger & reject(const TT &... args){
612 // static const Notification notif(__FUNCTION__, 41);
613 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE, TextStyle::DIM);
614 initMessage<L>(notif);
615 flush(args...);
616 return *this;
617 };
618
619
621 template<int L=LOG_INFO,typename ... TT>
622 inline
623 Logger & success(const TT &... args){
624 // static const Notification notif(__FUNCTION__, 92);
625 static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::DIM);
626 initMessage<L>(notif);
627 flush(args...);
628 return *this;
629 };
630
631
633 template<int L=LOG_INFO,typename ... TT>
634 inline
635 Logger & hint(const TT &... args){
636 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::DIM, TextStyle::ITALIC);
637 initMessage<L>(notif);
638 flush(args...);
639 return *this;
640 };
641
642
643 template<int L=LOG_INFO,typename ... TT>
644 inline
645 Logger & revised(const TT &... args){
646 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::ITALIC); // , TextStyle::DIM
647 initMessage<L>(notif);
648 flush(args...);
649 return *this;
650 };
651
652
653
655
665 template<typename ... TT>
666 inline
667 Logger & debug(const TT &... args){
668 static const Notification notif(__FUNCTION__, TextStyle::DIM);
669 initMessage<LOG_DEBUG>(notif);
670 flush(args...);
671 return *this;
672 };
673
675 template<typename ... TT>
676 inline
677 Logger & debug2(const TT &... args){
678 static const Notification notif(__FUNCTION__, TextStyle::DIM, TextStyle::ITALIC);
679 initMessage<LOG_DEBUG+1>(notif);
680 flush(args...);
681 return *this;
682 };
683
684 template<typename ... TT>
685 inline
686 Logger & debug3(const TT &... args){
687 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::DIM, TextStyle::ITALIC);
688 initMessage<LOG_DEBUG+2>(notif);
689 flush(args...);
690 return *this;
691 };
692
693
694 inline
695 Logger & log(level_t level){
696 initMessage(level); // avoid
697 return *this;
698 };
699
700 // Experimental! For mout.log(level)(args); !
701 template<typename ... TT>
702 inline
703 Logger & operator()(const TT &... args){
704 flush(args...);
705 return *this;
706 };
707
708
709 static bool TIMING; // = false;
710 static char MARKER;
711
712 bool timing;
713
715 //Logger & timestamp(const std::string & label);
716
720 inline
722 if (TIMING && !timing){
723 initTiming(this->prefix);
724 }
725 };
726
730 template<typename ... TT>
731 void startTiming(const TT &... args){
732 if (TIMING && !timing){ // consider error if already timing?
733 initTiming(args...);
734 }
735 };
736
737 //template<typename ... TT>
738 //void endTiming(const TT &... args){
739 void endTiming(){
740 if (timing){
741 time = monitor.getMilliseconds() - time;
742 std::cerr << "TIMING:" << MARKER << "</div> ";
743 //describeTiming(args...); // STORE timing label?
744 // << ": "
745 std::cerr << "<b>" << (static_cast<float>(time)/1000.0f) << "</b>" << "<br/>" << '\n';
746 /*
747 std::cerr << "TIMING:" << MARKER << "</ol> ";
748 //describeTiming(args...); // STORE timing label?
749 // << ": "
750 std::cerr << "<b>" << (static_cast<float>(time)/1000.0f) << "</b>" << "</li>" << '\n';
751 */
752 timing = false;
753 }
754 }
755
756
757public:
758
759
761 // Logger & timestamp();
762
763
765
766 Logger &operator<<(const std::ostream & sstr) {
767 // TODO if (!message.empty())
768 if (level <= monitor.getVerbosity())
769 message << sstr.rdbuf(); // so simple? See StreamBuilder for additional checks
770 return *this;
771 }
772
773 inline
774 Logger &operator<<(const std::type_info & type) {
775 if (level <= monitor.getVerbosity()){
776 message << Type::call<simpleName>(type);
777 }
778 return *this;
779 }
780
781
782 template <class T>
783 Logger &operator<<(const T & x) {
784 //cerr << "source input:" << x << '\n';
785 if (level <= monitor.getVerbosity())
786 message << x;
787 return *this;
788 }
789
790 typedef void * oper;
791 static oper endl;
792
793
794 inline
795 void end(){
796 monitor.flush(level, *notif_ptr, prefix, message);
797 }
798
800 inline
802 monitor.flush(level, *notif_ptr, prefix, message);
803 return *this; // <- drop this?
804 }
805
807 inline
809
810 if (&l != this){
811 message << " NOTE: Logger" << __FUNCTION__ << " flush with non-this Logger";
812 }
813 monitor.flush(level, *notif_ptr, prefix, message);
814 return *this;
815 }
816
817 inline
818 int getVerbosity() const {
819 return monitor.getVerbosity();
820 };
821
822protected:
823
824 Log & monitor;
825
826 std::string prefix;
827
828 level_t level;
829 time_t time;
830
831 const Notification * notif_ptr;
832
833protected:
834
835 template<typename ... TT>
836 void initTiming(const TT &... args){
837 timing = true; // consider error if already timing?
838 std::cerr << "TIMING:" << MARKER; // << "<li>";
839 describeTiming(args...);
840 // std::cerr << " [" << prefix << "] <ol>" << '\n';
841 //std::cerr << " <ol>" << '\n';
842 std::cerr << " <div>" << '\n';
843 time = monitor.getMilliseconds();
844 };
845
846
847 template<typename T, typename ... TT>
848 void describeTiming(const T & arg, const TT &... args){
849 std::cerr << arg;
850 describeTiming(args...);
851 };
852
853 inline
854 void describeTiming(){
855 };
856
865
872 template<typename ... TT>
873 inline
874 //void setPrefix(const char * filename, const char * func_name, const TT &... args){
875 void setPrefix(const char * filename, const TT &... args){
876
877 std::stringstream sstr;
878
879 if (filename){
880
881 if (*filename != '\0'){
882
883 const char * s2 = strrchr(filename, '/');
884 if (s2 == nullptr)
885 s2 = filename;
886 else
887 ++s2;
888
890 const char * s3 = strrchr(s2, '.');
891 if (s3 == nullptr)
892 sstr << s2;
893 //prefix.assign(s2);
894 else
895 //prefix.assign(s2, s3-s2);
896 sstr.write(s2, size_t(s3-s2));
897 // prefix.append(":");
898 // sstr << ':';
899 }
900 }
901 // NEW sstr << func_name << ": ";
902 //appendPrefix(sstr, func_name, args...);
903 appendPrefix(sstr, args...);
904 prefix = sstr.str();
905 }
906
907 /*
908 template<typename T, typename ... TT>
909 inline
910 void setPrefix(const TT &... args){
911 std::stringstream sstr;
912 appendPrefix(sstr, args...);
913 prefix = sstr.str();
914 }
915 */
916
917
918 inline
919 void appendPrefix(std::stringstream & sstr){
920 }
921
922 template<typename T, typename ... TT>
923 void appendPrefix(std::stringstream & sstr, const T & arg, const TT &... args){
924 sstr << ":" << arg;
925 appendPrefix(sstr, args...);
926 }
927
928 template <level_t L>
929 Logger & initMessage(const Notification & notif){
930 this->notif_ptr = & notif;
931 this->level = L;
932 this->message.str("");
933 return *this;
934 }
935 //void initMessage(level_t level);
936
937 /*
938 template <level_t L>
939 Logger & initMessage(){
940
941 static
942 const Notification & notif = Log::getDict()[L];
943
944 this->notif_ptr = &notif;
945 this->level = L;
946 this->message.str("");
947 return *this;
948 }
949 */
950
952 Logger & initMessage(level_t level);
953
954 /*
955 inline
956 Logger & initMessage(level_t level){
957 static const Notification notif(__FUNCTION__); // TextStyle::DIM, TextStyle::ITALIC);
958 this->notif_ptr = & notif; // Log::getDict()[level];
959 this->level = level;
960 this->message.str("");
961 return *this;
962 }
963 */
964
965 template<typename T, typename ... TT>
966 inline
967 Logger & flush(const T & arg, const TT &... rest){
968 //*this << arg;
969 append(arg);
970 flush(rest...);
971 return *this;
972 };
973
974 template<typename T>
975 inline
976 Logger & flush(const T & arg){
977 // *this << arg;
978 append(arg);
979 monitor.flush(level, *notif_ptr, prefix, message);
980 return *this;
981 };
982
983 inline
984 Logger & flush(){
985 return *this;
986 };
987
988 template<typename T>
989 inline
990 void append(const T & arg){
991 *this << arg;
992 }
993
994 /*
995 inline
996 Logger & flush(){
997 monitor.flush(level, *notif_ptr, prefix, message);
998 return *this;
999 };
1000 */
1001
1002
1003};
1004
1005
1006template <>
1007inline
1008void Logger::append(const TextStyle::Colour & colour){
1009 *this << "<color>";
1010}
1011
1012
1013template <typename ... TT>
1014Logger::Logger(const char *filename, const TT & ...args):
1015 message(*this),
1016 timing(false),
1017 monitor(getLog()),
1018 level(LOG_NOTICE),
1019 time(getLog().getMilliseconds()),
1020 notif_ptr(NULL){
1021 setPrefix(filename, args...);
1022}
1023
1024template <typename ... TT>
1025Logger::Logger(Log &log, const char *filename, const TT & ...args):
1026 message(*this),
1027 timing(false),
1028 monitor(log),
1029 level(LOG_NOTICE),
1030 time(log.getMilliseconds()),
1031 notif_ptr(NULL){
1032 setPrefix(filename, args...);
1033}
1034//std::ostream &operator<<(std::ostream &ostr, const Log &error);
1035
1036
1037}
1038
1039//const std::string FEELU(__FILE__);
1040
1041#endif /* DEBUG_H_ */
1042
1043// Drain
Definition Log.h:288
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:808
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:875
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:1014
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:801
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:54
Definition StringBuilder.h:58
Definition TextStyleVT100.h:45
Definition DataSelector.cpp:1277
Definition Log.h:95