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(name) '#', #name, '=', name 
  314    std::stringstream & message;
 
  327    template <
typename ... TT>
 
  328    Logger(
const char *filename, 
const TT & ...args);
 
  336    template <
typename ... TT>
 
  337    Logger(
Log &log, 
const char *filename, 
const TT & ...args); 
 
  349        return (monitor.getVerbosity() >= l);
 
 
  366    template <
int L, 
typename ... TT>
 
  369        static const Notification notif(__FUNCTION__, TextStyle::DIM); 
 
  370        initMessage<L>(notif);
 
 
  377    template<
typename ... TT>
 
  380        static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::REVERSE, TextStyle::BOLD);
 
  381        initMessage<LOG_EMERG>(notif);
 
 
  387    template<
typename ... TT>
 
  390        static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::BOLD);
 
  391        initMessage<LOG_ALERT>(notif);
 
 
  397    template<
typename ... TT>
 
  400        static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE);
 
  401        initMessage<LOG_CRIT>(notif);
 
 
  414    template<
typename ... TT>
 
  417        static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::BOLD);
 
  419        initMessage<LOG_ERR>(notif);
 
 
  428    template<
typename ... TT>
 
  432        static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::BOLD);
 
  433        initMessage<LOG_WARNING>(notif);
 
 
  439    template<
int L=LOG_WARNING,
typename ... TT>
 
  443        static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
 
  444        initMessage<L>(notif);
 
 
  451    template<
int L=LOG_WARNING,
typename ... TT>
 
  455        static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
 
  456        initMessage<L>(notif);
 
 
  463    template<
int L=LOG_WARNING,
typename ... TT>
 
  467        static const Notification notif(__FUNCTION__, TextStyle::PURPLE, TextStyle::DIM, TextStyle::UNDERLINE);
 
  468        initMessage<L>(notif);
 
 
  474    template<
int L=LOG_WARNING,
typename ... TT>
 
  477        static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE); 
 
  478        initMessage<L>(notif);
 
 
  487    template<
typename ... TT>
 
  490        static const Notification notif(__FUNCTION__, TextStyle::BOLD);
 
  491        initMessage<LOG_NOTICE>(notif);
 
 
  498    template<
int L=LOG_NOTICE,
typename ... TT>
 
  501        static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM);
 
  502        initMessage<L>(notif);
 
 
  509    template<
int L=LOG_NOTICE,
typename ... TT>
 
  512        static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::OVERLINE); 
 
  513        initMessage<L>(notif);
 
 
  519    template<
int L=LOG_NOTICE,
typename ... TT>
 
  522        static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::DIM, TextStyle::UNDERLINE); 
 
  523        initMessage<L>(notif);
 
 
  529    template<
int L=LOG_NOTICE,
typename ... TT>
 
  532        static const Notification notif(__FUNCTION__, TextStyle::CYAN); 
 
  533        initMessage<L>(notif);
 
 
  539    template<
int L=LOG_NOTICE,
typename ... TT>
 
  541    Logger & experimental(
const TT &... args){
 
  542        static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::REVERSE, TextStyle::DIM); 
 
  543        initMessage<L>(notif);
 
  548    template<
int L=LOG_NOTICE,
typename ... TT>
 
  550    Logger & advice(
const TT &... args){
 
  551        static const Notification notif(__FUNCTION__, TextStyle::Colour::PURPLE);
 
  552        initMessage<L>(notif);
 
  560    template<
typename ... TT>
 
  562    Logger & info(
const TT &... args){
 
  563        static const Notification notif(__FUNCTION__, TextStyle::WHITE); 
 
  564        initMessage<LOG_INFO>(notif);
 
  570    template<
int L=LOG_INFO,
typename ... TT>
 
  572    Logger & ok(
const TT &... args){
 
  573        static const Notification notif(__FUNCTION__, TextStyle::GREEN); 
 
  574        initMessage<L>(notif);
 
  580    template<
int L=LOG_INFO,
typename ... TT>
 
  584        static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::REVERSE, TextStyle::DIM);
 
  585        initMessage<L>(notif);
 
 
  594    template<
int L=LOG_INFO,
typename ... TT>
 
  598        static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::REVERSE, TextStyle::DIM);
 
  599        initMessage<L>(notif);
 
 
  608    template<
int L=LOG_INFO,
typename ... TT>
 
  612        static const Notification notif(__FUNCTION__, TextStyle::RED, TextStyle::REVERSE, TextStyle::DIM);
 
  613        initMessage<L>(notif);
 
 
  620    template<
int L=LOG_INFO,
typename ... TT>
 
  624        static const Notification notif(__FUNCTION__, TextStyle::GREEN, TextStyle::DIM);
 
  625        initMessage<L>(notif);
 
 
  632    template<
int L=LOG_INFO,
typename ... TT>
 
  635        static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::DIM, TextStyle::ITALIC);
 
  636        initMessage<L>(notif);
 
 
  642    template<
int L=LOG_INFO,
typename ... TT>
 
  644    Logger & revised(
const TT &... args){
 
  645        static const Notification notif(__FUNCTION__, TextStyle::YELLOW, TextStyle::ITALIC); 
 
  646        initMessage<L>(notif);
 
  664    template<
typename ... TT>
 
  667        static const Notification notif(__FUNCTION__, TextStyle::DIM);
 
  668        initMessage<LOG_DEBUG>(notif);
 
 
  674    template<
typename ... TT>
 
  677        static const Notification notif(__FUNCTION__, TextStyle::DIM, TextStyle::ITALIC);
 
  678        initMessage<LOG_DEBUG+1>(notif);
 
 
  683    template<
typename ... TT>
 
  685    Logger & debug3(
const TT &... args){
 
  686        static const Notification notif(__FUNCTION__, TextStyle::CYAN, TextStyle::DIM, TextStyle::ITALIC);
 
  687        initMessage<LOG_DEBUG+2>(notif);
 
  694    Logger & log(level_t level){
 
  700    template<
typename ... TT>
 
  702    Logger & operator()(
const TT &... args){
 
  721        if (TIMING && !timing){
 
  722            initTiming(this->prefix);
 
 
  729    template<
typename ... TT>
 
  731        if (TIMING && !timing){  
 
 
  740            time = monitor.getMilliseconds() - time;
 
  741            std::cerr << 
"TIMING:" << MARKER << 
"</div> ";
 
  744            std::cerr << 
"<b>"  << (
static_cast<float>(time)/1000.0f) << 
"</b>" << 
"<br/>" << 
'\n';
 
  767        if (level <= monitor.getVerbosity())
 
  768            message << sstr.rdbuf(); 
 
 
  774        if (level <= monitor.getVerbosity())
 
  775            message << Type::call<simpleName>(type);
 
  783        if (level <= monitor.getVerbosity())
 
  794        monitor.flush(level, *notif_ptr, prefix, message);
 
  800        monitor.flush(level, *notif_ptr, prefix, message);
 
 
  809            message << 
" NOTE: Logger" << __FUNCTION__ << 
" flush with non-this Logger";
 
  811        monitor.flush(level, *notif_ptr, prefix, message);
 
 
  816    int getVerbosity()
 const {
 
  817        return monitor.getVerbosity();
 
  829    const Notification * notif_ptr;
 
  833    template<
typename ... TT>
 
  834    void initTiming(
const TT &... args){
 
  836        std::cerr << 
"TIMING:" << MARKER; 
 
  837        describeTiming(args...);
 
  840        std::cerr << 
" <div>" << 
'\n';
 
  841        time = monitor.getMilliseconds();
 
  845    template<
typename T, 
typename ... TT>
 
  846    void describeTiming(
const T & arg, 
const TT &... args){
 
  848        describeTiming(args...);
 
  852    void describeTiming(){
 
  870    template<
typename ... TT>
 
  873    void setPrefix(
const char * filename, 
const TT &... args){
 
  875        std::stringstream sstr;
 
  879            if (*filename != 
'\0'){
 
  881                const char * s2 = strrchr(filename, 
'/');
 
  888                const char * s3 = strrchr(s2, 
'.');
 
  894                    sstr.write(s2, 
size_t(s3-s2));
 
  901        appendPrefix(sstr, args...);
 
 
  917    void appendPrefix(std::stringstream & sstr){
 
  920    template<
typename T, 
typename ... TT>
 
  921    void appendPrefix(std::stringstream & sstr, 
const T & arg, 
const TT &... args){
 
  923        appendPrefix(sstr, args...);
 
  927    Logger & initMessage(
const Notification & notif){
 
  928        this->notif_ptr = & notif;
 
  930        this->message.str(
"");
 
  950    Logger & initMessage(level_t level);
 
  963    template<
typename T, 
typename ... TT>
 
  965    Logger & flush(
const T & arg, 
const TT &... rest){
 
  974    Logger & flush(
const T & arg){
 
  977        monitor.flush(level, *notif_ptr, prefix, message);
 
  988    void append(
const T & arg){
 
 
 1006void Logger::append(
const TextStyle::Colour & colour){
 
 1011template <
typename ... TT>
 
 1017                time(getLog().getMilliseconds()),
 
 
 1022template <
typename ... TT>
 
 1028                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: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