00001 #include "logging/Appender.hpp"
00002 #include "ocl/Component.hpp"
00003
00004 #include <log4cpp/Appender.hh>
00005 #include <log4cpp/BasicLayout.hh>
00006 #include <log4cpp/SimpleLayout.hh>
00007 #include <log4cpp/PatternLayout.hh>
00008
00009 namespace OCL {
00010 namespace logging {
00011
00012 Appender::Appender(std::string name) :
00013 RTT::TaskContext(name),
00014 appender(0),
00015 layoutName_prop("LayoutName", "Layout name (e.g. 'simple', 'pattern')"),
00016 layoutPattern_prop("LayoutPattern", "Layout conversion pattern (for those layouts that use a pattern)")
00017 {
00018 ports()->addEventPort("LogPort", log_port );
00019
00020 properties()->addProperty(layoutName_prop);
00021 properties()->addProperty(layoutPattern_prop);
00022 }
00023
00024 Appender::~Appender()
00025 {
00026 }
00027
00028 bool Appender::configureLayout()
00029 {
00030 bool rc;
00031 const std::string& layoutName = layoutName_prop.rvalue();
00032 const std::string& layoutPattern = layoutPattern_prop.rvalue();
00033
00034 rc = true;
00035 if (appender &&
00036 (!layoutName.empty()))
00037 {
00038
00039 if (0 == layoutName.compare("basic"))
00040 {
00041 appender->setLayout(new log4cpp::BasicLayout());
00042 }
00043 else if (0 == layoutName.compare("simple"))
00044 {
00045 appender->setLayout(new log4cpp::SimpleLayout());
00046 }
00047 else if (0 == layoutName.compare("pattern"))
00048 {
00049 log4cpp::PatternLayout *layout = new log4cpp::PatternLayout();
00051 layout->setConversionPattern(layoutPattern);
00052 appender->setLayout(layout);
00053
00054
00055 }
00056 else
00057 {
00058 log(Error) << "Invalid layout '" << layoutName
00059 << "' in configuration for category: "
00060 << getName() << endlog();
00061 rc = false;
00062 }
00063 }
00064
00065 return rc;
00066 }
00067
00068 bool Appender::startHook()
00069 {
00071
00072
00073 return true;
00074 }
00075
00076
00077 }
00078 }
00079
00080 ORO_LIST_COMPONENT_TYPE(OCL::logging::Appender);