title: Appender with multi-class example for logging system
body: <p>I'm newbie working with a logging system, but it's something very useful to add to your programs.</p>
  
  <p>Summarizing my problem. I use the logging library <strong>log4cplus</strong></p>
  
  <p>I doing and easy example with two simple classes and the main program.</p>
  
  <p>That's my error log:</p>
  
  <ul>
  <li>log4cplus:ERROR No appenders could be found for logger (main).  </li>
  <li>log4cplus:ERROR Please initialize the log4cplus system properly.</li>
  <li>Segmentation fault: 11</li>
  </ul>
  
  <p>The problem is i don't know how to solve the problem with the appender.</p>
  
  <p>That's basic code of my example.
  <strong>Class1.h</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include &lt;log4cplus/configurator.h&gt;
  #include &lt;log4cplus/logger.h&gt;
  
  using namespace std;
  // Use the log4cplus namespace
  using namespace log4cplus;
  
  class one
  {
      private:
          // Create the logger
          Logger logger;
  
      public:
          bool flag;
          int valor;
  
          one();  
          int multiplica(int a);  
  };
  </code></pre>
  
  <p><strong>Class1.cpp</strong></p>
  
  <pre><code>one::one()
  {
      logger.getInstance(LOG4CPLUS_TEXT("Clase One - constructor.")); 
  }
  
  int one::multiplica(int a)
  {
      int sol = 0;
  
      sol = valor * a;
  
      // Imprimo un mesaje en el log.
      LOG4CPLUS_INFO(logger, "El resultado de la multiplicación es: xx");
  
      return sol;
  }
  </code></pre>
  
  <p><strong>Class2.h</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include &lt;log4cplus/configurator.h&gt;
  #include &lt;log4cplus/logger.h&gt;
  
  using namespace std;
  // Use the log4cplus namespace
  using namespace log4cplus;
  
  class two
  {
      private:
          // Create the logger
          Logger logger;
  
      public:
          bool flag;
          int valor;
  
          two();
          int suma(int a);    
  };
  </code></pre>
  
  <p><strong>Class.cpp</strong></p>
  
  <pre><code>two::two()
  {
      logger.getInstance(LOG4CPLUS_TEXT("Clase Two - DEconstructor.")); 
  }
  
  int two::suma(int a)
  {
      int sol = 0;
  
      sol = valor + a;
  
      // Imprimo un mesaje en el log.
      LOG4CPLUS_INFO(logger, "El resultado de la suma es: YY ");
  
      return sol;
  }
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>int main(int argc, char** argv)
  {
      // Load the properties
      PropertyConfigurator::doConfigure("logClase.properties");
      Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("main"));
  
      // Log with INFO level
      if (logger.isEnabledFor(INFO_LOG_LEVEL))
      {
          LOG4CPLUS_INFO(logger, "Application startup");
      }
  
          one uno;
          two dos;
  
          uno.valor = dos.valor = 4;
          uno.multiplica(7);
          dos.suma(7);
  
      // Log with INFO level
      if (logger.isEnabledFor(INFO_LOG_LEVEL))
      {
          LOG4CPLUS_INFO(logger, "Application shutdown");
      }
  
      return 0;
  }
  </code></pre>
  
  <p>What i'm doing wrong ??? 
  That's the correct way to work with the logging system ??</p>
  
  <p>I use a simple properties file to save all the log messages in a file.</p>
  
  <p>That's my <strong>logClase.properties</strong> file to configure de logger.</p>
  
  <pre><code>log4cplus.rootLogger=INFO, STDOUT, FILEAPPENDER
  log4cplus.logger.main=INFO
  log4cplus.logger.utils=FILEAPPENDER
  
  log4cplus.appender.STDOUT=log4cplus::ConsoleAppender
  log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout
  log4cplus.appender.STDOUT.layout.ConversionPattern=%d{%m/%d/%y %H:%M:%S} [%t] %-5p %c{2} %%%x%% - %m [%l]%n
  
  log4cplus.appender.FILEAPPENDER=log4cplus::RollingFileAppender
  log4cplus.appender.FILEAPPENDER.File=KlasseEx.log
  log4cplus.appender.FILEAPPENDER.MaxFileSize=5MB
  #log4cplus.appender.FILEAPPENDER.MaxFileSize=500KB
  log4cplus.appender.FILEAPPENDER.MaxBackupIndex=1
  log4cplus.appender.FILEAPPENDER.layout=log4cplus::PatternLayout
  log4cplus.appender.FILEAPPENDER.layout.ConversionPattern=%d{%m/%d/%y %H:%M:%S} [%t] %-5p %c{2} %%%x%% - %m [%l]%n
  </code></pre>
  
  <p>I want to use FILEAPPENDER and the Console appender to throw messages in a file and into the console. I think that's not must be so difficult to do, it must be easy to do it.</p>