// // CustomAppender - shows how to implement a custom appender that stores log messages in memory. // #include #include #include #include namespace plog { template // Typically a formatter is passed as a template parameter. class MyAppender : public IAppender // All appenders MUST inherit IAppender interface. { public: virtual void write(const Record& record) PLOG_OVERRIDE // This is a method from IAppender that MUST be implemented. { util::nstring str = Formatter::format(record); // Use the formatter to get a string from a record. m_messageList.push_back(str); // Store a log message in a list. } std::list& getMessageList() { return m_messageList; } private: std::list m_messageList; }; } int main() { static plog::MyAppender myAppender; // Create our custom appender. plog::init(plog::debug, &myAppender); // Initialize the logger with our appender. PLOGD << "A debug message!"; myAppender.getMessageList(); // This returns a list of stored log messages. return 0; }