00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __PION_LOGSERVICE_HEADER__
00011 #define __PION_LOGSERVICE_HEADER__
00012
00013 #include <boost/thread/mutex.hpp>
00014 #include <boost/scoped_ptr.hpp>
00015 #include <pion/PionLogger.hpp>
00016 #include <pion/net/WebService.hpp>
00017 #include <pion/net/HTTPResponseWriter.hpp>
00018 #include <string>
00019 #include <list>
00020
00021 #if defined(PION_USE_LOG4CXX)
00022 #include <log4cxx/appenderskeleton.h>
00023
00024
00025
00026 #ifndef _LOG4CXX_HELPERS_POOL_H
00027 namespace log4cxx {
00028 namespace helpers {
00029 typedef int Pool;
00030 }
00031 }
00032 #endif
00033 #elif defined(PION_USE_LOG4CPLUS)
00034 #include <log4cplus/appender.h>
00035 #include <log4cplus/loglevel.h>
00036 #elif defined(PION_USE_LOG4CPP)
00037 #include <log4cpp/AppenderSkeleton.hh>
00038 #endif
00039
00040
00041 namespace pion {
00042 namespace plugins {
00043
00044
00048 class LogServiceAppender
00049 #if defined(PION_USE_LOG4CXX)
00050 : public log4cxx::AppenderSkeleton
00051 #elif defined(PION_USE_LOG4CPLUS)
00052 : public log4cplus::Appender
00053 #elif defined(PION_USE_LOG4CPP)
00054 : public log4cpp::AppenderSkeleton
00055 #endif
00056 {
00057 public:
00058
00059 LogServiceAppender(void);
00060 virtual ~LogServiceAppender() {}
00061
00063 inline void setMaxEvents(unsigned int n) { m_max_events = n; }
00064
00066 void addLogString(const std::string& log_string);
00067
00069 void writeLogEvents(pion::net::HTTPResponseWriterPtr& writer);
00070
00071 private:
00073 static const unsigned int DEFAULT_MAX_EVENTS;
00074
00076 unsigned int m_max_events;
00077
00079 unsigned int m_num_events;
00080
00082 std::list<std::string> m_log_events;
00083
00085 boost::mutex m_log_mutex;
00086
00087 #if defined(PION_USE_LOG4CXX)
00088 public:
00089
00090 virtual void close() {}
00091 virtual bool requiresLayout() const { return false; }
00092 protected:
00094 virtual void append(const log4cxx::spi::LoggingEventPtr& event);
00095
00096 virtual void append(const log4cxx::spi::LoggingEventPtr& event,
00097 log4cxx::helpers::Pool& pool)
00098 {
00099 append(event);
00100 }
00101 #elif defined(PION_USE_LOG4CPLUS)
00102 public:
00103
00104 virtual void close() {}
00105 protected:
00106 virtual void append(const log4cplus::spi::InternalLoggingEvent& event);
00107 private:
00109 log4cplus::LogLevelManager m_log_level_manager;
00110 #elif defined(PION_USE_LOG4CPP)
00111 public:
00112
00113 virtual void close() {}
00114 virtual bool requiresLayout() const { return true; }
00115 virtual void setLayout(log4cpp::Layout* layout) { m_layout_ptr.reset(layout); }
00116 protected:
00118 virtual void _append(const log4cpp::LoggingEvent& event);
00119 private:
00121 boost::scoped_ptr<log4cpp::Layout> m_layout_ptr;
00122 #endif
00123
00124 };
00125
00126
00130 class LogService :
00131 public pion::net::WebService
00132 {
00133 public:
00134
00135 LogService(void);
00136 virtual ~LogService();
00137
00139 virtual void operator()(pion::net::HTTPRequestPtr& request,
00140 pion::net::TCPConnectionPtr& tcp_conn);
00141
00143 inline LogServiceAppender& getLogAppender(void) { return *m_log_appender_ptr; }
00144
00145 private:
00147 LogServiceAppender * m_log_appender_ptr;
00148 };
00149
00150
00151 }
00152 }
00153
00154 #endif