TwiceAsNice
2019-02-18
|
Log is an easy to use thread safe logging library, with 9 levels of logging (Nice::LFATAL, Nice::LERROR, Nice::LWARNING, Nice::LINFO, Nice::LNOTICE, Nice::LDEBUG). 3 classes of log macros, plain string logging, c++ iostream logging and optional output redirection. More...
#include <Stream.h>
Log is an easy to use thread safe logging library, with 9 levels of logging (Nice::LFATAL, Nice::LERROR, Nice::LWARNING, Nice::LINFO, Nice::LNOTICE, Nice::LDEBUG). 3 classes of log macros, plain string logging, c++ iostream logging and optional output redirection.
#define Nice::LDEBUG // all loglevels #define NICE_DEBUG // Nice::LFATAL, Nice::LALERT, Nice::LCRITICAL, Nice::LERROR, Nice::LWARNING, Nice::LNOTICE, Nice::LINFO, Nice::LDEBUG #define NICE_LOG_DEBUGLEVEL7 // Nice::LFATAL, Nice::LALERT, Nice::LCRITICAL, Nice::LERROR, Nice::LWARNING, Nice::LNOTICE, Nice::LINFO #define NICE_LOG_DEBUGLEVEL6 // Nice::LFATAL, Nice::LALERT, Nice::LCRITICAL, Nice::LERROR, Nice::LWARNING, Nice::LNOTICE #define NICE_LOG_DEBUGLEVEL5 // Nice::LFATAL, Nice::LALERT, Nice::LCRITICAL, Nice::LERROR, Nice::LWARNING #define NICE_LOG_DEBUGLEVEL4 // Nice::LFATAL, Nice::LALERT, Nice::LCRITICAL, Nice::LERROR #define NICE_LOG_DEBUGLEVEL3 // Nice::LFATAL, Nice::LALERT, Nice::LCRITICAL #define NICE_LOG_DEBUGLEVEL2 // Nice::LFATAL, Nice::LALERT #define NICE_LOG_DEBUGLEVEL1 // Nice::LFATAL
The following code snippet illustrates using the log macros:
#include "niceLog.h" using namespace Nice; int main(int argc , char ** argv ) { T_QLOG("something to print"); U9_QLOG("something to print"); U8_QLOG("something to print"); U7_QLOG("something to print"); U6_QLOG("something to print"); U5_QLOG("something to print"); U4_QLOG("something to print"); U3_QLOG("something to print"); U2_QLOG("something to print"); U1_QLOG("something to print"); D_QLOG("something to print"); I_QLOG("something to print"); N_QLOG("something to print"); W_QLOG("something to print"); E_QLOG("something to print"); C_QLOG("something to print"); A_QLOG("something to print"); F_QLOG("something to print"); F_LOG("log log log " << 1 << "..."); A_LOG("log log log " << 2 << "..."); C_LOG("log log log " << 3 << "..."); E_LOG("log log log " << 4 << "..."); W_LOG("log log log " << 5 << "..."); N_LOG("log log log " << 6 << "..."); I_LOG("log log log " << 7 << "..."); D_LOG("log log log " << 8 << "..."); U1_LOG("log log log " << 9 << "..."); U2_LOG("log log log " << 10 << "..."); U3_LOG("log log log " << 11 << "..."); U4_LOG("log log log " << 12 << "..."); U5_LOG("log log log " << 13 << "..."); U6_LOG("log log log " << 14 << "..."); U7_LOG("log log log " << 15 << "..."); U8_LOG("log log log " << 16 << "..."); U9_LOG("log log log " << 17 << "..."); T_LOG("log log log " << 18 << "..."); F_ASSERT(false, "no its false"); A_ASSERT(false, "no its false"); C_ASSERT(1 == 2, "no its false"); E_ASSERT(false, "no its false"); W_ASSERT(false, "no its false"); N_ASSERT(1 == 2, "no its false"); I_ASSERT(false, "no its false"); D_ASSERT(false, "no its false"); T_ASSERT(1 == 2, "no its false"); F_ASSERT(1 == 1, "yes its true"); A_ASSERT(true, "yes its true"); C_ASSERT(true, "yes its true"); E_ASSERT(1 != 2, "yes its true"); W_ASSERT(true, "yes its true"); N_ASSERT(true, "yes its true"); I_ASSERT(1 == 1, "yes its true"); D_ASSERT(true, "yes its true"); T_ASSERT(true, "yes its true"); // redirect output to file and use mono logtype text s_stdout.setFile(::fopen("/tmp/test.log","w+")); s_stdout.setTypeStr(s_stdout.typeStr); F_LOG("log log log " << 1 << "..."); E_LOG("log log log " << 2 << "..."); W_LOG("log log log " << 3 << "..."); I_LOG("log log log " << 4 << "..."); N_LOG("log log log " << 5 << "..."); D_LOG("log log log " << 6 << "..."); // redirect output back to stderr and set min loglevel to Nice::LWARNING s_stdout.setFile(stderr); s_stdout.setLogLevel(Nice::LWARNING); F_LOG("log log log " << 1 << "..."); A_LOG("log log log " << 2 << "..."); C_LOG("log log log " << 3 << "..."); E_LOG("log log log " << 4 << "..."); W_LOG("log log log " << 5 << "..."); N_LOG("log log log " << 6 << "..."); I_LOG("log log log " << 7 << "..."); D_LOG("log log log " << 8 << "..."); T_LOG("log log log " << 9 << "..."); }
#define Nice::LDEBUG // all loglevels #define NICE_DEBUG // Nice::LFATAL, Nice::LALERT, Nice::LCRITICAL, Nice::LERROR, Nice::LWARNING, Nice::LNOTICE, Nice::LINFO, Nice::LDEBUG #define NICE_LOG_DEBUGLEVEL7 // Nice::LFATAL, Nice::LALERT, Nice::LCRITICAL, Nice::LERROR, Nice::LWARNING, Nice::LNOTICE, Nice::LINFO #define NICE_LOG_DEBUGLEVEL6 // Nice::LFATAL, Nice::LALERT, Nice::LCRITICAL, Nice::LERROR, Nice::LWARNING, Nice::LNOTICE #define NICE_LOG_DEBUGLEVEL5 // Nice::LFATAL, Nice::LALERT, Nice::LCRITICAL, Nice::LERROR, Nice::LWARNING #define NICE_LOG_DEBUGLEVEL4 // Nice::LFATAL, Nice::LALERT, Nice::LCRITICAL, Nice::LERROR #define NICE_LOG_DEBUGLEVEL3 // Nice::LFATAL, Nice::LALERT, Nice::LCRITICAL #define NICE_LOG_DEBUGLEVEL2 // Nice::LFATAL, Nice::LALERT #define NICE_LOG_DEBUGLEVEL1 // Nice::LFATAL
The following code snippet illustrates using the log macros:
#include "niceLog.h" using namespace Nice; int main(int argc , char ** argv ) { T_QLOG("something to print"); U9_QLOG("something to print"); U8_QLOG("something to print"); U7_QLOG("something to print"); U6_QLOG("something to print"); U5_QLOG("something to print"); U4_QLOG("something to print"); U3_QLOG("something to print"); U2_QLOG("something to print"); U1_QLOG("something to print"); D_QLOG("something to print"); I_QLOG("something to print"); N_QLOG("something to print"); W_QLOG("something to print"); E_QLOG("something to print"); C_QLOG("something to print"); A_QLOG("something to print"); F_QLOG("something to print"); F_LOG("log log log " << 1 << "..."); A_LOG("log log log " << 2 << "..."); C_LOG("log log log " << 3 << "..."); E_LOG("log log log " << 4 << "..."); W_LOG("log log log " << 5 << "..."); N_LOG("log log log " << 6 << "..."); I_LOG("log log log " << 7 << "..."); D_LOG("log log log " << 8 << "..."); U1_LOG("log log log " << 9 << "..."); U2_LOG("log log log " << 10 << "..."); U3_LOG("log log log " << 11 << "..."); U4_LOG("log log log " << 12 << "..."); U5_LOG("log log log " << 13 << "..."); U6_LOG("log log log " << 14 << "..."); U7_LOG("log log log " << 15 << "..."); U8_LOG("log log log " << 16 << "..."); U9_LOG("log log log " << 17 << "..."); T_LOG("log log log " << 18 << "..."); F_ASSERT(false, "no its false"); A_ASSERT(false, "no its false"); C_ASSERT(1 == 2, "no its false"); E_ASSERT(false, "no its false"); W_ASSERT(false, "no its false"); N_ASSERT(1 == 2, "no its false"); I_ASSERT(false, "no its false"); D_ASSERT(false, "no its false"); T_ASSERT(1 == 2, "no its false"); F_ASSERT(1 == 1, "yes its true"); A_ASSERT(true, "yes its true"); C_ASSERT(true, "yes its true"); E_ASSERT(1 != 2, "yes its true"); W_ASSERT(true, "yes its true"); N_ASSERT(true, "yes its true"); I_ASSERT(1 == 1, "yes its true"); D_ASSERT(true, "yes its true"); T_ASSERT(true, "yes its true"); // redirect output to file and use mono logtype text s_stdout.setFile(::fopen("/tmp/test.log","w+")); s_stdout.setTypeStr(s_stdout.typeStr); F_LOG("log log log " << 1 << "..."); E_LOG("log log log " << 2 << "..."); W_LOG("log log log " << 3 << "..."); I_LOG("log log log " << 4 << "..."); N_LOG("log log log " << 5 << "..."); D_LOG("log log log " << 6 << "..."); // redirect output back to stderr and set min loglevel to Nice::LWARNING s_stdout.setFile(stderr); s_stdout.setLogLevel(Nice::LWARNING); F_LOG("log log log " << 1 << "..."); A_LOG("log log log " << 2 << "..."); C_LOG("log log log " << 3 << "..."); E_LOG("log log log " << 4 << "..."); W_LOG("log log log " << 5 << "..."); N_LOG("log log log " << 6 << "..."); I_LOG("log log log " << 7 << "..."); D_LOG("log log log " << 8 << "..."); T_LOG("log log log " << 9 << "..."); }