Dan Vonk
Dan Vonk

Reputation: 79

Using Poco::Logger for entire project

AutoPtr<SplitterChannel> splitterChannel(new SplitterChannel());

        AutoPtr<Channel> consoleChannel(new ConsoleChannel());
        AutoPtr<Channel> fileChannel(new FileChannel("Arcanite.log"));
        AutoPtr<FileChannel> rotatedFileChannel(new FileChannel("Arcanite_R.log"));

        rotatedFileChannel->setProperty("rotation", "100");
        rotatedFileChannel->setProperty("archive", "timestamp");

        splitterChannel->addChannel(consoleChannel);
        splitterChannel->addChannel(fileChannel);
        splitterChannel->addChannel(rotatedFileChannel);

        //"%d-%m-%Y %H:%M:%S: %t"
        AutoPtr<Formatter> formatter(new PatternFormatter("%d-%m-%Y %H:%M:%S %s: %t"));
        AutoPtr<Channel> formattingChannel(new FormattingChannel(formatter, splitterChannel));


        Logger& sLog = Logger::create("LogChan", formattingChannel, Message::PRIO_TRACE);

Ive written my logger which i want to use for my server, in multiple classes. How can i adapt this to do this? This is probably basic c++ but i seem to have missed a few lessons :P

Upvotes: 4

Views: 5643

Answers (1)

Cesar Ortiz
Cesar Ortiz

Reputation: 932

Class Poco::Logger works as a logging framework.

When you define a logger instance with a fixed name ("LogChan" in your example), it is accessible from all your classes. So you should make a

Logger& logger = Logger::get("logChan"); 

from your other classes to get the logger reference.

I guess below it use a singleton pattern to generate the pool of loggers.

Upvotes: 5

Related Questions