Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Multiple instances of log4cpp in Qt
Forum Updated to NodeBB v4.3 + New Features

Multiple instances of log4cpp in Qt

Scheduled Pinned Locked Moved Solved 3rd Party Software
2 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yuvaram
    wrote on 17 Feb 2017, 09:32 last edited by A Former User
    #1

    Hi ,

    In my project there are multiple module, need different log files for each module in different folders. I have created multiple instances of log4cpp. But logs are appending only into single file of last instance created.

    Please let me know, can we create multiple instances of log4cpp.
    Verified object names using setObjectName() and Objectname(), all object names are different.
    Thank you in advance.

    Yuvaram Aligeti
    Embedded Qt Developer
    : )

    J 1 Reply Last reply 17 Feb 2017, 09:35
    0
    • Y yuvaram
      17 Feb 2017, 09:32

      Hi ,

      In my project there are multiple module, need different log files for each module in different folders. I have created multiple instances of log4cpp. But logs are appending only into single file of last instance created.

      Please let me know, can we create multiple instances of log4cpp.
      Verified object names using setObjectName() and Objectname(), all object names are different.
      Thank you in advance.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 17 Feb 2017, 09:35 last edited by jsulm
      #2

      @yuvaram How is your question related to Qt?
      On the project page (http://log4cpp.sourceforge.net/) there is an example logging to two different targets: console and a file:

      int main(int argc, char** argv) {
      	log4cpp::Appender *appender1 = new log4cpp::OstreamAppender("console", &std::cout);
      	appender1->setLayout(new log4cpp::BasicLayout());
      
      	log4cpp::Appender *appender2 = new log4cpp::FileAppender("default", "program.log");
      	appender2->setLayout(new log4cpp::BasicLayout());
      
      	log4cpp::Category& root = log4cpp::Category::getRoot();
      	root.setPriority(log4cpp::Priority::WARN);
      	root.addAppender(appender1);
      
      	log4cpp::Category& sub1 = log4cpp::Category::getInstance(std::string("sub1"));
      	sub1.addAppender(appender2);
      
      	// use of functions for logging messages
      	root.error("root error");
      	root.info("root info");
      	sub1.error("sub1 error");
      	sub1.warn("sub1 warn");
      
      	// printf-style for logging variables
      	root.warn("%d + %d == %s ?", 1, 1, "two");
      
      	// use of streams for logging messages
      	root << log4cpp::Priority::ERROR << "Streamed root error";
      	root << log4cpp::Priority::INFO << "Streamed root info";
      	sub1 << log4cpp::Priority::ERROR << "Streamed sub1 error";
      	sub1 << log4cpp::Priority::WARN << "Streamed sub1 warn";
      
      	// or this way:
      	root.errorStream() << "Another streamed error";
      
      	return 0;
      }
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      1/2

      17 Feb 2017, 09:32

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved