blob: 83dd4fb49ffe28b4745429805c09ea6264a6fbbf [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Generated by Apache Maven Doxia at 2020-08-22 -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>log4cxx - - Apache log4cxx</title>
<link rel="stylesheet" href="./css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="./css/site.css" type="text/css" />
<script type="text/javascript" src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/bootstrap.min.js"></script>
<script type="text/javascript" src="./js/prettify.min.js"></script>
<script type="text/javascript" src="./js/site.js"></script>
<meta name="Date-Revision-yyyymmdd" content="20200822" />
<meta http-equiv="Content-Language" content="en" />
</head>
<body class="composite">
<a href="https://logging.apache.org/">
<img class="logo-left" src="./images/logos/ls-logo.jpg" alt="Apache logging services logo" />
</a>
<img class="logo-right" src="./images/logos/logo.png" alt="Apache log4j logo" />
<div class="clear"></div>
<div class="navbar">
<div class="navbar-inner">
<div class="container-fluid">
<a class="brand" href="http://logging.apache.org/log4cxx">Apache log4cxx &#8482;</a>
<ul class="nav">
<li>
<a href="https://wiki.apache.org/logging" class="external" target="_blank" title="Logging Wiki">Logging Wiki</a>
</li>
<li>
<a href="https://www.apache.org/" class="external" target="_blank" title="Apache">Apache</a>
</li>
<li>
<a href="https://logging.apache.org/" class="external" target="_blank" title="Logging Services">Logging Services</a>
</li>
<li>
<a href="https://github.com/apache/logging-log4cxx" class="external" target="_blank" title="GitHub">GitHub</a>
</li>
</ul>
<div class="pull-right">
<span id="publishDate">Last Published: 2020-08-22</span>
<span class="divider">|</span> <span id="projectVersion">Version: 0.11.0</span>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<table class="layout-table">
<tr>
<td class="sidebar">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-home"></i>About</li>
<li class="none">
<a href="index.html" title="What is log4cxx?">What is log4cxx?</a>
</li>
<li class="none">
<a href="project-info.html" title="Project Information">Project Information</a>
</li>
<li class="none">
<a href="project-reports.html" title="Generated Reports">Generated Reports</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-book"></i>Usage</li>
<li class="none">
<a href="usage.html" title="How to use log4cxx?">How to use log4cxx?</a>
</li>
<li class="none">
<a href="apidocs/index.html" title="API Documentation">API Documentation</a>
</li>
<li class="none active">
<a href="faq.html" title="FAQ">FAQ</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-cog"></i>Get</li>
<li class="none">
<a href="download.html" title="Download">Download</a>
</li>
<li class="none">
<a href="changes-report.html" title="Changes">Changes</a>
</li>
<li class="none">
<a href="license.html" title="License">License</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-pencil"></i>Community</li>
<li class="none">
<a href="mail-lists.html" title="Mailing Lists">Mailing Lists</a>
</li>
<li class="none">
<a href="community/issue-tracking.html" title="Issue Tracking">Issue Tracking</a>
</li>
<li class="none">
<a href="https://wiki.apache.org/logging-log4cxx" class="external" target="_blank" title="Wiki">Wiki</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-pencil"></i>Development</li>
<li class="none">
<a href="source-repository.html" title="Repository">Repository</a>
</li>
<li class="none">
<a href="dependencies.html" title="Dependencies">Dependencies</a>
</li>
<li class="expanded">
<a href="building/index.html" title="Building">Building</a>
<ul>
<li class="none">
<a href="building/maven.html" title="Apache Maven 2">Apache Maven 2</a>
</li>
<li class="none">
<a href="building/autotools.html" title="Autotools">Autotools</a>
</li>
<li class="none">
<a href="building/cmake.html" title="CMake">CMake</a>
</li>
<li class="none">
<a href="building/vcpkg.html" title="Microsoft vcpkg">Microsoft vcpkg</a>
</li>
</ul>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-info-sign"></i>Apache</li>
<li class="none">
<a href="https://www.apache.org" class="external" target="_blank" title="Home">Home</a>
</li>
<li class="none">
<a href="https://www.apache.org/foundation/sponsorship.html" class="external" target="_blank" title="Sponsorship">Sponsorship</a>
</li>
<li class="none">
<a href="https://www.apache.org/foundation/thanks.html" class="external" target="_blank" title="Thanks">Thanks</a>
</li>
<li class="none">
<a href="https://www.apachecon.com" class="external" target="_blank" title="Conferences">Conferences</a>
</li>
</ul>
</div>
<div id="poweredBy">
<a href="https://maven.apache.org/" title="Built by Maven" class="poweredBy">
<img class="poweredBy" alt="Built by Maven" src="./images/logos/maven-feather.png" />
</a>
</div>
</td>
<td class="content">
<!-- Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. --><h1>Frequently Asked Technical Questions</h1>
<div class="section">
<h2><a name="table_of_contents"></a>Table of contents<a name="Table_of_contents"></a></h2>
<ol style="list-style-type: decimal">
<li><a href="#custom_levels">How do I add a custom level to Apache log4cxx?</a></li>
<li><a href="#msvc_crash">My application on Windows crashes on shutdown?</a></li>
<li><a href="#unicode_supported">Does Apache log4cxx support Unicode?</a></li>
</ol></div>
<div class="section">
<h2><a name="custom_levels"></a>How do I add a custom level to Apache log4cxx?<a name="How_do_I_add_a_custom_level_to_Apache_log4cxx"></a></h2>
<p>This is a common topic for all the Apache logging frameworks and typically motivated to try to categorize events by functionality or audience. An common request is to add an AUDIT level so that the user can configure AUDIT level messages to go to a specific appender. However, the logger name was designed explicitly to support routing of messages by topic or audience. The common pattern of using classnames for logger names obscures the more general capability of logger name to represent the topic or audience of the logging request. The easiest approach to solve the underlying issue is to use a logger names like &#x201c;AUDIT.com.example.MyPackage.MyClass&#x201d; that allow all AUDIT messages to be routed to a particular appender. If you attempted to use a level for that then you would lose the ability to distinguish between different significances within the audit messages.</p></div>
<div class="section">
<h2><a name="msvc_crash"></a>My application on Windows crashes on shutdown?<a name="My_application_on_Windows_crashes_on_shutdown"></a></h2>
<p>Apache log4cxx API calls use C++ Standard Template Library string parameters. If the caller is using a different instance or type of the C Runtime Library that log4cxx, then it is very likely that some memory that was originally allocated by log4cxx would be freed by the caller. If log4cxx and the caller are using different C RTL&#x2019;s, the program will likely crash at the point. Use &#x201c;Multithread DLL&#x201d; with release builds of log4cxx and &#x201c;Multithread DLL Debug&#x201d; with debug builds.</p></div>
<div class="section">
<h2><a name="unicode_supported"></a>Does Apache log4cxx support Unicode?<a name="Does_Apache_log4cxx_support_Unicode"></a></h2>
<p>Yes. Apache log4cxx exposes API methods in multiple string flavors supporting differently encoded textual content, like <tt>char*</tt>, <tt>std::string</tt>, <tt>wchar_t*</tt>, <tt>std::wstring</tt>, <tt>CFStringRef</tt> et al. All provided texts will be converted to the <tt>LogString</tt> type before further processing, which is one of several supported Unicode representations selected by the <tt>--with-logchar</tt> option. If methods are used that take <tt>LogString</tt> as arguments, the macro <tt>LOG4CXX_STR()</tt> can be used to convert literals to the current <tt>LogString</tt> type. FileAppenders support an encoding property as well, which should be explicitly specified to <tt>UTF-8</tt> or <tt>UTF-16</tt> for e.g. XML files. The important point is to get the chain of input, internal processing and output correct and that might need some additional setup in the app using log4cxx:</p>
<p>According to the <a class="externalLink" href="https://www.gnu.org/software/libc/manual/html_node/Setting-the-Locale.html">libc documentation</a>, all programs start in the <tt>C</tt> locale by default, which is the <a class="externalLink" href="https://stackoverflow.com/questions/48743106/whats-ansi-x3-4-1968-encoding">same as ANSI_X3.4-1968</a> and what&#x2019;s commonly known as the encoding <tt>US-ASCII</tt>. That encoding supports a very limited set of characters only, so inputting Unicode with that encoding in effect to output characters can&#x2019;t work properly. For example, here is some Hebrew text which says &#x201c;People with disabilities&#x201d;:</p>
<div class="source">
<pre>&#x5e0;&#x5e9;&#x5d9;&#x5dd; &#x5e2;&#x5dd; &#x5de;&#x5d5;&#x5d2;&#x5d1;&#x5dc;&#x5d5;&#x5ea;
</pre></div>
<p>If you are to log this information, output on some console might be like the following, simply because the app uses <tt>US-ASCII</tt> by default and that can&#x2019;t map those characters:</p>
<div class="source">
<pre>loggername - ?????????? ???? ??????????????
</pre></div>
<p>The important thing to understand is that this is some always applied, backwards compatible default behaviour and even the case when the current environment sets a locale like <tt>en_US.UTF-8</tt>. One might need to explicitly tell the app at startup to use the locale of the environment and make things compatible with Unicode this way. See also <a class="externalLink" href="https://stackoverflow.com/questions/571359/how-do-i-set-the-proper-initial-locale-for-a-c-program-on-windows">some SO post</a> on setting the default locale in C++.</p>
<div class="source">
<pre>std::setlocale( LC_ALL, &quot;&quot; ); /* Set locale for C functions */
std::locale::global(std::locale(&quot;&quot;)); /* set locale for C++ functions */
</pre></div>
<p>See <a class="externalLink" href="https://issues.apache.org/jira/browse/LOGCXX-483">LOGCXX-483</a> or <a class="externalLink" href="https://github.com/apache/logging-log4cxx/pull/31#issuecomment-668870727">GHPR #31</a> for additional details.</p></div>
</td>
</tr>
</table>
</div>
<div class="footer">
<p>Copyright © 2003-2020 <a class="external" href="http://www.apache.org">Apache Software Foundation</a>. All Rights Reserved.</p>
<p>Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, and the Apache Logging project logo are trademarks of The Apache Software Foundation.</p>
<p>Site powered by <a class="external" href="https://getbootstrap.com/">Twitter Bootstrap</a>. Icons from <a class="external" href="https://glyphicons.com/">Glyphicons Free</a>.</p>
</div>
</body>
</html>