Skip to content

Commit cbb97a8

Browse files
committed
The locale for C function is required by the ConsoleAppender
1 parent acf207e commit cbb97a8

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/site/markdown/faq.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,25 @@ used that take `LogString` as arguments, the macro `LOG4CXX_STR()` can be used t
5252
to the current `LogString` type.
5353

5454
The default external representation is controlled by the `LOG4CXX_CHARSET` cmake option.
55-
FileAppenders support an `Encoding` property allowing character set encoding control per appender.
56-
For example, you can use `UTF-8` or `UTF-16` when writing XML or JSON layouts.
55+
This default is used to encode a multi-byte characters
56+
unless an `Encoding` property is explicitly configured
57+
for the log4cxx::FileAppender specialization use use.
58+
Note you should use `UTF-8` or `UTF-16` encoding when writing XML or JSON layouts.
5759
Log4cxx also implements character set encodings for `US-ASCII` (`ISO646-US` or `ANSI_X3.4-1968`)
5860
and `ISO-8859-1` (`ISO-LATIN-1` or `CP1252`).
5961
You are highly encouraged to stick to `UTF-8` for the best support from tools and operating systems.
6062

6163
The `locale` character set encoding provides support beyond the above internally implemented options.
6264
It allows you to use any multi-byte encoding provided by the standard library.
63-
See also [some SO post](https://stackoverflow.com/questions/571359/how-do-i-set-the-proper-initial-locale-for-a-c-program-on-windows)
64-
on setting the default locale in C++.
65+
If using the `locale` character set encoding or the log4cxx::ConsoleAppender
66+
you will need to explicitly configure the system locale at startup.
6567

6668
```
67-
std::setlocale( LC_ALL, "" ); /* Set locale for C functions */
68-
std::locale::global(std::locale("")); /* set locale for C++ functions */
69+
std::setlocale( LC_ALL, "" ); /* Set user-preferred locale for the ConsoleAppender */
70+
std::locale::global(std::locale("")); /* Set user-preferred locale for FileAppenders */
6971
```
7072

71-
According to the [libc documentation](https://www.gnu.org/software/libc/manual/html_node/Setting-the-Locale.html),
73+
This is necessary because, according to the [libc documentation](https://www.gnu.org/software/libc/manual/html_node/Setting-the-Locale.html),
7274
all programs start in the `C` locale by default, which is the [same as ANSI_X3.4-1968](https://stackoverflow.com/questions/48743106/whats-ansi-x3-4-1968-encoding)
7375
and what's commonly known as the encoding `US-ASCII`. That encoding supports a very limited set of
7476
characters only, so inputting Unicode with that encoding in effect to output characters can't work
@@ -85,8 +87,3 @@ loggername - ?????????? ???? ??????????????
8587

8688
The important thing to understand is that this is some always applied, backwards compatible default
8789
behaviour and even the case when the current environment sets a locale like `en_US.UTF-8`.
88-
89-
So when using the `locale` character set encoding you will, at startup,
90-
need to explicitly set the `std::locale` to a value able to encode your characters
91-
and which is supported on your operating environment.
92-

0 commit comments

Comments
 (0)