00001 /************************************************************************* 00002 * * 00003 * Open Physics Abstraction Layer * 00004 * Copyright (C) 2004-2005 * 00005 * Alan Fischer alan.fischer@gmail.com * 00006 * Andres Reinot andres@reinot.com * 00007 * Tyler Streeter tylerstreeter@gmail.com * 00008 * All rights reserved. * 00009 * Web: opal.sourceforge.net * 00010 * * 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of EITHER: * 00013 * (1) The GNU Lesser General Public License as published by the Free * 00014 * Software Foundation; either version 2.1 of the License, or (at * 00015 * your option) any later version. The text of the GNU Lesser * 00016 * General Public License is included with this library in the * 00017 * file license-LGPL.txt. * 00018 * (2) The BSD-style license that is included with this library in * 00019 * the file license-BSD.txt. * 00020 * * 00021 * This library is distributed in the hope that it will be useful, * 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * 00024 * license-LGPL.txt and license-BSD.txt for more details. * 00025 * * 00026 *************************************************************************/ 00027 00028 #ifndef OPAL_LOGGER_H 00029 #define OPAL_LOGGER_H 00030 00031 // Put this here for now. They seem to nail all the really annoying and 00032 // useless VC6 warning: 4786, Debug info too long 00033 #if defined(WIN32) || defined(_WIN32) 00034 #pragma warning(disable:4786) 00035 #endif 00036 00037 #include <iomanip> 00038 #include <stdlib.h> 00039 #include <string> 00040 #include <ostream> 00041 #include <iostream> 00042 #include <map> 00043 #include <iosfwd> 00044 #include <stdexcept> 00045 00046 #include "Defines.h" 00047 #include "Singleton.h" 00048 00049 #define OPAL_LOGGER Logger::instance().stream 00050 00051 namespace opal 00052 { 00054 namespace loggerImpl 00055 { 00061 class Logger 00062 { 00063 public: 00064 Logger(); 00065 00066 ~Logger(); 00067 00069 void OPAL_CALL setStream(const std::string& name, 00070 std::ostream *stream, const std::string& prefix="", 00071 char mark='\0'); 00072 00073 //static void silenceStream(const std::string& name); 00074 00075 //static void unsilenceStream(const std::string& name); 00076 00078 std::ostream& OPAL_CALL stream(const std::string& name); 00079 00080 private: 00081 struct Stream 00082 { 00083 std::ostream *nullStream; 00084 std::ostream *stream; 00085 bool silent; 00086 char mark; 00087 std::string prefix; 00088 }; 00089 00090 void init(); 00091 std::map<std::string, Stream> mStreams; 00092 }; 00093 } 00094 typedef Singleton<loggerImpl::Logger> Logger; 00095 } 00096 00097 #endif