<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to CodeExamples</title><link>https://sourceforge.net/p/log4cplus/wiki/CodeExamples/</link><description>Recent changes to CodeExamples</description><atom:link href="https://sourceforge.net/p/log4cplus/wiki/CodeExamples/feed" rel="self"/><language>en</language><lastBuildDate>Tue, 28 Feb 2023 19:32:17 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/log4cplus/wiki/CodeExamples/feed" rel="self" type="application/rss+xml"/><item><title>CodeExamples modified by Václav Haisman</title><link>https://sourceforge.net/p/log4cplus/wiki/CodeExamples/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v9
+++ v10
@@ -1,3 +1,5 @@
+**OBSOLETE: See https://github.com/log4cplus/log4cplus/wiki/Code-Examples instead.**
+
 [TOC]

 Hello World
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Václav Haisman</dc:creator><pubDate>Tue, 28 Feb 2023 19:32:17 -0000</pubDate><guid>https://sourceforge.netdd5569819d7adc688e1f8d3204b7ec9a29250f25</guid></item><item><title>CodeExamples modified by Václav Haisman</title><link>https://sourceforge.net/p/log4cplus/wiki/CodeExamples/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v8
+++ v9
@@ -106,8 +106,6 @@
 --------------

 As we have mentioned earlier, `LOG4CPLUS_WARN()`, `LOG4CPLUS_ERROR()`, etc., macros use C++ string stream under the hood. The following example demonstrates how is it possible to use it with the macros.
-
-Beside these macros, there are two more groups of logging macros. `LOG4CPLUS_*_STR()` can be used for logging messages that are just plain strings that do not need any kind of formatting. There is also group of `LOG4CPLUS_*_FMT()` macros which format logged message using `printf()` formatting string.

 ~~~~ {.cpp}
 #include &amp;lt;log4cplus logger.h=""&amp;gt;
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Václav Haisman</dc:creator><pubDate>Fri, 27 Apr 2018 22:19:34 -0000</pubDate><guid>https://sourceforge.neta46ae488b89bb66acf2213e7f3c227312f484904</guid></item><item><title>CodeExamples modified by Václav Haisman</title><link>https://sourceforge.net/p/log4cplus/wiki/CodeExamples/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v7
+++ v8
@@ -1,6 +1,3 @@
-# Code Examples
-=============
-
 [TOC]

 Hello World
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Václav Haisman</dc:creator><pubDate>Tue, 22 Mar 2016 19:29:04 -0000</pubDate><guid>https://sourceforge.net7b375585ac79d78ae3331da4ebefa35088b4258a</guid></item><item><title>CodeExamples modified by Václav Haisman</title><link>https://sourceforge.net/p/log4cplus/wiki/CodeExamples/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v6
+++ v7
@@ -1,5 +1,7 @@
-Code Examples
+# Code Examples
 =============
+
+[TOC]

 Hello World
 -----------
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Václav Haisman</dc:creator><pubDate>Tue, 22 Mar 2016 19:28:42 -0000</pubDate><guid>https://sourceforge.netabecb435469334ae17efec0aab7a587462590527</guid></item><item><title>CodeExamples modified by Václav Haisman</title><link>https://sourceforge.net/p/log4cplus/wiki/CodeExamples/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v5
+++ v6
@@ -1,140 +1,282 @@
-# log4cplus code examples
-
-## Hello World
-
-Here is a minimal log4cplus source:
-
-~~~~{.cpp}
-#include &amp;lt;log4cplus logger.h=""&amp;gt;
-#include &amp;lt;log4cplus loggingmacros.h=""&amp;gt;
-#include &amp;lt;log4cplus configurator.h=""&amp;gt;
-#include &amp;lt;iomanip&amp;gt;
-
-using namespace log4cplus;
+Code Examples
+=============
+
+Hello World
+-----------
+
+Here is a minimal [log4cplus](https://sourceforge.net/projects/log4cplus/) example for [log4cplus](https://sourceforge.net/projects/log4cplus/) version 2.0 and later:
+
+~~~~ {.cpp}
+#include &amp;lt;log4cplus logger.h=""&amp;gt;
+#include &amp;lt;log4cplus loggingmacros.h=""&amp;gt;
+#include &amp;lt;log4cplus configurator.h=""&amp;gt;
+#include &amp;lt;log4cplus initializer.h=""&amp;gt;

 int
 main()
 {
-    initialize();
-    BasicConfigurator config;
+    // Initialization and deinitialization.
+    log4cplus::Initializer initializer;
+
+    log4cplus::BasicConfigurator config;
     config.configure();
-    
-    Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("main"));
+
+    log4cplus::Logger logger = log4cplus::Logger::getInstance(
+        LOG4CPLUS_TEXT("main"));
     LOG4CPLUS_WARN(logger, LOG4CPLUS_TEXT("Hello, World!"));
     return 0;
 }
 ~~~~

-## Logging macros
-
-`LOG4CPLUS_WARN`, `LOG4CPLUS_ERROR`, etc. macros use `std::ostream` under the hood. The following example demonstrates how is it possible to use it with the macros.
-
-~~~~{.cpp}
-#include &amp;lt;log4cplus logger.h=""&amp;gt;
-#include &amp;lt;log4cplus loggingmacros.h=""&amp;gt;
-#include &amp;lt;log4cplus configurator.h=""&amp;gt;
+The above code prints `WARN - Hello, World!` on console. Let’s dissect it:
+
+~~~~ {.cpp}
+#include &amp;lt;log4cplus logger.h=""&amp;gt;
+~~~~
+
+We need this header to get `Logger` class which represents a handle to named logger.
+
+~~~~ {.cpp}
+#include &amp;lt;log4cplus loggingmacros.h=""&amp;gt;
+~~~~
+
+This header declares `LOG4CPLUS_WARN()` logging macro. Beside this one, it also declares one for each standard logging level: FATAL, ERROR, WARN, INFO, DEBUG, TRACE.
+
+~~~~ {.cpp}
+#include &amp;lt;log4cplus configurator.h=""&amp;gt;
+~~~~
+
+This header declares `BasicConfigurator` class.
+
+~~~~ {.cpp}
+#include &amp;lt;log4cplus initializer.h=""&amp;gt;
+~~~~
+
+This header declares `Initializer` class.
+
+~~~~ {.cpp}
+log4cplus::Initializer initializer;
+~~~~
+
+Instantiating the `Initializer` class internally initializes [log4cplus](https://sourceforge.net/projects/log4cplus/).
+
+The `Initializer` class also maintains a reference count. The class can be instantiated multiple times. When this reference count reaches zero, after the last instance of `Initializer` is destroyed, it shuts down [log4cplus](https://sourceforge.net/projects/log4cplus/) internals. Currently, after [log4cplus](https://sourceforge.net/projects/log4cplus/) is deinitialized, it cannot be re-initialized.
+
+[log4cplus](https://sourceforge.net/projects/log4cplus/) tries to use some other methods of shutting down its internals. However, that means that it ***cannot be used after `main()` exits***.
+
+~~~~ {.cpp}
+log4cplus::BasicConfigurator config;
+config.configure();
+~~~~
+
+These two lines configure *root logger* with `ConsoleAppender` and simple layout.
+
+~~~~ {.cpp}
+log4cplus::Logger logger = log4cplus::Logger::getInstance(
+    LOG4CPLUS_TEXT("main"));
+~~~~
+
+Here we obtain logger handle to logger named *main*.
+
+The `LOG4CPLUS_TEXT()` macro used above has the same function as the `TEXT()` or `_T()` macros do on Windows: In case `UNICODE` preprocessor symbol is defined, it prefixes the string literal that is passed as its parameter with the `L` to make it wide character string literal.
+
+~~~~ {.cpp}
+LOG4CPLUS_WARN(logger, LOG4CPLUS_TEXT("Hello, World!"));
+~~~~
+
+Here we invoke the `LOG4CPLUS_WARN()` macro to log the *Hello, World!* message into the *main* logger. The logged message will be propagated from the *main* logger towards the *root logger* which has a `ConsoleAppender` attached to it to print it on console.
+
+Internally, this macro uses C++ string stream to format the *Hello, World!* message. The consequence of this is that you can use all of the standard C++ streams manipulators.
+
+(De-)Initialization
+-------------------
+
+### Initialization
+
+In most cases, [log4cplus](https://sourceforge.net/projects/log4cplus/) is initialized before `main()` is executed. However, depending on compiler, platform, run time libraries and how log4cplus is linked to, it is possible it will not be initialized automatically. This is why initializing [log4cplus](https://sourceforge.net/projects/log4cplus/) on top of `main()` is a good rule of thumb.
+
+As the previous code example shows, initialization of [log4cplus](https://sourceforge.net/projects/log4cplus/) is done by instantiation of `log4cplus::Initializer` class. This is true for [log4cplus](https://sourceforge.net/projects/log4cplus/) versions 2.0 and later. In previous versions, instead of instantiating this class (the header `log4cplus/initializer.h` and the class do not exist there), call to function `log4cplus::initialize()` is used.
+
+### Deinitialization
+
+[log4cplus](https://sourceforge.net/projects/log4cplus/) tries to deinitialize itself and free all of its allocated resources after `main()` exits. However, again, depending on compiler, platform and run time libraries, it might not be possible. This is why proper deinitialization is *necessary*.
+
+In version 2.0 and later, it is done by the last instance of `log4cplus::Initializer` class and its destructor. In previous versions, calling `Logger::shutdown()` was the proper shutdown method.
+
+Logging macros
+--------------
+
+As we have mentioned earlier, `LOG4CPLUS_WARN()`, `LOG4CPLUS_ERROR()`, etc., macros use C++ string stream under the hood. The following example demonstrates how is it possible to use it with the macros.
+
+Beside these macros, there are two more groups of logging macros. `LOG4CPLUS_*_STR()` can be used for logging messages that are just plain strings that do not need any kind of formatting. There is also group of `LOG4CPLUS_*_FMT()` macros which format logged message using `printf()` formatting string.
+
+~~~~ {.cpp}
+#include &amp;lt;log4cplus logger.h=""&amp;gt;
+#include &amp;lt;log4cplus loggingmacros.h=""&amp;gt;
+#include &amp;lt;log4cplus configurator.h=""&amp;gt;
+#include &amp;lt;log4cplus initializer.h=""&amp;gt;
 #include &amp;lt;iomanip&amp;gt;
-
-using namespace std;
-using namespace log4cplus;

 int
 main()
 {
-    initialize();
-    BasicConfigurator config;
+    log4cplus::Initializer initializer;
+
+    log4cplus::BasicConfigurator config;
     config.configure();
-    Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("logger"));
-
-    LOG4CPLUS_WARN(logger,   "This is"
-                           &amp;lt;&amp;lt; " a reall"
-                           &amp;lt;&amp;lt; "y long message." &amp;lt;&amp;lt; endl
-                           &amp;lt;&amp;lt; "Just testing it out" &amp;lt;&amp;lt; endl
-                           &amp;lt;&amp;lt; "What do you think?");
-    LOG4CPLUS_WARN(logger, "This is a bool: " &amp;lt;&amp;lt; true);
-    LOG4CPLUS_WARN(logger, "This is a char: " &amp;lt;&amp;lt; 'x');
-    LOG4CPLUS_WARN(logger, "This is a short: " &amp;lt;&amp;lt; (short)-100);
-    LOG4CPLUS_WARN(logger, "This is a unsigned short: " &amp;lt;&amp;lt; (unsigned short)100);
-    LOG4CPLUS_WARN(logger, "This is a int: " &amp;lt;&amp;lt; (int)1000);
-    LOG4CPLUS_WARN(logger, "This is a unsigned int: " &amp;lt;&amp;lt; (unsigned int)1000);
-    LOG4CPLUS_WARN(logger, "This is a long(hex): " &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; (long)100000000);
-    LOG4CPLUS_WARN(logger, "This is a unsigned long: " 
-                           &amp;lt;&amp;lt; (unsigned long)100000000);
-    LOG4CPLUS_WARN(logger, "This is a float: " &amp;lt;&amp;lt; 1.2345f);
-    LOG4CPLUS_WARN(logger, "This is a double: " 
-                           &amp;lt;&amp;lt; setprecision(15) 
-                           &amp;lt;&amp;lt; 1.2345234234);
-    LOG4CPLUS_WARN(logger, "This is a long double: " 
-                           &amp;lt;&amp;lt; setprecision(15) 
-                           &amp;lt;&amp;lt; (long double)123452342342.342);
+
+    log4cplus::Logger logger = log4cplus::Logger::getInstance(
+        LOG4CPLUS_TEXT("main"));
+
+    LOG4CPLUS_INFO(logger,
+        LOG4CPLUS_TEXT("This is")
+        &amp;lt;&amp;lt; LOG4CPLUS_TEXT(" a reall")
+        &amp;lt;&amp;lt; LOG4CPLUS_TEXT("y long message.") &amp;lt;&amp;lt; std::endl
+        &amp;lt;&amp;lt; LOG4CPLUS_TEXT("Just testing it out") &amp;lt;&amp;lt; std::endl
+        &amp;lt;&amp;lt; LOG4CPLUS_TEXT("What do you think?"));
+    LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("This is a bool: ") &amp;lt;&amp;lt; true);
+    LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("This is a char: ")
+        &amp;lt;&amp;lt; LOG4CPLUS_TEXT('x'));
+    LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("This is a short: ")
+        &amp;lt;&amp;lt; static_cast&amp;lt;short&amp;gt;(-100));
+    LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("This is a unsigned short: ")
+        &amp;lt;&amp;lt; static_cast&amp;lt;unsigned short=""&amp;gt;(100));
+    LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("This is a int: ") &amp;lt;&amp;lt; 1000);
+    LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("This is a unsigned int: ") &amp;lt;&amp;lt; 1000U);
+    LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("This is a long(hex): ")
+        &amp;lt;&amp;lt; std::hex &amp;lt;&amp;lt; 100000000L);
+    LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("This is a unsigned long: ")
+        &amp;lt;&amp;lt; static_cast&amp;lt;unsigned long=""&amp;gt;(100000000U));
+    LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("This is a float: ") &amp;lt;&amp;lt; 1.2345f);
+    LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("This is a double: ")
+        &amp;lt;&amp;lt; std::setprecision(15)
+        &amp;lt;&amp;lt; 1.2345234234);
+    LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("This is a long double: ")
+        &amp;lt;&amp;lt; std::setprecision(15)
+        &amp;lt;&amp;lt; 123452342342.342L);

     return 0;
 }
 ~~~~

-
-## Log level
-
-This example shows how log messages can be filtered at runtime by adjusting the log level threshold on `Logger` instance.
-
-~~~~{.cpp}
-#include &amp;lt;log4cplus logger.h=""&amp;gt;
-#include &amp;lt;log4cplus loggingmacros.h=""&amp;gt;
-#include &amp;lt;log4cplus configurator.h=""&amp;gt;
+The code above should just print the expected:
+
+    INFO - This is a really long message.
+    Just testing it out
+    What do you think?
+    INFO - This is a bool: 1
+    INFO - This is a char: x
+    INFO - This is a short: -100
+    INFO - This is a unsigned short: 100
+    INFO - This is a int: 1000
+    INFO - This is a unsigned int: 1000
+    INFO - This is a long(hex): 5f5e100
+    INFO - This is a unsigned long: 100000000
+    INFO - This is a float: 1.2345
+    INFO - This is a double: 1.2345234234
+    INFO - This is a long double: 123452342342.342
+
+Beside these macros, there are two more groups of logging macros. `LOG4CPLUS_*_STR()` can be used for logging messages that are just plain strings that do not need any kind of formatting. There is also group of `LOG4CPLUS_*_FMT()` macros which format logged message using `printf()` formatting string.
+
+Log level
+---------
+
+This example shows how log messages can be filtered at run time by adjusting the *log level threshold* on `Logger` instance.
+
+~~~~ {.cpp}
+#include &amp;lt;log4cplus logger.h=""&amp;gt;
+#include &amp;lt;log4cplus loglevel.h=""&amp;gt;
+#include &amp;lt;log4cplus loggingmacros.h=""&amp;gt;
+#include &amp;lt;log4cplus configurator.h=""&amp;gt;
+#include &amp;lt;log4cplus initializer.h=""&amp;gt;
 #include &amp;lt;iomanip&amp;gt;
-#include &amp;lt;iostream&amp;gt;
-
-using namespace std;
-using namespace log4cplus;
-
-Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("main"));
-
-void printMessages()
-{
-    LOG4CPLUS_TRACE(logger, "printMessages()");
-    LOG4CPLUS_DEBUG(logger, "This is a DEBUG message");
-    LOG4CPLUS_INFO(logger, "This is a INFO message");
-    LOG4CPLUS_WARN(logger, "This is a WARN message");
-    LOG4CPLUS_ERROR(logger, "This is a ERROR message");
-    LOG4CPLUS_FATAL(logger, "This is a FATAL message");
-}
-
+
+void
+printMessages(log4cplus::Logger const &amp;amp; logger)
+{
+    // Print messages using all common log levels.
+    LOG4CPLUS_TRACE (logger, "printMessages()");
+    LOG4CPLUS_DEBUG (logger, "This is a DEBUG message");
+    LOG4CPLUS_INFO (logger, "This is a INFO message");
+    LOG4CPLUS_WARN (logger, "This is a WARN message");
+    LOG4CPLUS_ERROR (logger, "This is a ERROR message");
+    LOG4CPLUS_FATAL (logger, "This is a FATAL message");
+}
+
+void
+thresholdTest(log4cplus::LogLevel ll)
+{
+    log4cplus::Logger logger
+        = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("main"));
+
+    // Set log level threshold on logger.
+    logger.setLogLevel(ll);
+
+    // Print messages.
+    log4cplus::tcout
+        &amp;lt;&amp;lt; LOG4CPLUS_TEXT("*** calling printMessages() with ")
+        &amp;lt;&amp;lt; log4cplus::getLogLevelManager().toString(ll)
+        &amp;lt;&amp;lt; LOG4CPLUS_TEXT(" set: ***")
+        &amp;lt;&amp;lt; std::endl;
+    printMessages(logger);
+    log4cplus::tcout &amp;lt;&amp;lt; std::endl;
+}

 int
 main()
 {
-    initialize();
-    BasicConfigurator config;
+    log4cplus::Initializer initializer;
+
+    log4cplus::BasicConfigurator config;
     config.configure();

-    logger.setLogLevel(TRACE_LOG_LEVEL);
-    cout &amp;lt;&amp;lt; "*** calling printMessages() with TRACE set: ***" &amp;lt;&amp;lt; endl;
-    printMessages();
-
-    logger.setLogLevel(DEBUG_LOG_LEVEL);
-    cout &amp;lt;&amp;lt; "\n*** calling printMessages() with DEBUG set: ***" &amp;lt;&amp;lt; endl;
-    printMessages();
-
-    logger.setLogLevel(INFO_LOG_LEVEL);
-    cout &amp;lt;&amp;lt; "\n*** calling printMessages() with INFO set: ***" &amp;lt;&amp;lt; endl;
-    printMessages();
-
-    logger.setLogLevel(WARN_LOG_LEVEL);
-    cout &amp;lt;&amp;lt; "\n*** calling printMessages() with WARN set: ***" &amp;lt;&amp;lt; endl;
-    printMessages();
-
-    logger.setLogLevel(ERROR_LOG_LEVEL);
-    cout &amp;lt;&amp;lt; "\n*** calling printMessages() with ERROR set: ***" &amp;lt;&amp;lt; endl;
-    printMessages();
-
-    logger.setLogLevel(FATAL_LOG_LEVEL);
-    cout &amp;lt;&amp;lt; "\n*** calling printMessages() with FATAL set: ***" &amp;lt;&amp;lt; endl;
-    printMessages();
+    thresholdTest(log4cplus::TRACE_LOG_LEVEL);
+    thresholdTest(log4cplus::DEBUG_LOG_LEVEL);
+    thresholdTest(log4cplus::INFO_LOG_LEVEL);
+    thresholdTest(log4cplus::WARN_LOG_LEVEL);
+    thresholdTest(log4cplus::ERROR_LOG_LEVEL);
+    thresholdTest(log4cplus::FATAL_LOG_LEVEL);

     return 0;
 }
 ~~~~

-## More examples
-
-See sources in `tests/` directory in log4cplus source distribution for more examples of log4cplus usage.
+The code prints fewer and fewer messages as the log level threshold is being risen.
+
+    *** calling printMessages() with TRACE set: ***
+    TRACE - printMessages()
+    DEBUG - This is a DEBUG message
+    INFO - This is a INFO message
+    WARN - This is a WARN message
+    ERROR - This is a ERROR message
+    FATAL - This is a FATAL message
+
+    *** calling printMessages() with DEBUG set: ***
+    DEBUG - This is a DEBUG message
+    INFO - This is a INFO message
+    WARN - This is a WARN message
+    ERROR - This is a ERROR message
+    FATAL - This is a FATAL message
+
+    *** calling printMessages() with INFO set: ***
+    INFO - This is a INFO message
+    WARN - This is a WARN message
+    ERROR - This is a ERROR message
+    FATAL - This is a FATAL message
+
+    *** calling printMessages() with WARN set: ***
+    WARN - This is a WARN message
+    ERROR - This is a ERROR message
+    FATAL - This is a FATAL message
+
+    *** calling printMessages() with ERROR set: ***
+    ERROR - This is a ERROR message
+    FATAL - This is a FATAL message
+
+    *** calling printMessages() with FATAL set: ***
+    FATAL - This is a FATAL message
+
+More examples
+-------------
+
+See sources in `tests/` directory in [log4cplus](https://sourceforge.net/projects/log4cplus/) source distribution for more examples of [log4cplus](https://sourceforge.net/projects/log4cplus/) usage.
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Václav Haisman</dc:creator><pubDate>Tue, 22 Mar 2016 19:28:04 -0000</pubDate><guid>https://sourceforge.net9fdb110154ee8fe8b41e3c10a33a215d36b55e88</guid></item><item><title>CodeExamples modified by Václav Zeman</title><link>https://sourceforge.net/p/log4cplus/wiki/CodeExamples/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v4
+++ v5
@@ -135,3 +135,6 @@
 }
 ~~~~

+## More examples
+
+See sources in `tests/` directory in log4cplus source distribution for more examples of log4cplus usage.
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Václav Zeman</dc:creator><pubDate>Sun, 29 Sep 2013 18:27:40 -0000</pubDate><guid>https://sourceforge.netda27f4d46f553ba29128aee52bcf882076932728</guid></item><item><title>CodeExamples modified by Václav Zeman</title><link>https://sourceforge.net/p/log4cplus/wiki/CodeExamples/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v3
+++ v4
@@ -71,3 +71,67 @@
     return 0;
 }
 ~~~~
+
+
+## Log level
+
+This example shows how log messages can be filtered at runtime by adjusting the log level threshold on `Logger` instance.
+
+~~~~{.cpp}
+#include logger.h&gt;
+#include &lt;log4cplusloggingmacros.h&gt;
+#include configurator.h&gt;
+#include &lt;iomanip&gt;
+#include &lt;iostream&gt;
+
+using namespace std;
+using namespace log4cplus;
+
+Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("main"));
+
+void printMessages()
+{
+    LOG4CPLUS_TRACE(logger, "printMessages()");
+    LOG4CPLUS_DEBUG(logger, "This is a DEBUG message");
+    LOG4CPLUS_INFO(logger, "This is a INFO message");
+    LOG4CPLUS_WARN(logger, "This is a WARN message");
+    LOG4CPLUS_ERROR(logger, "This is a ERROR message");
+    LOG4CPLUS_FATAL(logger, "This is a FATAL message");
+}
+
+
+int
+main()
+{
+    initialize();
+    BasicConfigurator config;
+    config.configure();
+
+    logger.setLogLevel(TRACE_LOG_LEVEL);
+    cout &lt;&lt; "*** calling printMessages() with TRACE set: ***" &lt;&lt; endl;
+    printMessages();
+
+    logger.setLogLevel(DEBUG_LOG_LEVEL);
+    cout &lt;&lt; "\n*** calling printMessages() with DEBUG set: ***" &lt;&lt; endl;
+    printMessages();
+
+    logger.setLogLevel(INFO_LOG_LEVEL);
+    cout &lt;&lt; "\n*** calling printMessages() with INFO set: ***" &lt;&lt; endl;
+    printMessages();
+
+    logger.setLogLevel(WARN_LOG_LEVEL);
+    cout &lt;&lt; "\n*** calling printMessages() with WARN set: ***" &lt;&lt; endl;
+    printMessages();
+
+    logger.setLogLevel(ERROR_LOG_LEVEL);
+    cout &lt;&lt; "\n*** calling printMessages() with ERROR set: ***" &lt;&lt; endl;
+    printMessages();
+
+    logger.setLogLevel(FATAL_LOG_LEVEL);
+    cout &lt;&lt; "\n*** calling printMessages() with FATAL set: ***" &lt;&lt; endl;
+    printMessages();
+
+    return 0;
+}
+~~~~
+
&lt;/iostream&gt;&lt;/iomanip&gt;&lt;/log4cplusloggingmacros.h&gt;&lt;/pre&gt;&lt;pre&gt;
&lt;/pre&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Václav Zeman</dc:creator><pubDate>Sun, 29 Sep 2013 18:25:07 -0000</pubDate><guid>https://sourceforge.net30701d799de19c2bf56634abac7efbee782850d2</guid></item><item><title>CodeExamples modified by Václav Zeman</title><link>https://sourceforge.net/p/log4cplus/wiki/CodeExamples/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Václav Zeman</dc:creator><pubDate>Sun, 29 Sep 2013 18:20:58 -0000</pubDate><guid>https://sourceforge.nete91f60d72ad45ec701ecd1129c2f707785d19e0c</guid></item><item><title>CodeExamples modified by Václav Zeman</title><link>https://sourceforge.net/p/log4cplus/wiki/CodeExamples/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -1,6 +1,8 @@
 # log4cplus code examples

 ## Hello World
+
+Here is a minimal log4cplus source:

 ~~~~{.cpp}
 #include logger.h&gt;
@@ -22,3 +24,50 @@
     return 0;
 }
 ~~~~
+
+## Logging macros
+
+`LOG4CPLUS_WARN`, `LOG4CPLUS_ERROR`, etc. macros use `std::ostream` under the hood. The following example demonstrates how is it possible to use it with the macros.
+
+~~~~{.cpp}
+#include &lt;log4cpluslogger.h&gt;
+#include loggingmacros.h&gt;
+#include &lt;log4cplusconfigurator.h&gt;
+#include 
+
+using namespace std;
+using namespace log4cplus;
+
+int
+main()
+{
+    initialize();
+    BasicConfigurator config;
+    config.configure();
+    Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("logger"));
+
+    LOG4CPLUS_WARN(logger,   "This is"
+                           &lt;&lt; " a reall"
+                           &lt;&lt; "y long message." &lt;&lt; endl
+                           &lt;&lt; "Just testing it out" &lt;&lt; endl
+                           &lt;&lt; "What do you think?");
+    LOG4CPLUS_WARN(logger, "This is a bool: " &lt;&lt; true);
+    LOG4CPLUS_WARN(logger, "This is a char: " &lt;&lt; 'x');
+    LOG4CPLUS_WARN(logger, "This is a short: " &lt;&lt; (short)-100);
+    LOG4CPLUS_WARN(logger, "This is a unsigned short: " &lt;&lt; (unsigned short)100);
+    LOG4CPLUS_WARN(logger, "This is a int: " &lt;&lt; (int)1000);
+    LOG4CPLUS_WARN(logger, "This is a unsigned int: " &lt;&lt; (unsigned int)1000);
+    LOG4CPLUS_WARN(logger, "This is a long(hex): " &lt;&lt; hex &lt;&lt; (long)100000000);
+    LOG4CPLUS_WARN(logger, "This is a unsigned long: " 
+                           &lt;&lt; (unsigned long)100000000);
+    LOG4CPLUS_WARN(logger, "This is a float: " &lt;&lt; 1.2345f);
+    LOG4CPLUS_WARN(logger, "This is a double: " 
+                           &lt;&lt; setprecision(15) 
+                           &lt;&lt; 1.2345234234);
+    LOG4CPLUS_WARN(logger, "This is a long double: " 
+                           &lt;&lt; setprecision(15) 
+                           &lt;&lt; (long double)123452342342.342);
+
+    return 0;
+}
+~~~~
&lt;/log4cplusconfigurator.h&gt;&lt;/log4cpluslogger.h&gt;&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Václav Zeman</dc:creator><pubDate>Sun, 29 Sep 2013 18:18:05 -0000</pubDate><guid>https://sourceforge.net37c6b2a3556a088437475cb1c73d382fd97caa42</guid></item><item><title>CodeExamples modified by Václav Zeman</title><link>https://sourceforge.net/p/log4cplus/wiki/CodeExamples/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="log4cplus-code-examples"&gt;log4cplus code examples&lt;/h1&gt;
&lt;h2 id="hello-world"&gt;Hello World&lt;/h2&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="vi"&gt;#include&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;log4cplus&lt;/span&gt;&lt;span class="p"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;logger.h&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="vi"&gt;#include&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;log4cplus&lt;/span&gt;&lt;span class="p"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;loggingmacros.h&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="vi"&gt;#include&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;log4cplus&lt;/span&gt;&lt;span class="p"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;configurator.h&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="vi"&gt;#include&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;iomanip&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nx"&gt;using&lt;/span&gt; &lt;span class="nx"&gt;namespace&lt;/span&gt; &lt;span class="nx"&gt;log4cplus&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;int&lt;/span&gt;
&lt;span class="nx"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;BasicConfigurator&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;config.configure&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="nx"&gt;Logger&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Logger&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nl"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;LOG4CPLUS_TEXT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;main&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="nx"&gt;LOG4CPLUS_WARN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;LOG4CPLUS_TEXT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Hello, World!&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Václav Zeman</dc:creator><pubDate>Sun, 29 Sep 2013 18:12:57 -0000</pubDate><guid>https://sourceforge.netfe2692bca4ba57899e87b3b0824893874562cc38</guid></item></channel></rss>