You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2024/10/18 06:51:16 UTC
(logging-log4cxx-site) 06/21: Modernize Log4cxx customization example code
This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx-site.git
commit b44c9b09947435e81dd599edddc1614c148781ac
Author: Stephen Webb <sw...@gmail.com>
AuthorDate: Fri May 10 14:30:07 2024 +1000
Modernize Log4cxx customization example code
---
1.3.0/extending-log4cxx.html | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/1.3.0/extending-log4cxx.html b/1.3.0/extending-log4cxx.html
index e7ce570d..5ddd3333 100644
--- a/1.3.0/extending-log4cxx.html
+++ b/1.3.0/extending-log4cxx.html
@@ -116,16 +116,15 @@ $(document).ready(function(){initNavTree('extending-log4cxx.html',''); initResiz
<p>The first thing for our example is to create a class that extends <a class="el" href="classlog4cxx_1_1AppenderSkeleton.html" title="Implementation base class for all appenders.">log4cxx.AppenderSkeleton</a> so that we don't need to implement all of the virtual methods that are defined in <a class="el" href="classlog4cxx_1_1Appender.html" title="Implement this interface for your own strategies for outputting log statements.">log4cxx.Appender</a>:</p>
<div class="fragment"><div class="line"><span class="keyword">namespace </span><a class="code hl_namespace" href="namespacelog4cxx.html">log4cxx</a> {</div>
<div class="line"> </div>
-<div class="line"><span class="keyword">class </span>NullWriterAppender : <span class="keyword">public</span> <a class="code hl_class" href="classlog4cxx_1_1AppenderSkeleton.html">log4cxx::AppenderSkeleton</a> {</div>
+<div class="line"><span class="keyword">class </span>NullWriterAppender : <span class="keyword">public</span> AppenderSkeleton {</div>
<div class="line">};</div>
<div class="line"> </div>
<div class="line">}</div>
-<div class="ttc" id="aclasslog4cxx_1_1AppenderSkeleton_html"><div class="ttname"><a href="classlog4cxx_1_1AppenderSkeleton.html">log4cxx::AppenderSkeleton</a></div><div class="ttdoc">Implementation base class for all appenders.</div><div class="ttdef"><b>Definition:</b> appenderskeleton.h:41</div></div>
<div class="ttc" id="anamespacelog4cxx_html"><div class="ttname"><a href="namespacelog4cxx.html">log4cxx</a></div><div class="ttdef"><b>Definition:</b> configuration.h:25</div></div>
</div><!-- fragment --><p>Next, we need to add in a few macros in order to properly register our new appender with Log4cxx:</p>
<div class="fragment"><div class="line"><span class="keyword">namespace </span><a class="code hl_namespace" href="namespacelog4cxx.html">log4cxx</a> {</div>
<div class="line"> </div>
-<div class="line"><span class="keyword">class </span>NullWriterAppender : <span class="keyword">public</span> <a class="code hl_class" href="classlog4cxx_1_1AppenderSkeleton.html">log4cxx::AppenderSkeleton</a> {</div>
+<div class="line"><span class="keyword">class </span>NullWriterAppender : <span class="keyword">public</span> AppenderSkeleton {</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line"> <a class="code hl_define" href="object_8h.html#a9e129ec12609d98bb2a10d15b46709ba">DECLARE_LOG4CXX_OBJECT</a>(NullWriterAppender)</div>
<div class="line"> <a class="code hl_define" href="object_8h.html#ac8ff8f70159e03fe7d8c4aa743cc9cda">BEGIN_LOG4CXX_CAST_MAP</a>()</div>
@@ -156,27 +155,31 @@ $(document).ready(function(){initNavTree('extending-log4cxx.html',''); initResiz
<p>These are basically stub methods, with a few comments on their use:</p>
<div class="fragment"><div class="line">NullWriterAppender(){}</div>
<div class="line"> </div>
-<div class="line"><span class="keyword">virtual</span> <span class="keywordtype">void</span> close(){}</div>
+<div class="line"><span class="keywordtype">void</span> close()<span class="keyword"> override </span>{}</div>
<div class="line"> </div>
-<div class="line"><span class="keyword">virtual</span> <span class="keywordtype">bool</span> requiresLayout()<span class="keyword"> const </span>{</div>
+<div class="line"><span class="keywordtype">bool</span> requiresLayout()<span class="keyword"> const override </span>{</div>
<div class="line"> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line">}</div>
<div class="line"> </div>
-<div class="line"><span class="keyword">virtual</span> <span class="keywordtype">void</span> append(<span class="keyword">const</span> spi::LoggingEventPtr& event, <a class="code hl_class" href="classlog4cxx_1_1helpers_1_1Pool.html">log4cxx::helpers::Pool</a>& p){</div>
+<div class="line"><span class="keywordtype">void</span> append(<span class="keyword">const</span> spi::LoggingEventPtr& event, helpers::Pool& p)<span class="keyword"> override </span>{</div>
<div class="line"> <span class="comment">// This gets called whenever there is a valid event for our appender.</span></div>
<div class="line">}</div>
<div class="line"> </div>
-<div class="line"><span class="keyword">virtual</span> <span class="keywordtype">void</span> activateOptions(<a class="code hl_class" href="classlog4cxx_1_1helpers_1_1Pool.html">log4cxx::helpers::Pool</a>& <span class="comment">/* pool */</span>) {</div>
+<div class="line"><span class="keywordtype">void</span> activateOptions(helpers::Pool& pool)<span class="keyword"> override </span>{</div>
<div class="line"> <span class="comment">// Given all of our options, do something useful(e.g. open a file)</span></div>
<div class="line">}</div>
<div class="line"> </div>
-<div class="line"><span class="keyword">virtual</span> <span class="keywordtype">void</span> setOption(<span class="keyword">const</span> LogString& option, <span class="keyword">const</span> LogString& value){</div>
-<div class="line"> <span class="keywordflow">if</span> (helpers::StringHelper::equalsIgnoreCase(option,</div>
-<div class="line"> LOG4CXX_STR(<span class="stringliteral">"SOMEVALUE"</span>), LOG4CXX_STR(<span class="stringliteral">"somevalue"</span>))){</div>
+<div class="line"><span class="keywordtype">void</span> setOption(<span class="keyword">const</span> LogString& option, <span class="keyword">const</span> LogString& value)<span class="keyword"> override </span>{</div>
+<div class="line"> <span class="keywordflow">if</span> (helpers::StringHelper::equalsIgnoreCase</div>
+<div class="line"> ( option</div>
+<div class="line"> , LOG4CXX_STR(<span class="stringliteral">"SOMEVALUE"</span>)</div>
+<div class="line"> , LOG4CXX_STR(<span class="stringliteral">"somevalue"</span>)</div>
+<div class="line"> )</div>
+<div class="line"> )</div>
+<div class="line"> {</div>
<div class="line"> <span class="comment">// Do something with the 'value' here.</span></div>
<div class="line"> }</div>
<div class="line">}</div>
-<div class="ttc" id="aclasslog4cxx_1_1helpers_1_1Pool_html"><div class="ttname"><a href="classlog4cxx_1_1helpers_1_1Pool.html">log4cxx::helpers::Pool</a></div><div class="ttdef"><b>Definition:</b> pool.h:33</div></div>
</div><!-- fragment --><p>At this point, we now have a fully functioning(if useless) custom appender. We can now refer to this appender in our configuration file like so:</p>
<div class="fragment"><div class="line"><?<span class="keyword">xml</span> <span class="keyword">version</span>=<span class="stringliteral">"1.0"</span> <span class="keyword">encoding</span>=<span class="stringliteral">"UTF-8"</span> ?></div>
<div class="line"><<span class="keywordtype">log4j:configuration</span> <span class="keyword">xmlns:log4j</span>=<span class="stringliteral">"http://jakarta.apache.org/log4j/"</span>></div>