Overview
Features
Download
Documentation
Community
Add-Ons & Services

Using logger without Application class

A general discussion forum.

Using logger without Application class

Postby sampsont » 24 Mar 2009, 19:05

I'm writing some low level classes that will later be used in a larger application. What would be the best way to use the logger class without being in the context of a Poco Application class? Is this possible or do I need to make a dummy Application to put my project in to make the logger work?

Thanks!
sampsont
 
Posts: 31
Joined: 05 Mar 2009, 17:08

Re: Using logger without Application class

Postby guenter » 24 Mar 2009, 20:17

You can use all the logger features without the Application class. The application class is just used to configure the logger hierarchy in your application. All you need to add logging to a class is the following:

Code: Select all
#include "Poco/Logger.h"

class MyClass
{
public:
    MyClass():
        _logger(Poco::Logger::get("MyClass"))
    {
    }

    void doSomethingNifty()
    {
        _logger.information("doing something nifty");
    }

private:
    Poco::Logger& _logger;
};
guenter
 
Posts: 1122
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Using logger without Application class

Postby sampsont » 24 Mar 2009, 21:19

Thanks!

Since I haven't configured the logger, is the message going to some default place that I can look at?
sampsont
 
Posts: 31
Joined: 05 Mar 2009, 17:08

Re: Using logger without Application class

Postby guenter » 24 Mar 2009, 22:01

You won't see any messages unless you configure at least the root logger at the startup of your application.
The simplest way to do this is to add the following code to your program's startup code:

Code: Select all
Poco::Logger::root().setChannel(new Poco::ConsoleChannel);


For additional options, see the Logger sample in Foundation/samples.
guenter
 
Posts: 1122
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Using logger without Application class

Postby sampsont » 24 Mar 2009, 22:32

Great! Thanks! Now I have to figure out exactly what's going on. I'm new to Poco and C++. I've done a lot of C programming. When I try to use Poco, the documentation assumes you are very experienced. Could you recommend the best way to come up to speed on Poco? I have looked at the tutorial and sample code and the Platform reference but is there some kind of "Missing Manual" available that fills in some of the philosophy?

I just started a job that is already using Poco. I have to master this stuff.

Thanks
sampsont
 
Posts: 31
Joined: 05 Mar 2009, 17:08

Re: Using logger without Application class

Postby guenter » 24 Mar 2009, 23:06

The best way to learn POCO probably is to study the sample code that comes with every library. This should give you a good idea how things are supposed to work. The rest can be looked up in the reference documentation, or directly in the POCO source code.
guenter
 
Posts: 1122
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests