Go to the documentation of this file.00001
00008
00009
00010
00011
00012 #include <iostream>
00013 #include <string>
00014 #include <ecl/threads/thread.hpp>
00015 #include <ecl/streams/log_stream.hpp>
00016
00017
00018
00019
00020
00021 using std::string;
00022 using ecl::New;
00023 using ecl::LogStream;
00024 using ecl::Thread;
00025
00026
00027
00028
00029
00030 namespace ecl {
00031 namespace demos {
00032
00033
00034
00035
00036
00037 enum LogModes {
00038 Warning,
00039 Error,
00040 Debug,
00041 };
00042
00043 void enableModes( LogStream &log_stream ) {
00044 log_stream.enableHeader();
00045 log_stream.enableTimeStamp();
00046 log_stream.enableMode(Warning,"WARNING");
00047 log_stream.enableMode(Error,"ERROR");
00048 log_stream.enableMode(Debug,"DEBUG");
00049 }
00050
00051 void f() {
00052 LogStream logstream("test.log",New);
00053 enableModes(logstream);
00054 LOG(logstream,Debug) << "Debug message from a threaded function.\n";
00055 FLUSH(logstream);
00056 }
00057
00058 }
00059 }
00060
00061
00062
00063
00064
00065 using namespace ecl::demos;
00066
00067
00068
00069
00070
00071 int main(int argc, char** argv) {
00072
00073 std::cout << std::endl;
00074 std::cout << "***********************************************************" << std::endl;
00075 std::cout << " LogStream" << std::endl;
00076 std::cout << "***********************************************************" << std::endl;
00077 std::cout << std::endl;
00078
00079 std::cout << "This program will log from main and a parallel thread" << std::endl;
00080 std::cout << "to a shared log file call 'test.log'." << std::endl;
00081
00082 LogStream logstream("test.log",New);
00083 enableModes(logstream);
00084 Thread thread(f);
00085 LOG(logstream,Debug) << "Debug message from main.\n";
00086 FLUSH(logstream);
00087 thread.join();
00088
00089 std::cout << std::endl;
00090 std::cout << "***********************************************************" << std::endl;
00091 std::cout << " Passed" << std::endl;
00092 std::cout << "***********************************************************" << std::endl;
00093 std::cout << std::endl;
00094
00095 return 0;
00096 }