00001 #ifndef PHX_LOG_H
00002 #define PHX_LOG_H
00003
00011 #include <iostream>
00012 #include <Phx/Util/PhxPtrInterface.h>
00013 #include <Phx/Core/PhxNamedInterface.h>
00014
00015
00016 #define PHX_DEBUGGING LOG_LEVEL_DEBUG,__FILE__,__LINE__
00017 #define PHX_INFO LOG_LEVEL_INFO,__FILE__,__LINE__
00018 #define PHX_WARNING LOG_LEVEL_WARNING,__FILE__,__LINE__
00019 #define PHX_ERROR LOG_LEVEL_ERROR,__FILE__,__LINE__
00020 #define PHX_NORMAL LOG_LEVEL_NORMAL,__FILE__,__LINE__
00021
00022 #define LOG_TO_STDOUT true
00023
00024 namespace Phx
00025 {
00026
00032 enum Mode
00033 { LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARNING,
00034 LOG_LEVEL_ERROR, LOG_LEVEL_NORMAL
00035 };
00036
00041 class Log:public NamedInterface
00042 {
00043 public:
00044 class OutputStream;
00045
00046 static const NamedInterface::Type INTERFACE_TYPE;
00047 static const String INTERFACE_TYPE_NAME;
00048
00049 static const NamedInterface::Identifier LOG_IDENTIFIER;
00050 static const String LOG_NAME;
00051
00059 virtual Ptr < OutputStream >
00060 newOutputStream (const String & prefix) = 0;
00061
00068
00069
00070
00079 virtual void newMessage(const String& name,
00080 Mode mode,
00081 const char *file,
00082 int line,
00083 const String& message) = 0;
00084 };
00085
00086
00087
00088 class Log::OutputStream:public LockedPtrInterface < OutputStream >
00089 {
00090 public:
00091
00092 virtual Log::OutputStream & stream (Mode mode,
00093 const char *file,
00094 int line) = 0;
00095
00100 virtual Log::
00101 OutputStream & operator << (std::ostream &
00102 (*pf) (std::ostream &)) = 0;
00103
00107 template < class T >
00108 Log::OutputStream & operator << (const T & str)
00109 {
00110 buffer () << str;
00111 return *this;
00112 }
00113 private:
00117 virtual std::ostream & buffer (void) = 0;
00118 };
00119 }
00120 #endif // PHX_LOG_H