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/logger.hpp>
00016 #include <pion/http/plugin_service.hpp>
00017 #include <pion/http/response_writer.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 #endif
00034
00035
00036 namespace pion {
00037 namespace plugins {
00038
00039
00043 class LogServiceAppender
00044 #ifdef PION_HAS_LOG_APPENDER
00045 : public log_appender
00046 #endif
00047 {
00048 public:
00049
00050 LogServiceAppender(void);
00051 virtual ~LogServiceAppender() {}
00052
00054 inline void setMaxEvents(unsigned int n) { m_max_events = n; }
00055
00057 void addLogString(const std::string& log_string);
00058
00060 void writeLogEvents(pion::http::response_writer_ptr& writer);
00061
00062 private:
00064 static const unsigned int DEFAULT_MAX_EVENTS;
00065
00067 unsigned int m_max_events;
00068
00070 unsigned int m_num_events;
00071
00073 std::list<std::string> m_log_events;
00074
00076 boost::mutex m_log_mutex;
00077
00078 #if defined(PION_USE_LOG4CXX)
00079 public:
00080
00081 virtual void close() {}
00082 virtual bool requiresLayout() const { return false; }
00083 protected:
00085 virtual void append(const log4cxx::spi::LoggingEventPtr& event);
00086
00087 virtual void append(const log4cxx::spi::LoggingEventPtr& event,
00088 log4cxx::helpers::Pool& pool)
00089 {
00090 append(event);
00091 }
00092 #elif defined(PION_USE_LOG4CPLUS)
00093 public:
00094
00095 virtual void close() {}
00096 protected:
00097 virtual void append(const log4cplus::spi::InternalLoggingEvent& event);
00098 private:
00100 log4cplus::LogLevelManager m_log_level_manager;
00101 #elif defined(PION_USE_LOG4CPP)
00102 public:
00103
00104 virtual void close() {}
00105 virtual bool requiresLayout() const { return true; }
00106 virtual void setLayout(log4cpp::Layout* layout) { m_layout_ptr.reset(layout); }
00107 protected:
00109 virtual void _append(const log4cpp::LoggingEvent& event);
00110 private:
00112 boost::scoped_ptr<log4cpp::Layout> m_layout_ptr;
00113 #endif
00114
00115 };
00116
00117
00121 class LogService :
00122 public pion::http::plugin_service
00123 {
00124 public:
00125
00126 LogService(void);
00127 virtual ~LogService();
00128
00130 virtual void operator()(pion::http::request_ptr& http_request_ptr,
00131 pion::tcp::connection_ptr& tcp_conn);
00132
00134 inline LogServiceAppender& getLogAppender(void) {
00135 #ifdef PION_HAS_LOG_APPENDER
00136 return dynamic_cast<LogServiceAppender&>(*m_log_appender_ptr);
00137 #else
00138 return *m_log_appender_ptr;
00139 #endif
00140 }
00141
00142 private:
00144 #ifdef PION_HAS_LOG_APPENDER
00145 log_appender_ptr m_log_appender_ptr;
00146 #else
00147 LogServiceAppender * m_log_appender_ptr;
00148 #endif
00149 };
00150
00151
00152 }
00153 }
00154
00155 #endif