Overview
Features
Download
Documentation
Community
Add-Ons & Services

Poco::Logger

Please post support and help requests here.

Poco::Logger

Postby Splitpi » 19 Dec 2008, 18:45

I am trying to use the Poco::Logger class and would like to have my own wrapper class. But I am having a devil of a time getting it to work.

Here is my wrapper definition:
Code: Select all
    typedef enum
    {
        CONSOLE = 0,
        FILE,
        BOTH
    } LOGGERTYPE;
   
    //should be only 1 to 9 to Message::Priority enum
    //typedef void (*func_array)(const std::string&);
   
    class cLogger
    {
    public:
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    //  cLogger()
    //  Constructor,
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
        cLogger(Logger & in_logger);
   
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    //  ~cLogger()
    //  Destructor,
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
        ~cLogger()
        {
            m_consolelogger.destroy("ConsoleLogger");
            m_filelogger.destroy("FileLogger");
        }
   
        // Log at information priority to the file
        void operator<<(const std::string & in_str);
       
        // Log at critical priority
        void critical(const std::string& , const LOGGERTYPE & = FILE);
        // Log at debug priority
        void debug(const std::string& , const LOGGERTYPE & = FILE);
        // Log at error priority
        void error(const std::string &, const LOGGERTYPE & = FILE);
        // Log at fatal priority
        void fatal(const std::string &, const LOGGERTYPE & = FILE);
        // Log at information priority
        void information(const std::string &, const LOGGERTYPE & = FILE);
        // Log at notice priority
        void notice(const std::string &, const LOGGERTYPE & = FILE);
        // Log at trace priority
        void trace(const std::string &, const LOGGERTYPE & = FILE);
        // Log at warning priority
        void warning(const std::string &, const LOGGERTYPE & = FILE);
        // Log at priority indicated in second value,
        //    default is Information
        void log(const std::string &, const int & = Message::PRIO_INFORMATION,
                 const LOGGERTYPE & = FILE);
   
    private:
       
        void setupfunctiontable();
        std::string getlogfilename();

        FormattingChannel* m_pfcconsole;
        FormattingChannel* m_pfcfile;
        FileChannel*       m_pfcfilechan;
       
        Logger&            m_consolelogger;
        Logger&            m_filelogger;
        Mutex              m_mconsolemutex;
        Mutex              m_mfilemutex;
        void (cLogger::* m_pfuncarray[9])(const std::string &, const ProWrite::LOGGERTYPE&);         
    };


And the constructor:
Code: Select all
cLogger::cLogger(Logger & in_logger) :
        m_pfcconsole(NULL), m_pfcfile(NULL), m_pfcfilechan(NULL),
        m_consolelogger(in_logger), m_filelogger(in_logger),
        m_mconsolemutex(), m_mfilemutex(),
        m_pfuncarray()
{
    try
    {
        Mutex::ScopedLock conlock(m_mconsolemutex);
        Mutex::ScopedLock filelock(m_mfilemutex);
        m_pfcconsole = new FormattingChannel(new PatternFormatter("%s: %p: %t"));
        if (m_pfcconsole)
        {
            m_pfcconsole->setChannel(new ConsoleChannel);
            m_pfcconsole->open();
           
        }
        else
        {
            throw "Could not allocate logger!";
        }
        m_pfcfile = new FormattingChannel(new PatternFormatter("%Y-%m-%d %H:%M:%S.%c %N[%P]:%s:%q:%t"));
        if (m_pfcfile)
        {
           
            m_pfcfilechan = new FileChannel(getlogfilename());
            m_pfcfilechan->setProperty("rotation", "150k");
            m_pfcfilechan->setProperty("archive", "timestamp");
            m_pfcfile->setChannel(m_pfcfilechan);
           
            m_pfcfile->open();   
        }
        else
        {
            throw "Could not allocate logger!";
        }
       
        m_consolelogger.create("ConsoleLogger", m_pfcconsole, Message::PRIO_INFORMATION);
        m_filelogger.create("FileLogger", m_pfcfile, Message::PRIO_INFORMATION);
        setupfunctiontable();
    }
    catch(...)
    {
    }
}


In the main I created the wrapper like this:
Code: Select all
cLogger mainlogger(Poco::Logger);


And passed it around reference:
Code: Select all
Poco::SharedPtr<cTimerImpl> timer = new cTimerImpl(&mainlogger);


I get the following compilation error:
../src/Main_App/Main_App.cpp: In function ‘int main(int, char**)’:
../src/Main_App/Main_App.cpp:35: error: no matching function for call to ‘ProWrite::cTimerImpl::cTimerImpl(ProWrite::cLogger (*)(Poco::Logger))’

If I create mainlogger as a pointer to cLogger .... i.e. cLogger* mainlogger = new cLogger(Poco::Logger);

I get the following error:
../src/Main_App/Main_App.cpp: In function ‘int main(int, char**)’:
../src/Main_App/Main_App.cpp:32: error: expected primary-expression before ‘)’ token

The biggest issue I am having is the that the Poco::Logger Constructor call is private.

Any help?
Splitpi
 
Posts: 3
Joined: 19 Dec 2008, 18:37

Re: Poco::Logger

Postby alex » 20 Dec 2008, 14:32

Splitpi wrote:I am trying to use the Poco::Logger class and would like to have my own wrapper class.
...
In the main I created the wrapper like this:
Code: Select all
cLogger mainlogger(Poco::Logger);


Try
Code: Select all
cLogger mainlogger(Poco::Logger::root());
alex
 
Posts: 1143
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Poco::Logger

Postby Splitpi » 22 Dec 2008, 17:41

Thanks Alex...

That seems to work. But I changed the constructor to just initialize the the Logger objects in the the constructor with root versus having it passed into the cLogger class.
Splitpi
 
Posts: 3
Joined: 19 Dec 2008, 18:37


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest