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_VAR(name) '#', #name, '=', name
304
305
306
308
311//class Logger : public std::stringstream {
312class Logger : public StreamBuilder<0> {
313
314 std::stringstream & message;
315
316public:
317
318
319
320 typedef Log::level_t level_t;
321
323
327 template <typename ... TT>
328 Logger(const char *filename, const TT & ...args);
329 //Logger(const char *filename, const std::string & name = "");
330
332
336 template <typename ... TT>
337 Logger(Log &log, const char *filename, const TT & ...args); //const char *className = NULL);
338 //Logger(Log &log, const char *filename, const std::string & name = ""); //const char *className = NULL);
339
340 ~Logger();
341
343
347 inline
348 bool isLevel(level_t l){
349 return (monitor.getVerbosity() >= l);
350 };
351
353
357 inline
358 bool isDebug(level_t l=0){
359 return isLevel(LOG_DEBUG+l);
360 //return (monitor.getVerbosity() >= (LOG_DEBUG+l));
361 };
362
363
364
366 template <int L, typename ... TT>
367 inline
368 Logger & start(const TT &... args){
369 static const Notification notif(__FUNCTION__, TextStyle::DIM); //, TextStyle::BOLD
370 initMessage<L>(notif);
371 flush(args...);
372 return *this;
373 };
374
375
377 template<typename ... TT>
378 inline
379 Logger & quit(const TT &... args){
380 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::REVERSE, TextStyle::BOLD);
381 initMessage<LOG_EMERG>(notif);
382 flush(args...);
383 return *this;
384 };
385
387 template<typename ... TT>
388 inline
389 Logger & alert(const TT &... args){
390 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::BOLD);
391 initMessage<LOG_ALERT>(notif);
392 flush(args...);
393 return *this;
394 };
395
397 template<typename ... TT>
398 inline
399 Logger & critical(const TT &... args){
400 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE);
401 initMessage<LOG_CRIT>(notif);
402 flush(args...);
403 return *this;
404 };
405
407 /*
408 inline
409 Logger & error(){
410 return initMessage<LOG_ERR>();
411 };
412 */
413
414 template<typename ... TT>
415 inline
416 Logger & error(const TT &... args){
417 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::BOLD);
418 // error();
419 initMessage<LOG_ERR>(notif);
420 flush(args...);
421 return *this;
422 };
423
424
425 // LOG_WARNING
426
428 template<typename ... TT>
429 inline
430 Logger & warn(const TT &... args){
431 // warn();
432 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::BOLD);
433 initMessage<LOG_WARNING>(notif);
434 flush(args...);
435 return *this;
436 };
437
439 template<int L=LOG_WARNING,typename ... TT>
440 inline
441 Logger & discouraged(const TT &... args){
442 //static const Notification notif(__FUNCTION__, 35);
443 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
444 initMessage<L>(notif);
445 flush(args...);
446 return *this;
447 };
448
449
451 template<int L=LOG_WARNING,typename ... TT>
452 inline
453 Logger & fail(const TT &... args){
454 //static const Notification notif(__FUNCTION__, 33);
455 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
456 initMessage<L>(notif);
457 flush(args...);
458 return *this;
459 };
460
462 // Valid alternative should be displayed.
463 template<int L=LOG_WARNING,typename ... TT>
464 inline
465 Logger & obsolete(const TT &... args){
466 //static const Notification notif(__FUNCTION__, 35);
467 static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::DIM, TextStyle::UNDERLINE);
468 initMessage<L>(notif);
469 flush(args...);
470 return *this;
471 };
472
474 template<int L=LOG_WARNING,typename ... TT>
475 inline
476 Logger & attention(const TT &... args){
477 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE, TextStyle::DIM); // 46);
478 initMessage<L>(notif);
479 flush(args...);
480 return *this;
481 };
482
483
484 // LOG_NOTICE
485
487 template<typename ... TT>
488 inline
489 Logger & note(const TT &... args){
490 static const Notification notif(__FUNCTION__, TextStyle::BOLD);
491 initMessage<LOG_NOTICE>(notif);
492 //initMessage<LOG_NOTICE>();
493 flush(args...);
494 return *this;
495 };
496
498 template<int L=LOG_NOTICE,typename ... TT>
499 inline
500 Logger & suspicious(const TT &... args){
501 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
502 initMessage<L>(notif);
503 flush(args...);
504 return *this;
505 };
506
507
509 template<int L=LOG_NOTICE,typename ... TT>
510 inline
511 Logger & unimplemented(const TT &... args){
512 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::OVERLINE); // , 35);
513 initMessage<L>(notif);
514 flush(args...);
515 return *this;
516 };
517
519 template<int L=LOG_NOTICE,typename ... TT>
520 inline
521 Logger & deprecating(const TT &... args){
522 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM, TextStyle::UNDERLINE); //33);
523 initMessage<L>(notif);
524 flush(args...);
525 return *this;
526 };
527
529 template<int L=LOG_NOTICE,typename ... TT>
530 inline
531 Logger & special(const TT &... args){
532 static const Notification notif(__FUNCTION__, TextStyle::CYAN); //36);
533 initMessage<L>(notif);
534 flush(args...);
535 return *this;
536 };
537
538
539 template<int L=LOG_NOTICE,typename ... TT>
540 inline
541 Logger & experimental(const TT &... args){
542 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE); // 94);
543 initMessage<L>(notif);
544 flush(args...);
545 return *this;
546 };
547
548 template<int L=LOG_NOTICE,typename ... TT>
549 inline
550 Logger & advice(const TT &... args){
551 static const Notification notif(__FUNCTION__, TextStyle::UNDERLINE);// 40);
552 initMessage<L>(notif);
553 flush(args...);
554 return *this;
555 };
556
557
558 // LOG_INFO
559
560 template<typename ... TT>
561 inline
562 Logger & info(const TT &... args){
563 static const Notification notif(__FUNCTION__, TextStyle::WHITE); //32);
564 initMessage<LOG_INFO>(notif);
565 // initMessage<LOG_INFO>();
566 flush(args...);
567 return *this;
568 };
569
570 template<int L=LOG_INFO,typename ... TT>
571 inline
572 Logger & ok(const TT &... args){
573 static const Notification notif(__FUNCTION__, TextStyle::GREEN); //32);
574 initMessage<L>(notif);
575 flush(args...);
576 return *this;
577 };
578
580 template<int L=LOG_INFO,typename ... TT>
581 inline
582 Logger & accept(const TT &... args){
583 //static const Notification notif(__FUNCTION__, 42);
584 static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::REVERSE, TextStyle::DIM);
585 initMessage<L>(notif);
586 flush(args...);
587 return *this;
588 };
589
591
594 template<int L=LOG_INFO,typename ... TT>
595 inline
596 Logger & pending(const TT &... args){
597 //static const Notification notif(__FUNCTION__, 42);
598 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::REVERSE, TextStyle::DIM);
599 initMessage<L>(notif);
600 flush(args...);
601 return *this;
602 };
603
605
608 template<int L=LOG_INFO,typename ... TT>
609 inline
610 Logger & reject(const TT &... args){
611 // static const Notification notif(__FUNCTION__, 41);
612 static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE, TextStyle::DIM);
613 initMessage<L>(notif);
614 flush(args...);
615 return *this;
616 };
617
618
620 template<int L=LOG_INFO,typename ... TT>
621 inline
622 Logger & success(const TT &... args){
623 // static const Notification notif(__FUNCTION__, 92);
624 static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::DIM);
625 initMessage<L>(notif);
626 flush(args...);
627 return *this;
628 };
629
630
632 template<int L=LOG_INFO,typename ... TT>
633 inline
634 Logger & hint(const TT &... args){
635 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::DIM, TextStyle::ITALIC);
636 initMessage<L>(notif);
637 flush(args...);
638 return *this;
639 };
640
641
642 template<int L=LOG_INFO,typename ... TT>
643 inline
644 Logger & revised(const TT &... args){
645 static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::ITALIC); // , TextStyle::DIM
646 initMessage<L>(notif);
647 flush(args...);
648 return *this;
649 };
650
651
652
654
664 template<typename ... TT>
665 inline
666 Logger & debug(const TT &... args){
667 static const Notification notif(__FUNCTION__, TextStyle::DIM);
668 initMessage<LOG_DEBUG>(notif);
669 flush(args...);
670 return *this;
671 };
672
674 template<typename ... TT>
675 inline
676 Logger & debug2(const TT &... args){
677 static const Notification notif(__FUNCTION__, TextStyle::DIM, TextStyle::ITALIC);
678 initMessage<LOG_DEBUG+1>(notif);
679 flush(args...);
680 return *this;
681 };
682
683 template<typename ... TT>
684 inline
685 Logger & debug3(const TT &... args){
686 static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::DIM, TextStyle::ITALIC);
687 initMessage<LOG_DEBUG+2>(notif);
688 flush(args...);
689 return *this;
690 };
691
692
693 inline
694 Logger & log(level_t level){
695 initMessage(level); // avoid
696 return *this;
697 };
698
699 // Experimental! For mout.log(level)(args); !
700 template<typename ... TT>
701 inline
702 Logger & operator()(const TT &... args){
703 flush(args...);
704 return *this;
705 };
706
707
708 static bool TIMING; // = false;
709 static char MARKER;
710
711 bool timing;
712
714 //Logger & timestamp(const std::string & label);
715
719 inline
721 if (TIMING && !timing){
722 initTiming(this->prefix);
723 }
724 };
725
729 template<typename ... TT>
730 void startTiming(const TT &... args){
731 if (TIMING && !timing){ // consider error if already timing?
732 initTiming(args...);
733 }
734 };
735
736 //template<typename ... TT>
737 //void endTiming(const TT &... args){
738 void endTiming(){
739 if (timing){
740 time = monitor.getMilliseconds() - time;
741 std::cerr << "TIMING:" << MARKER << "</div> ";
742 //describeTiming(args...); // STORE timing label?
743 // << ": "
744 std::cerr << "<b>" << (static_cast<float>(time)/1000.0f) << "</b>" << "<br/>" << '\n';
745 /*
746 std::cerr << "TIMING:" << MARKER << "</ol> ";
747 //describeTiming(args...); // STORE timing label?
748 // << ": "
749 std::cerr << "<b>" << (static_cast<float>(time)/1000.0f) << "</b>" << "</li>" << '\n';
750 */
751 timing = false;
752 }
753 }
754
755
756public:
757
758
760 // Logger & timestamp();
761
762
764
765 Logger &operator<<(const std::ostream & sstr) {
766 // TODO if (!message.empty())
767 if (level <= monitor.getVerbosity())
768 message << sstr.rdbuf(); // so simple? See StreamBuilder for additional checks
769 return *this;
770 }
771
772 inline
773 Logger &operator<<(const std::type_info & type) {
774 if (level <= monitor.getVerbosity())
775 message << Type::call<simpleName>(type);
776 return *this;
777 }
778
779
780 template <class T>
781 Logger &operator<<(const T & x) {
782 //cerr << "source input:" << x << '\n';
783 if (level <= monitor.getVerbosity())
784 message << x;
785 return *this;
786 }
787
788 typedef void * oper;
789 static oper endl;
790
791
792 inline
793 void end(){
794 monitor.flush(level, *notif_ptr, prefix, message);
795 }
796
798 inline
800 monitor.flush(level, *notif_ptr, prefix, message);
801 return *this; // <- drop this?
802 }
803
805 inline
807
808 if (&l != this){
809 message << " NOTE: Logger" << __FUNCTION__ << " flush with non-this Logger";
810 }
811 monitor.flush(level, *notif_ptr, prefix, message);
812 return *this;
813 }
814
815 inline
816 int getVerbosity() const {
817 return monitor.getVerbosity();
818 };
819
820protected:
821
822 Log & monitor;
823
824 std::string prefix;
825
826 level_t level;
827 time_t time;
828
829 const Notification * notif_ptr;
830
831protected:
832
833 template<typename ... TT>
834 void initTiming(const TT &... args){
835 timing = true; // consider error if already timing?
836 std::cerr << "TIMING:" << MARKER; // << "<li>";
837 describeTiming(args...);
838 // std::cerr << " [" << prefix << "] <ol>" << '\n';
839 //std::cerr << " <ol>" << '\n';
840 std::cerr << " <div>" << '\n';
841 time = monitor.getMilliseconds();
842 };
843
844
845 template<typename T, typename ... TT>
846 void describeTiming(const T & arg, const TT &... args){
847 std::cerr << arg;
848 describeTiming(args...);
849 };
850
851 inline
852 void describeTiming(){
853 };
854
863
870 template<typename ... TT>
871 inline
872 //void setPrefix(const char * filename, const char * func_name, const TT &... args){
873 void setPrefix(const char * filename, const TT &... args){
874
875 std::stringstream sstr;
876
877 if (filename){
878
879 if (*filename != '\0'){
880
881 const char * s2 = strrchr(filename, '/');
882 if (s2 == nullptr)
883 s2 = filename;
884 else
885 ++s2;
886
888 const char * s3 = strrchr(s2, '.');
889 if (s3 == nullptr)
890 sstr << s2;
891 //prefix.assign(s2);
892 else
893 //prefix.assign(s2, s3-s2);
894 sstr.write(s2, size_t(s3-s2));
895 // prefix.append(":");
896 // sstr << ':';
897 }
898 }
899 // NEW sstr << func_name << ": ";
900 //appendPrefix(sstr, func_name, args...);
901 appendPrefix(sstr, args...);
902 prefix = sstr.str();
903 }
904
905 /*
906 template<typename T, typename ... TT>
907 inline
908 void setPrefix(const TT &... args){
909 std::stringstream sstr;
910 appendPrefix(sstr, args...);
911 prefix = sstr.str();
912 }
913 */
914
915
916 inline
917 void appendPrefix(std::stringstream & sstr){
918 }
919
920 template<typename T, typename ... TT>
921 void appendPrefix(std::stringstream & sstr, const T & arg, const TT &... args){
922 sstr << ":" << arg;
923 appendPrefix(sstr, args...);
924 }
925
926 template <level_t L>
927 Logger & initMessage(const Notification & notif){
928 this->notif_ptr = & notif;
929 this->level = L;
930 this->message.str("");
931 return *this;
932 }
933 //void initMessage(level_t level);
934
935 /*
936 template <level_t L>
937 Logger & initMessage(){
938
939 static
940 const Notification & notif = Log::getDict()[L];
941
942 this->notif_ptr = &notif;
943 this->level = L;
944 this->message.str("");
945 return *this;
946 }
947 */
948
950 Logger & initMessage(level_t level);
951
952 /*
953 inline
954 Logger & initMessage(level_t level){
955 static const Notification notif(__FUNCTION__); // TextStyle::DIM, TextStyle::ITALIC);
956 this->notif_ptr = & notif; // Log::getDict()[level];
957 this->level = level;
958 this->message.str("");
959 return *this;
960 }
961 */
962
963 template<typename T, typename ... TT>
964 inline
965 Logger & flush(const T & arg, const TT &... rest){
966 //*this << arg;
967 append(arg);
968 flush(rest...);
969 return *this;
970 };
971
972 template<typename T>
973 inline
974 Logger & flush(const T & arg){
975 // *this << arg;
976 append(arg);
977 monitor.flush(level, *notif_ptr, prefix, message);
978 return *this;
979 };
980
981 inline
982 Logger & flush(){
983 return *this;
984 };
985
986 template<typename T>
987 inline
988 void append(const T & arg){
989 *this << arg;
990 }
991
992 /*
993 inline
994 Logger & flush(){
995 monitor.flush(level, *notif_ptr, prefix, message);
996 return *this;
997 };
998 */
999
1000
1001};
1002
1003
1004template <>
1005inline
1006void Logger::append(const TextStyle::Colour & colour){
1007 *this << "<color>";
1008}
1009
1010
1011template <typename ... TT>
1012Logger::Logger(const char *filename, const TT & ...args):
1013 message(*this),
1014 timing(false),
1015 monitor(getLog()),
1016 level(LOG_NOTICE),
1017 time(getLog().getMilliseconds()),
1018 notif_ptr(NULL){
1019 setPrefix(filename, args...);
1020}
1021
1022template <typename ... TT>
1023Logger::Logger(Log &log, const char *filename, const TT & ...args):
1024 message(*this),
1025 timing(false),
1026 monitor(log),
1027 level(LOG_NOTICE),
1028 time(log.getMilliseconds()),
1029 notif_ptr(NULL){
1030 setPrefix(filename, args...);
1031}
1032//std::ostream &operator<<(std::ostream &ostr, const Log &error);
1033
1034
1035}
1036
1037//const std::string FEELU(__FILE__);
1038
1039#endif /* DEBUG_H_ */
1040
1041// 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:312
Logger & start(const TT &... args)
General.
Definition Log.h:368
Logger & operator<<(const std::ostream &sstr)
Send a longer [INFO] preceded with a time stamp.
Definition Log.h:765
Logger & discouraged(const TT &... args)
Warning on user's convention or action that can potentially cause errors or confusions.
Definition Log.h:441
Logger & pending(const TT &... args)
Report a conditional accept/reject, to be completed next.
Definition Log.h:596
Logger & operator<<(const Logger &l)
NEW: sending "mout" insread of "mout.endl" Handling flush operator.
Definition Log.h:806
bool isDebug(level_t l=0)
Returns true, if the debug level of the monitor is at least l.
Definition Log.h:358
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:430
Logger & success(const TT &... args)
Some processing step has completed with desired result.
Definition Log.h:622
Logger & alert(const TT &... args)
Quits immediately, dumps pending messages.
Definition Log.h:389
void setPrefix(const char *filename, const TT &... args)
Sets a label that starts every line in the log.
Definition Log.h:873
Logger & obsolete(const TT &... args)
Feature has been removed. Special type of Logger::warn().
Definition Log.h:465
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:666
Logger & quit(const TT &... args)
Quits immediately, dumps pending messages.
Definition Log.h:379
Logger & note(const TT &... args)
For top-level information.
Definition Log.h:489
Logger & hint(const TT &... args)
Like advice, but weaker.
Definition Log.h:634
void startTiming(const TT &... args)
Definition Log.h:730
void startTiming()
Send a short [INFO] preceded with a time stamp.
Definition Log.h:720
Logger & critical(const TT &... args)
Quits immediately, dumps pending messages.
Definition Log.h:399
Logger & special(const TT &... args)
Other useful information.
Definition Log.h:531
Logger & reject(const TT &... args)
Some input has been rejected, for example by a syntax.
Definition Log.h:610
Logger & fail(const TT &... args)
Possible error, but execution can continue. Special type of Logger::warn().
Definition Log.h:453
bool isLevel(level_t l)
Returns true, if the log monitor level is at least l.
Definition Log.h:348
Logger & attention(const TT &... args)
Possible error, but execution can continue. Special type of Logger::warn().
Definition Log.h:476
Logger(const char *filename, const TT &...args)
Start logging,.
Definition Log.h:1012
Logger & error(const TT &... args)
Echoes.
Definition Log.h:416
Logger & suspicious(const TT &... args)
A weak warning about something going possibly wrong.
Definition Log.h:500
Logger & accept(const TT &... args)
Some input has been accepted, for example by a syntax.
Definition Log.h:582
Logger & operator<<(oper op)
Handling flush operator.
Definition Log.h:799
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition Log.h:511
Logger & deprecating(const TT &... args)
Feature will be removed. Special type of Logger::note().
Definition Log.h:521
Logger & debug2(const TT &... args)
Debug information.
Definition Log.h:676
Definition StreamBuilder.h:53
Definition StringBuilder.h:58
Definition TextStyleVT100.h:45
Definition DataSelector.cpp:1277
Definition Log.h:95