Overview
Features
Download
Documentation
Community
Add-Ons & Services

About the logger

Please post support and help requests here.

About the logger

Postby atticmusic » 09 Aug 2012, 07:11

Do I need to do any setting before using logger?

Code: Select all
#include "Poco/Logger.h"
#include "Poco/PatternFormatter.h"
#include "Poco/FormattingChannel.h"
#include "Poco/ConsoleChannel.h"
#include "Poco/FileChannel.h"
#include "Poco/Message.h"

using Poco::Logger;
using Poco::PatternFormatter;
using Poco::FormattingChannel;
using Poco::WindowsConsoleChannel;
using Poco::FileChannel;
using Poco::Message;

int main(int argc, char *argv[])
{
      // set up two channel chains - one to the
      // console and the other one to a log file.
      FormattingChannel* pFCConsole = new FormattingChannel(new PatternFormatter("%s: %p: %t"));
      pFCConsole->setChannel(new WindowsConsoleChannel);
      pFCConsole->open();
     
      FormattingChannel* pFCFile = new FormattingChannel(new PatternFormatter("%Y-%m-%d %H:%M:%S.%c %N[%P]:%s:%q:%t"));
      pFCFile->setChannel(new FileChannel("sample.log"));
      pFCFile->open();

      // create two Logger objects - one for
      // each channel chain.
      Logger& consoleLogger = Logger::create("ConsoleLogger", pFCConsole, Message::PRIO_INFORMATION);
      Logger& fileLogger    = Logger::create("FileLogger", pFCFile, Message::PRIO_WARNING);
     
      // log some messages
      consoleLogger.error("An error message");
      fileLogger.error("An error message");
     
      consoleLogger.warning("A warning message");
      fileLogger.error("A warning message");
     
      consoleLogger.information("An information message");
      fileLogger.information("An information message");
     
      Logger::get("ConsoleLogger").error("Another error message");

   system("pause");
}


But neither was there anything in the console screen nor sample.log is generated.
What do I need to do, Thanks a lot
atticmusic
 
Posts: 2
Joined: 08 Aug 2012, 06:45

Re: About the logger

Postby guenter » 10 Aug 2012, 06:45

You'll also need to open the channels that you pass to your FormattingChannel instances.
guenter
 
Posts: 1091
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron