这个问题通常是由于缺少链接日志库引起的。您可以通过在主Makefile或在编译器字符串中添加-llog4cxx来修复它。
例如,在使用gcc编译器时,您可以这样编写:
g++ -o myprogram myprogram.cpp -llog4cxx
以下是在使用自定义策略和log4cxx 0.10.0版本时编写策略的示例代码:
#include
class MyCustomLogPolicy : public log4cxx::spi::LoggingEvent { public: MyCustomLogPolicy() {}
MyCustomLogPolicy(const log4cxx::LoggerPtr& logger,
const log4cxx::LevelPtr& level,
const log4cxx::String& message) :
log4cxx::spi::LoggingEvent(logger, level, message) {}
MyCustomLogPolicy(const log4cxx::LoggerPtr& logger,
const log4cxx::spi::LocationInfo& locationInfo,
const log4cxx::LevelPtr& level,
const log4cxx::String& message,
const log4cxx::helpers::ThrowablePtr& throwable) :
log4cxx::spi::LoggingEvent(logger, locationInfo, level, message, throwable) {}
virtual ~MyCustomLogPolicy() {}
virtual log4cxx::helpers::ObjectPtr getProperty(const log4cxx::String& name) const {
return NULL;
}
virtual void getPropertyList(log4cxx::helpers::ObjectList& pList) const {}
virtual void setProperty(const log4cxx::String& name, const log4cxx::helpers::ObjectPtr& value) {}
virtual void readExternal(log4cxx::helpers::ObjectInput& in) throw (log4cxx::helpers::IOException, log4cxx::helpers::ClassNotFoundException) {}
virtual void writeExternal(log4cxx::helpers::ObjectOutput& out) const throw (log4cxx