README 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. % log4cplus README
  2. Short Description
  3. =================
  4. log4cplus is a simple to use C++ logging API providing thread-safe,
  5. flexible, and arbitrarily granular control over log management and
  6. configuration. It is modeled after the Java log4j API.
  7. Latest Project Information
  8. ==========================
  9. The latest up-to-date information for this project can be found at
  10. [log4cplus.sourceforge.net](http://log4cplus.sourceforge.net). Please
  11. submit bugs, patches, feature requests, etc., there.
  12. Tested on the following platforms
  13. =================================
  14. - Linux/AMD64 with GCC 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1)
  15. - Linux/AMD64 with Sun C++ 5.12 Linux_i386 2011/11/16
  16. - Linux/AMD64 with Clang version 3.2-1~exp9ubuntu1
  17. (tags/RELEASE_32/final) (based on LLVM 3.2)
  18. - Linux/AMD64 with Intel(R) C++ Intel(R) 64 Compiler XE for
  19. applications running on Intel(R) 64, Version 12.1 Build 20120410
  20. - FreeBSD/AMD64 with GCC 3.4.6, 4.2.1 and 4.3.3
  21. - Windows 7 with MS Visual C++ 10.0
  22. - OpenSolaris 5.11 with Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21,
  23. with -library=stlport4
  24. - Solaris 5.10 with Sun C++ 5.8 2005/10/13, with -library=stlport4
  25. - NetBSD 5.0.2/AMD64 with GCC 4.1.3 20080704 prerelease (NetBSD nb2
  26. 20081120)
  27. - OpenBSD 5.0/AMD64 with GCC 4.2.1 20070719
  28. - Haiku R1 Alpha 4.1 with GCC 4.6.3
  29. Configure script options
  30. ========================
  31. `--enable-debugging`
  32. --------------------
  33. This option is disabled by default. This option mainly affects GCC
  34. builds but it also has some limited effect on non-GCC builds. It
  35. turns on debugging information generation, undefines `NDEBUG` symbol
  36. and adds `-fstack-check` (GCC).
  37. `--enable-warnings`
  38. -------------------
  39. This option is enabled by default. It adds platform / compiler
  40. dependent warning options to compiler command line.
  41. `--enable-so-version`
  42. ---------------------
  43. This option is enabled by default. It enables SO version decoration
  44. on resulting library file, e.g., the `.2.0.0` in
  45. `liblog4cplus-1.2.so.2.0.0`.
  46. `--enable-release-version`
  47. --------------------------
  48. This option is enabled by default. It enables release version
  49. decoration on the resulting library file, e.g., the `-1.2` in
  50. `liblog4cplus-1.2.so.2.0.0`.
  51. `--enable-symbols-visibility-options`
  52. -------------------------------------
  53. This option is enabled by default. It enables use of compiler and
  54. platform specific option for symbols visibility. See also the
  55. [Visibility](http://gcc.gnu.org/wiki/Visibility) page on GCC Wiki.
  56. `--enable-profiling`
  57. --------------------
  58. This option is disabled by default. This option adds profiling
  59. information generation compiler option `-pg` to GCC and Sun CC /
  60. Solaris Studio builds.
  61. `--enable-threads`
  62. ------------------
  63. This option is enabled by default. It turns on detection of necessary
  64. compiler and linker flags that enable POSIX threading support.
  65. While this detection usually works well, some platforms still need
  66. help with configuration by supplying additional flags to the configure
  67. script. One of the know deficiencies is Solaris Studio on Linux. See
  68. one of the later note for details.
  69. `--with-working-locale`
  70. -----------------------
  71. This is one of three locale and `wchar_t` <-> `char` conversion
  72. related options. It is disabled by default.
  73. It is know to work well with GCC on Linux. Other platforms generally
  74. have lesser locale support in their implementations of the C++
  75. standard library. It is known not to work well on any BSDs.
  76. See also docs/unicode.txt.
  77. `--with-working-c-locale`
  78. -------------------------
  79. This is second of `wchar_t` <-> `char` conversion related options. It
  80. is disabled by default.
  81. It is known to work well on most Unix--like platforms, including
  82. recent Cygwin.
  83. `--with-iconv`
  84. --------------
  85. This is third of `wchar_t` <-> `char` conversion related options. It is
  86. disabled by default.
  87. The conversion using iconv() function always uses `"UTF-8"` and
  88. `"WCHAR_T"` as source/target encoding. It is known to work well on
  89. platforms with GNU iconv. Different implementations of `iconv()`
  90. might not support `"WCHAR_T"` encoding selector.
  91. Either system provided `iconv()` or library provided `libiconv()` are
  92. detected and accepted. Also both SUSv3 and GNU `iconv()` function
  93. signatures are accepted.
  94. `--with-qt`
  95. -----------
  96. This option is disabled by default. It enables compilation of a
  97. separate shared library (liblog4cplusqt4debugappender) that implements
  98. `Qt4DebugAppender`. It requires Qt4 and pkg-config to be installed.
  99. Notes
  100. =====
  101. Cygwin/MinGW
  102. ------------
  103. Some version of GCC (3.4.x and probably some of 4.x series too) on
  104. Windows (both Mingw and Cygwin) produces lots of warnings of the form:
  105. > warning: inline function 'void foo()' is declared as dllimport:
  106. attribute ignored
  107. This can be worked around by adding `-Wno-attributes` option to GCC
  108. command. Unfortunately, not all affected version of GCC have this
  109. option.
  110. MinGW and MSVCRT version
  111. ------------------------
  112. log4cplus can use functions like `_vsnprintf_s()` (Microsoft's secure
  113. version of `vsnprintf()`). MinGW tool--chains (by default) link to the
  114. system MSVCRT.DLL. Unfortunately, older systems, like Windows XP, ship
  115. with MSVCRT.DLL that lacks these functions. It is possible to compile
  116. log4cplus with MinGW tool--chains but _without_ using the Microsoft's
  117. secure functions by defining `__MSVCRT_VERSION__` to value less than
  118. `0x900` and vice versa.
  119. $ ../configure CPPFLAGS="-D__MSVCRT_VERSION__=0x700"
  120. Windows and TLS
  121. ---------------
  122. log4cplus uses thread-local storage (TLS) for NDC, MDC and to optimize
  123. use of some temporary objects. On Windows there are two ways to get
  124. TLS:
  125. (1) using `TlsAlloc()`, etc., functions
  126. (2) using `__declspec(thread)`
  127. While method (2) generates faster code, it has some limitations prior
  128. to Windows Vista. If log4cplus.dll is loaded at run time using
  129. `LoadLibrary()` (or as a dependency of such loaded library), then
  130. accessing `__declspec(thread)` variables can cause general protection
  131. fault (GPF) errors. This is because Windows prior to Windows Vista do
  132. not extend the TLS for libraries loaded at run time using
  133. LoadLibrary(). To allow using the best available method, log4cplus
  134. enables the method (2) by checking `_WIN32_WINNT >= 0x0600` condition,
  135. when compiling log4cplus targeted to Windows Vista or later.
  136. Android, TLS and CMake
  137. ----------------------
  138. [log4cplus] uses thread--local storage (TLS, see "Windows and TLS" for
  139. details). On the Android platform, when [log4cplus] is being compiled using
  140. the `android/android.toolchain.cmake`, you might get errors featuring the
  141. `__emutls` symbol:
  142. global-init.cxx:268:46: error: log4cplus::internal::__emutls_t._ZN9log4cplus8internal3ptdE causes a section type conflict with log4cplus::internal::ptd
  143. To work around this issue, invoke CMake with
  144. `-DANDROID_FUNCTION_LEVEL_LINKING:BOOL=OFF` option.
  145. Threads and signals
  146. -------------------
  147. log4cplus is not safe to be used from asynchronous signals' handlers.
  148. This is a property of most threaded programmes in general. If you are
  149. going to use log4cplus in threaded application and if you want to use
  150. log4cplus from signal handlers then your only option is to block
  151. signals in all threads but one that will handle all signals. On POSIX
  152. platforms, this is possible using the `sigwait()` call. log4cplus
  153. enables this approach by blocking all signals in any threads created
  154. through its threads helpers.
  155. IBM's XL C/C++ compiler
  156. -----------------------
  157. IBM's XL C/C++ compiler executable has [many variants][1]. To compile
  158. log4cplus with threading support specify one of the compiler variants
  159. that support threading using the `CXX` variable on configure script
  160. command line. E.g.:
  161. $ ../configure --enable-threads CXX=xlC_r
  162. [1]: http://pic.dhe.ibm.com/infocenter/comphelp/v121v141/index.jsp?topic=%2Fcom.ibm.xlcpp121.aix.doc%2Fcompiler_ref%2Ftucmpinv.html
  163. AIX reentrancy problem
  164. ----------------------
  165. There appears to be a reentracy problem with AIX 5.3 and xlC 8 which
  166. can result into a deadlock condition in some circumstances. It is
  167. unknown whether the problem manifests with other versions of either
  168. the OS or the compiler, too. The problem was initially reported in a
  169. bug report [#103][2].
  170. The core of the problem is that IBM's/xlC's standard C++ IOStreams
  171. implementation uses global non recursive lock to protect some of its
  172. state. The application in the bug report was trying to do logging
  173. using log4cplus from inside `overflow()` member function of a class
  174. derived from `std::streambuf` class. log4cplus itself uses
  175. `std::ostringstream`. This resulted into an attempt to recursively
  176. lock the global non recursive lock and a deadlock.
  177. [2]: http://sourceforge.net/p/log4cplus/bugs/103/
  178. Solaris / SunOS
  179. ---------------
  180. Some older version of this operating system might have problems
  181. linking log4cplus due to [missing `__tls_get_addr`][3] in their
  182. unpatched state.
  183. [3]: https://groups.google.com/d/msg/comp.unix.solaris/AAMqkK0QZ6U/zlkVKA1L_QcJ
  184. Solaris Studio
  185. --------------
  186. Solaris Studio compilers' default standard C++ library is very
  187. non-standard. It seems that it is not conforming enough in, e.g., Sun
  188. C++ 5.12 Linux_i386 2011/11/16 (missing `std::time_t`, etc.), but it
  189. works well enough on Solaris with Sun C++ 5.8 2005/10/13. Thus
  190. log4cplus adds `-library=stlport4` to the `CXXFLAGS` environment
  191. variable, unless a switch matching `-library=(stlport4|stdcxx4|Cstd)`
  192. is already present there. If you want to override the default
  193. supplied by log4cplus, just set it into `CXXFLAGS` on configure script
  194. command line.
  195. Solaris Studio supports the `__func__` symbol which can be used by
  196. log4cplus to record function name in logged events. To enable this
  197. feature, add `-features=extensions` switch to `CXXFLAGS` for configure
  198. script. Subsequently, you will have to add this switch to your
  199. application's build flags as well.
  200. Solaris Studio on GNU/Linux
  201. ---------------------------
  202. The autotools and our configure.ac combo does not handle Solaris
  203. Studio compiler on Linux well enough and needs a little help with
  204. configuration of POSIX threads:
  205. $ COMMON_FLAGS="-L/lib/x86_64-linux-gnu/ \
  206. -L/usr/lib/x86_64-linux-gnu/ -mt=yes -O"
  207. $ ../configure --enable-threads=yes \
  208. CC=/opt/solarisstudio12.3/bin/cc \
  209. CXX=/opt/solarisstudio12.3/bin/CC \
  210. CFLAGS="$COMMON_FLAGS" \
  211. CXXFLAGS="$COMMON_FLAGS" \
  212. LDFLAGS="-lpthread"
  213. HP-UX with aCC
  214. --------------
  215. It is necessary to turn on C++98 mode of aCC by providing the `-AA` flag:
  216. $ ../configure --enable-threads=yes CXXFLAGS="-AA"
  217. HP-UX with `aCC` on IA64
  218. ------------------------
  219. There is a problem on I64 HP-UX with `aCC` (HP C/aC++ B3910B
  220. A.06.20). The problem manifests as
  221. [unsatisfied symbols during linking of `loggingserver`][9]:
  222. ld: Unsatisfied symbol "virtual table of loggingserver::ClientThread" in file loggingserver.o
  223. The problem appears to be a deficiency in `aCC` and its support of
  224. `__declspec(dllexport)`. To work around this issue, add
  225. `--disable-symbols-visibility-options` to `configure` script command
  226. line:
  227. $ ../configure --disable-symbols-visibility-options \
  228. --enable-threads=yes CXXFLAGS="-AA"
  229. [9]: http://h30499.www3.hp.com/t5/Languages-and-Scripting/Building-Log4cplus-fails-with-quot-ld-Unsatisfied-symbol-virtual/td-p/6261411#.UoHtgPmet8G
  230. Haiku
  231. -----
  232. Haiku is supported with GCC 4+. The default GCC version in Haiku is
  233. set to version 2 (based on GCC 2.95.x). To change the default GCC
  234. version to version 4, please run `setgcc gcc4` command. This is to
  235. avoid linking errors like this:
  236. ~~~~
  237. main.cpp:(.text.startup+0x54a): undefined reference to `_Unwind_Resume'
  238. ~~~~
  239. Running the command switches the _current_ GCC version to version 4.
  240. This change is permanent and global. See also Haiku ticket
  241. [#8368](http://dev.haiku-os.org/ticket/8368).
  242. Qt4 / Win32 / MSVC
  243. ------------------
  244. In order to use log4cplus in Qt4 programs it is necessary to set
  245. following option: `Treat WChar_t As Built in Type: No (/Zc:wchar_t-)`
  246. Set this option for log4cplus project and `Qt4DebugAppender` project
  247. in MS Visual Studio. Remember to use Unicode versions of log4cplus
  248. libraries with Qt. It is also necessary to make clear distinction
  249. between debug and release builds of Qt project and log4cplus. Do not
  250. use log4cplus release library with debug version of Qt program or vice
  251. versa.
  252. For registering Qt4DebugAppender library at runtime, call this
  253. function: `log4cplus::Qt4DebugAppender::registerAppender()`
  254. Add these lines to qmake project file for using log4cplus and
  255. `Qt4DebugAppender`:
  256. INCLUDEPATH += C:\log4cplus\include
  257. win32 {
  258. CONFIG(debug, debug|release) {
  259. LIBS += -LC:\log4cplus\msvc10\Win32\bin.Debug_Unicode -llog4cplusUD
  260. LIBS += -LC:\log4cplus\msvc10\Win32\bin.Debug_Unicode -llog4cplus-Qt4DebugAppender
  261. } else {
  262. LIBS += -LC:\log4cplus\msvc10\Win32\bin.Release_Unicode -llog4cplusU
  263. LIBS += -LC:\log4cplus\msvc10\Win32\bin.Release_Unicode -llog4cplus-Qt4DebugAppender
  264. }
  265. }
  266. `LOG4CPLUS_*_FMT()` and UNICODE
  267. -------------------------------
  268. Beware, the `%s` specifier does not work the same way on Unix--like
  269. platforms as it does on Windows with Visual Studio. With Visual Studio
  270. the `%s` specifier changes its meaning conveniently by printing
  271. `wchar_t` string when used with `wprintf()` and `char` strings when
  272. used with `printf()`. On the other hand, Unix--like platforms keeps
  273. the meaning of printing `char` strings when used with both `wprintf()`
  274. and `printf()`. It is necessary to use `%ls` (C99) specifier or `%S`
  275. (SUSv2) specifier to print `wchar_t` strings on Unix--like platforms.
  276. The common ground for both platforms appears to be use of `%ls` and
  277. `wchar_t` string to print strings with unmodified formatting string
  278. argument on both Unix--like platforms and Windows. The conversion of
  279. `wchar_t` back to `char` then depends on C locale.
  280. C++11 support
  281. -------------
  282. log4cplus contains small amount of code that uses C++11 (ISO/IEC
  283. 14882:2011 standard) language features. C++11 features are used only
  284. if C++11 support is detected during compile time. Compiling log4cplus
  285. with C++11 compiler and standard library and using it with C++03
  286. (ISO/IEC 14882:2003 standard) application is not supported.
  287. Unsupported compilers
  288. ---------------------
  289. log4cplus does not support too old or broken C++ compilers:
  290. - Visual C++ prior to 7.1
  291. - GCC prior to 3.2
  292. - Older versions of Borland/CodeGear/Embarcadero C++ compilers
  293. Unsupported platforms
  294. ---------------------
  295. log4cplus requires some minimal set of C and/or C++ library
  296. functions. Some systems/platforms fail to provide these functions and
  297. thus log4cplus cannot be supported there:
  298. - Windows CE - missing implementations of `<time.h>` functions
  299. License
  300. =======
  301. This library is licensed under the Apache Public License 2.0 and two
  302. clause BSD license. Please read the included LICENSE file for
  303. details.