Logger.cpp

Go to the documentation of this file.
00001 #include "Logger.h"
00002 #include <fstream>
00003 
00004 namespace opal
00005 {
00006         namespace loggerImpl
00007         {
00008                 Logger::Logger()
00009                 {
00010                         //static std::ofstream debugOut, warningOut, errorOut;
00011                         //debugOut.open("opal_debug.log");
00012                         //warningOut.open("opal_warning.log");
00013                         //errorOut.open("opal_error.log");
00014 
00015                         //setStream("debug", &debugOut, "[OPAL debug] ");
00016                         //setStream("warning", &warningOut, "[OPAL warning] ");
00017                         //setStream("error", &errorOut, "[OPAL error] ");
00018                         //setStream("performance", &std::cout);
00019 
00020                         setStream("debug", &std::cout, "[OPAL debug] ");
00021                         setStream("warning", &std::cout, "[OPAL warning] ");
00022                         setStream("error", &std::cout, "[OPAL error] ");
00023                 }
00024 
00025                 Logger::~Logger()
00026                 {
00027                 }
00028 
00029                 void Logger::setStream(const std::string &name, std::ostream *stream, 
00030                         const std::string& prefix, char mark)
00031                 {
00032                         Logger::Stream s;
00033                         s.mark = mark;
00034                         s.silent = false;
00035                         s.stream = stream;
00036                         s.prefix = prefix;
00037         //              s.nullStream = new std::ostream( s.nullBuffer );
00038                         mStreams[name] = s;
00039                 }
00040 
00041                 //void Logger::silenceStream(const std::string &name)
00042                 //{
00043                 //      std::map<std::string, Logger::Stream>::iterator itr = 
00044                 //              mStreams.find(name);
00045                 //      if(itr != mStreams.end())
00046                 //      {
00047                 //              itr->second.silent = true;
00048                 //      }
00049                 //}
00050 
00051                 //void Logger::unsilenceStream(const std::string &name)
00052                 //{
00053                 //      std::map<std::string, Logger::Stream>::iterator itr = 
00054                 //              mStreams.find(name);            
00055                 //      if(itr != mStreams.end())
00056                 //      {
00057                 //              itr->second.silent = false;
00058                 //      }
00059                 //}
00060 
00061                 std::ostream &Logger::stream(const std::string &name)
00062                 {
00063                         Logger::Stream s = mStreams[name];
00064 
00065                         if(s.mark != '\0')
00066                         {
00067                                 std::cout << s.mark;
00068                                 std::cout.flush();
00069                         }
00070 
00071                         if (!s.prefix.empty())
00072                         {
00073                                 *s.stream << s.prefix;
00074                         }
00075 
00076                         return *(s.stream);
00077                 }
00078         }
00079 }

Generated on Tue May 16 17:49:51 2006 for OPAL by  doxygen 1.4.6-NO