00001
00002
00003
00004
00005
00006
00008 #include "MessageService/MsgService.h"
00009
00010
00011
00012
00013
00014
00015
00016 CVSID("$Id: TestDemo.cxx,v 1.3 2006/10/28 05:07:14 gmieg Exp $");
00017
00018
00019
00020 static void theBasics()
00021 {
00022
00023
00024
00025
00026
00027
00028 try {
00029 MSG("Bsx", Msg::kVerbose) << "This is a VERBOSE message\n";
00030 MSG("Bsx", Msg::kDebug) << "This is a DEBUG message\n";
00031 MSG("Bsx", Msg::kInfo) << "This is an INFO message\n";
00032 MSG("Bsx", Msg::kWarning) << "This is a WARNING message\n";
00033 MSG("Bsx", Msg::kError) << "This is an ERROR message\n";
00034 MSG("Bsx", Msg::kFatal) << "This is a FATAL message\n";
00035 }
00036 catch(MSGException) {
00037 cerr << endl << endl;
00038 cerr << "***************** MSGException *****************" << endl;
00039 cerr << "******** MSGException caught (TestDemo) ********" << endl;
00040 cerr << "***************** MSGException *****************" << endl;
00041 cerr << endl;
00042 MSG("Bsx", Msg::kError) << "This is a FATAL message\n";
00043 }
00044 }
00045
00046
00047
00048 static void fancyStuff()
00049
00050
00051
00052 {
00053
00054
00055 MsgService* msvc = MsgService::Instance();
00056 MsgStream* mstr = msvc->GetStream("Fan");
00057
00058
00059
00060 mstr->SetLogLevel(Msg::kDebug);
00061
00062
00063
00064
00065
00066 mstr->AttachOStream(Msg::kVerbose, "cerr");
00067 mstr->AttachOStream(Msg::kInfo, "cout");
00068
00069
00070
00071
00072
00073 mstr->SetFormat(Msg::kVerbose, Msg::kPriority + Msg::kName);
00074
00075
00076 mstr->AddFormat(Msg::kWarning, Msg::kTime);
00077
00078
00079 mstr->RemoveFormat(Msg::kWarning, Msg::kName);
00080 }
00081
00082
00083
00084 static void fancyMessages()
00085 {
00086
00087
00088
00089
00090
00091 try {
00092 MSG("Fan", Msg::kVerbose) << "This is a VERBOSE message\n";
00093 MSG("Fan", Msg::kDebug) << "This is a DEBUG message\n";
00094 MSG("Fan", Msg::kInfo) << "This is an INFO message\n";
00095 MSG("Fan", Msg::kWarning) << "This is a WARNING message\n";
00096 MSG("Fan", Msg::kError) << "This is an ERROR message\n";
00097 MSG("Fan", Msg::kFatal) << "This is a FATAL message\n";
00098 }
00099 catch(MSGException) {
00100 cerr << endl << endl;
00101 cerr << "***************** MSGException *****************" << endl;
00102 cerr << "******** MSGException caught (TestDemo) ********" << endl;
00103 cerr << "***************** MSGException *****************" << endl;
00104 cerr << endl;
00105 MSG("Fan", Msg::kError) << "This is a FATAL message\n";
00106 }
00107 }
00108
00109
00110
00111 static void manyMessageExample()
00112 {
00113
00114
00115
00116
00117 MsgStream *m1 = &MSGSTREAM("Mny", Msg::kError);
00118 (*m1) << " ===== *\n";
00119 (*m1) << "* Messages like this can save a little time and typing. *\n";
00120 (*m1) << "* However, notice that only one header gets printed! *\n";
00121 (*m1) << "* That's why I don't recommend using this for errors and *\n";
00122 (*m1) << "* warnings. *\n";
00123 (*m1) << "* ====================================================== *\n";
00124 }
00125
00126
00127
00128 static void printStatistics()
00129 {
00130
00131
00132
00133
00134 MsgService::Instance()->PrintStatistics();
00135 }
00136
00137
00138
00139 int main(void) {
00140
00141 theBasics();
00142 fancyStuff();
00143 fancyMessages();
00144 manyMessageExample();
00145 printStatistics();
00146
00147 return EXIT_SUCCESS;
00148 }