ICE 3.4.2
[php5-ice-freebsdport.git] / cpp / src / Ice / LoggerUtil.cpp
blobd6b500178365430304158dab61d5e77502238330
2 // **********************************************************************
3 //
4 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 //
6 // This copy of Ice is licensed to you under the terms described in the
7 // ICE_LICENSE file included in this distribution.
8 //
9 // **********************************************************************
11 #include <Ice/LoggerUtil.h>
12 #include <Ice/Logger.h>
13 #include <Ice/Plugin.h>
14 #include <Ice/LocalException.h>
15 #include <Ice/Instance.h>
17 using namespace std;
19 namespace IceUtilInternal
22 extern bool ICE_DECLSPEC_IMPORT printStackTraces;
26 ostringstream&
27 Ice::LoggerOutputBase::__str()
29 return _str;
32 Ice::LoggerOutputBase&
33 Ice::operator<<(Ice::LoggerOutputBase& out, ios_base& (*val)(ios_base&))
35 out.__str() << val;
36 return out;
39 Ice::LoggerOutputBase&
40 Ice::operator<<(Ice::LoggerOutputBase& out, const std::exception& ex)
42 #ifdef __GNUC__
43 if(IceUtilInternal::printStackTraces)
45 const ::IceUtil::Exception* exception = dynamic_cast<const ::IceUtil::Exception*>(&ex);
46 if(exception)
48 out.__str() << exception->what() << '\n' << exception->ice_stackTrace();
49 return out;
52 #endif
53 out.__str() << ex.what();
54 return out;
57 Ice::Print::Print(const LoggerPtr& logger) :
58 _logger(logger)
62 Ice::Print::~Print()
64 flush();
67 void
68 Ice::Print::flush()
70 string s = __str().str();
71 if(!s.empty())
73 _logger->print(s);
75 __str().str("");
78 Ice::Warning::Warning(const LoggerPtr& logger) :
79 _logger(logger)
83 Ice::Warning::~Warning()
85 flush();
88 void
89 Ice::Warning::flush()
91 string s = __str().str();
92 if(!s.empty())
94 _logger->warning(s);
96 __str().str("");
99 Ice::Error::Error(const LoggerPtr& logger) :
100 _logger(logger)
104 Ice::Error::~Error()
106 flush();
109 void
110 Ice::Error::flush()
112 string s = __str().str();
113 if(!s.empty())
115 _logger->error(s);
117 __str().str("");
120 Ice::Trace::Trace(const LoggerPtr& logger, const string& category) :
121 _logger(logger),
122 _category(category)
126 Ice::Trace::~Trace()
128 flush();
131 void
132 Ice::Trace::flush()
134 string s = __str().str();
135 if(!s.empty())
137 _logger->trace(_category, s);
139 __str().str("");
142 Ice::LoggerPlugin::LoggerPlugin(const CommunicatorPtr& communicator, const LoggerPtr& logger)
144 if(communicator == 0)
146 throw PluginInitializationException(__FILE__, __LINE__, "Communicator cannot be null");
149 if(logger == 0)
151 throw PluginInitializationException(__FILE__, __LINE__, "Logger cannot be null");
154 IceInternal::InstancePtr instance = IceInternal::getInstance(communicator);
155 instance->setLogger(logger);
158 void
159 Ice::LoggerPlugin::initialize()
163 void
164 Ice::LoggerPlugin::destroy()