add log4cplus

This commit is contained in:
gmueller 2011-07-04 11:56:19 +02:00
parent d7abbcb5c7
commit dafe52c4cd
99 changed files with 18973 additions and 2 deletions

5
libs/log4cplus/AUTHORS Normal file
View File

@ -0,0 +1,5 @@
Tad E. Smith <tcsmith@users.sourceforge.net>
Michael CATANZARITI
Steighton Haley <baldheadedguy@users.sourceforge.net>
Eduardo Francos <gualo@users.sourceforge.net>
Vaclav Haisman <wilx@users.sourceforge.net>

View File

@ -0,0 +1,145 @@
set (log4cplus_version_major 1)
set (log4cplus_version_minor 0)
set (log4cplus_version_patch 4)
set (log4cplus_soversion 4)
set (log4cplus_postfix "")
find_package (Threads)
message (STATUS "Threads: ${CMAKE_THREAD_LIBS_INIT}")
set (log4cplus_headers
include/log4cplus/appender.h
include/log4cplus/config/macosx.h
include/log4cplus/config/win32.h
include/log4cplus/config.hxx
include/log4cplus/configurator.h
include/log4cplus/consoleappender.h
include/log4cplus/fileappender.h
include/log4cplus/fstreams.h
include/log4cplus/helpers/appenderattachableimpl.h
include/log4cplus/helpers/loglog.h
include/log4cplus/helpers/logloguser.h
include/log4cplus/helpers/pointer.h
include/log4cplus/helpers/property.h
include/log4cplus/helpers/sleep.h
include/log4cplus/helpers/socket.h
include/log4cplus/helpers/socketbuffer.h
include/log4cplus/helpers/stringhelper.h
include/log4cplus/helpers/syncprims.h
include/log4cplus/helpers/thread-config.h
include/log4cplus/helpers/threads.h
include/log4cplus/helpers/timehelper.h
include/log4cplus/hierarchy.h
include/log4cplus/hierarchylocker.h
include/log4cplus/layout.h
include/log4cplus/logger.h
include/log4cplus/loggingmacros.h
include/log4cplus/loglevel.h
include/log4cplus/ndc.h
include/log4cplus/nteventlogappender.h
include/log4cplus/nullappender.h
include/log4cplus/socketappender.h
include/log4cplus/spi/appenderattachable.h
include/log4cplus/spi/factory.h
include/log4cplus/spi/filter.h
include/log4cplus/spi/loggerfactory.h
include/log4cplus/spi/loggerimpl.h
include/log4cplus/spi/loggingevent.h
include/log4cplus/spi/objectregistry.h
include/log4cplus/spi/rootlogger.h
include/log4cplus/streams.h
include/log4cplus/syslogappender.h
include/log4cplus/tstring.h
include/log4cplus/version.h
include/log4cplus/win32debugappender.h
include/log4cplus/win32consoleappender.h)
set (log4cplus_sources
src/appender.cxx
src/appenderattachableimpl.cxx
src/configurator.cxx
src/consoleappender.cxx
src/factory.cxx
src/fileappender.cxx
src/filter.cxx
src/global-init.cxx
src/hierarchy.cxx
src/hierarchylocker.cxx
src/layout.cxx
src/logger.cxx
src/loggerimpl.cxx
src/loggingevent.cxx
src/loglevel.cxx
src/loglog.cxx
src/logloguser.cxx
src/ndc.cxx
src/nullappender.cxx
src/objectregistry.cxx
src/patternlayout.cxx
src/pointer.cxx
src/property.cxx
src/rootlogger.cxx
src/sleep.cxx
src/socket.cxx
src/socketappender.cxx
src/socketbuffer.cxx
src/stringhelper.cxx
src/syncprims.cxx
src/syslogappender.cxx
src/threads.cxx
src/timehelper.cxx
src/version.cxx)
#message (STATUS "Type: ${UNIX}|${CYGWIN}|${WIN32}")
# Uncomment the following line to get locale aware string conversions.
#add_definitions (-DLOG4CPLUS_WORKING_LOCALE)
add_definitions(-DLOG4CPLUS_STATIC)
if ("${UNIX}" OR "${CYGWIN}")
set (log4cplus_sources ${log4cplus_sources}
src/socket-unix.cxx)
set (log4cplus_headers ${log4cplus_headers}
include/log4cplus/config/defines.hxx
include/log4cplus/helpers/syncprims-pthreads.h)
elseif (WIN32)
set (log4cplus_sources ${log4cplus_sources}
src/socket-win32.cxx
src/win32debugappender.cxx
src/nteventlogappender.cxx
src/win32consoleappender.cxx)
set (log4cplus_headers ${log4cplus_headers}
include/log4cplus/helpers/syncprims-win32.h)
# Comment out the following lines if you want non-Unicode version.
#add_definitions (-DUNICODE -D_UNICODE -UMBCS -U_MBCS)
set (log4cplus_postfix "${log4cplus_postfix}U")
#add_definitions (-DLOG4CPLUS_STATIC)
#set (log4cplus_postfix "${log4cplus_postfix}S")
endif ()
message (STATUS "Headers: ${log4cplus_headers}")
message (STATUS "Sources: ${log4cplus_sources}")
include_directories ("include")
set (log4cplus_all_sources ${log4cplus_sources} ${log4cplus_headers})
add_library (log4cplus STATIC ${log4cplus_all_sources})
#add_library (log4cplus SHARED ${log4cplus_all_sources})
target_link_libraries (log4cplus ${CMAKE_THREAD_LIBS_INIT})
set_target_properties (log4cplus PROPERTIES
VERSION "${log4cplus_version_major}.${log4cplus_version_minor}"
SOVERSION "${log4cplus_soversion}"
COMPILE_FLAGS "-DINSIDE_LOG4CPLUS")
if (WIN32)
set_target_properties (log4cplus PROPERTIES
DEBUG_POSTFIX "${log4cplus_postfix}D"
RELEASE_POSTFIX "${log4cplus_postfix}"
MINSIZEREL_POSTFIX "${log4cplus_postfix}"
RELWITHDEBINFO_POSTFIX "${log4cplus_postfix}")
target_link_libraries (log4cplus ws2_32 advapi32)
endif ()

1
libs/log4cplus/COPYING Normal file
View File

@ -0,0 +1 @@
See the LICENSE file.

428
libs/log4cplus/ChangeLog Normal file
View File

@ -0,0 +1,428 @@
Version 1.0.4
- Fixed bug #3101459 - TTCCLayout time is not in milliseconds since
process start by default.
- Fixed compilation of Non-Windows builds.
- Fixed various compilation and linking issues on SunOS.
Version 1.0.4-RC11
- Fixed bug #3083313, deadlock because of double locking when using
ConfigurationWatchDogThread.
- Improved portability to HP-UX and aCC compiler.
- Added %b PatternLayout format specifier; it expands to file
component of file path.
- Fixed bug #3058706, compilation error on AIX in socket-unix.cxx.
- Added %b pattern layout specifier. It expands to file name
component of path name.
- Fixed bug #3034758. Fixed infinite loop in
Hierarchy::updateParents() when logger hierarchy name starts with
a dot.
- Fixed bug #3034748. Fixed infinite loop in
PatternParser::extractOption() on missing '}'.
Version 1.0.4-RC10
- Fixed bug #3030133. Make Autoconf/Automake build system to respect
provided --includedir= value.
- Removed %X{N} PatternLayout format specifier for NDC with limited
depth. Replaced it with NDCMaxDepth property.
- Improved compatibility with Windows CE.
- Fixed memory leak when using POSIX threads.
- Fixed leak of mutex used to synchronize gethostbyname() calls.
- Fixed problem with how std::toupper(), std::tolower() and
std::isspace() are used in non-Unicode builds.
Version 1.0.4-RC9
- Fixed compilation problem in timehelper.cxx.
- Added %X{N} PatternLayout format specifier for NDC with limited
depth.
- Added facility property to SysLogAppender.
Version 1.0.4-RC8
- Always handle %s time format specifier (seconds since epoch) in
log4cplus. Detect and use clock_gettime() when available.
- Fixed compilation on OpenSolaris with Sun C++.
- Fixed compilation on OpenBSD.
- Fixed use of operator delete/delete[] in FileAppender (Patch
#3005234).
- Updated config.guess and config.sub to latest Git repository
versions.
- Added BufferSize property to FileAppender to allow control of the
appender's output buffer.
- Removed -fkeep-inline-functions from GCC flags for non-debugging
build.
Version 1.0.4-RC7
- Fixed thread safety issues with gethostbyname() by using
getaddrinfo() instead, where available.
- Fixed bug #2965390 - Minor internal debugging output issue.
- Added --enable-warnings (--disable-warnings) switches to the
configure script.
- Added ReopenDelay property to FileAppender, allowing the appender
to reopen output stream after write failure. (Patch #2971315)
Version 1.0.4-RC6
- Fixed bug #2945335 - MinGW/MSYS build problems. For Windows builds
the source now defaults to static library/empty LOG4CPLUS_EXPORT
macro.
- Fixed a security problem in SyslogAppender.
- Fixed bug #2955058 - Looping over properties during variables
expansion.
- Added missing dependency on log4cplus_dll project to filter_test
project.
- Added a constructor with Properties parameter to DenyAllFilter.
- Reworked Layout, Appender and Filter factories registration.
Version 1.0.4-RC5
- Implemented feature request #2927416 "Add a native Win32 Console
Appender".
- Loggingserver now exits with value 2 when it cannot open
listening socket.
- Improved Doxygen documentation.
- Added PropertyConfigurator::getProperties() and
PropertyConfigurator::getPropertyFilename() functions.
- Removed LOG4CPLUS_EXPORT on SharedObjectPtr<>.
- Turned on linker optimizations for MSVC8 builds to make resulting
binaries slightly smaller.
- Added --enable-runtime-pseudo-reloc linker option for Cygwin and
Mingw. Enable --enable-auto-import linker flag also for Mingw.
Version 1.0.4-RC4
- Fixed bug #2875993 - Implement connector thread for
SocketAppender.
- Improved documentation of Appenders' properties.
- Improved behaviour of DailyRollingFileAppender.
- Added x64 (AMD64) build configuration to MSVC8 project files.
- Reworked MSVC8 project files to use .vsprops files to share
project settings.
- Moved all tests into Tests project folder.
- Improved behaviour of ConfigurationWatchDogThread.
- Fixed bug #2890819 - Handle empty input in towstring_internal()
and tostring_internal().
- Corrected VERSION and SOVERSION in CMakeLists.txt.
- Fixed thread_test compilation on AIX.
- Added missing syncprims.cxx file in log4cplus_static.vcproj.
Version 1.0.4-RC3
IMPORTANT: Majority of log4cplus' source code is now licensed using
the Apache Software License 2.0. The rest is covered by two clause
BSD license.
- Fixed bug #2747435. Implement handling of log4cplus.configDebug
configuration property.
- Fixed variables shadowing.
- Doxygen documentation improvements and fixes.
- Add %i PatternLayout format. It expands to process ID.
- Fix logging macros compilation for LOG4CPLUS_SINGLE_THREADED case.
- Fix Logger log level configuration and root Logger handling log
level handling.
Version 1.0.4-RC2
- Fixed bug #2834811. Accessing index 0 of empty strings.
- Fixed bug #2834808. Memory leak in thread local storage code.
- Removed MSVC6 directory and project files.
- Update to libtool-2.2.6.
Version 1.0.4-RC1
- Fixed compilation with Borland C++ Builder compiler.
- Improved CMake build system to also build tests.
- Fixed compilation and improved support for Windows CE.
- Fixed compilation and improved support for Sun Studio 11 compiler.
- Fixed use after free and improved shutdown handling in
ConfigurationWatchDogThread.
- Implement %H (FQDN) and %h (host name) PatternLayout format
specifiers.
- Fixed bug #2829604. Environment variables substitution.
Version 1.0.3
- List of bugs fixed or otherwise dealt with:
<https://sourceforge.net/tracker/?func=browse&group_id=40830&atid=429073&artgroup=877523>
Version 1.0.3-RC9
- Tweaked Doxygen docs in comments for more recent Doxygen versions.
- Fix bug #2632087. Reworked WinSock initialization to fix deadlock
in WSAStartup() on Windows Vista.
- Fixed excessive errors reported in RollingFileAppender when
renaming non-existing files.
- Fall back to DAILY schedule in DailyRollingFileAppender for
invalid schedule specification.
- Added Debug_Unicode and Release_Unicode targets to MSVC8 test
cases builds.
Version 1.0.3-RC8
- Fixed SysLogAppender not being exported out of shared library
because of missing LOG4CPLUS_EXPORT.
- Fix bug #1168433. RollingFileAppender does a rename() to rename
logfile to logfile.1 etc. rename() on Windows will not overwrite
an existing file so only the first rename works. On Windows
(only), try to remove existing file first before calling rename().
- Fix bug #2573222. License issues. Most of log4cplus is covered by
ASL 1.1. The bits that are not covered by ASL 1.1 are covered by
two clause BSD licence. Texts of both licences are in LICENCE
file.
- Fix bug #2580037. Trim leading white space before comment
character '#' and both leading and trailing white space around
both key and value (e.g. " key = value ") in property files.
- Fix bug #2594345. Loggingserver and SocketAppender message format
mismatch.
- Fixed CMake builds.
Version 1.0.3-RC7
- Fix Bug #894464. Really only consider prefixes when searching for
matching properties.
- Fix compilation for combination of non-threaded and UNICODE
settings.
Version 1.0.3-RC6
- Fix Bug #852513 - Reconfiguring a logger does not remove old
appenders.
- Changed log4cplus thread helpers to block all signals on POSIX
platforms to enable their handling in a dedicated thread. (See
README, chapter Notes for explanation.)
- Changed thread creation from using CreateThread() to using
_beginthreadex() to avoid leaking C and C++ runtime memory.
- Fixed convertIntegerToString() to for negative numbers.
- Fixed wrong name used in BasicConfigurator for the
ConsoleAppender.
Version 1.0.3-RC5
- Add CMakeLists.txt to facilitate compilation of log4cplus on
Windows with different compilers than just the MSVC8.
- Fix compilation of Unicode enabled build without working locale.
(Patch #2429185)
Version 1.0.3-RC4
- IMPORTANT: log4cplus shared library version has been bumped to
3. The interfaces have slightly changed and 1.0.3 is not binary
compatible with 1.0.2.
- Fix more MSVC compilation problems.
- Changed log4cplus_static.vcproj to link with DLL C/C++ run time
(MSVCR80.dll and MSVCP80.dll).
- Implemented environment variables shadowing by properties and
recursive properties expansion.
- Reworked output directories layout of MSVC8 project. Now it
produces directories of the form
"log4cplus_{static,dll}.{Release,Debug}{_Unicode,}" and
"loggingserver.{Release,Debug}{_Unicode,}". The tests directory
projects still only compile using non-Unicode release and debug
version of the library.
- For single-threaded builds, re-use single tostringstream instead
of using a new one for each LOG4CPLUS_DEBUG() etc. macros.
- Merge Win32DebugAppender from trunk. (Patches #834925 and #858128)
- Make configuration of local server for NTEventLogAppender easier
by allowing empty server parameter string. (Feature Request
#875935)
Version 1.0.3-RC3
- Fix Bug #2268760 - Trailing garbage in strings produced by
Time::getFormattedTime().
- Fixed compilation of MSVC builds.
Version 1.0.3-RC2
- Fix Bug #2106949 - Compilation problem with Borland's compiler.
- Fix Bug #1717320, #1040902, #1040676 - strftime() complains about
our custom %q and %Q format specifiers with "Invalid format
directive".
- Removed safe_auto_ptr.
- Added --enable-debugging switch to configure script. It disables
optimization and turns on debugging info generation.
- Use locale and its codecvt facet in towstring()/tostring()
implementations when --with-working-locale is defined.
- Added support for GCC's -fvisibility=hidden flag where available
together with __attribute__ ((visibility("default"))).
Version 1.0.3-RC1
- IMPORTANT: VC6 users, VC6 is unsupported. Its standard C++ library
is too broken. The work around for VC6's std::string has been
removed from log4cplus code; it actually does not fix the problem,
it only makes it a little bit less likely to manifest. VC6 project
files are still distributed with the source but they are broken as
we have no means to update them. We strongly suggest that you
either move away from VC6 to some more modern and standard
conforming compiler (like VC8) or that you use the STLport
standard C++ library implementation instead of VC6's own.
- Fixed various compilation issues with MSVC8.
- Added MSVC8 project files.
- Fixed compilation with GCC 4.3.
- Fixed autoconf/automake build machinery so that it is possible to
build log4cplus in separate directory.
- Updated used autoconf and automake to version 2.62 and 1.10
respectively.
- Enabled DLL building on Cygwin.
- Fixed Bug #894623, #1178841 - Various compilation issues on
Cygwin.
- Fixed Bug #2017876 - Destruction synchronization issue.
- Fixed Bug #1831238 - Unintentional sign extension in char ->
wchar_t conversion.
- Fixed Bug #1548998 - config.h is exporting symbols that conflict
with other applications/libraries.
- Fixed Bug #898646 - Ambiguity between ::yield() and
thread::yeild() on Solaris.
- Fixed Bug #954455 - LOG4CPLUS_ macros semicolon problem.
Version 1.0.2 (February 10, 2004)
- Added "ImmediateFlush" configuration option to log4cplus::ConsoleAppender.
- Added do while loops around the logging statements in the macros.
- Fixed Bug #875960 - "log4cplus::ConfigureAndWatchThread crash"
- Fixed Bug #992034 - "rpm[build] -ta log4cplus-1.0.1.tar.gz doesn't work"
- Fixed Bug #875724 - "ConfigureAndWatchThread and mounted file systems"
- Fixed Bug #842280 - "'Append' mode when using FileAppended from cfg file."
All FileAppenders now have the "Append" configuration option. If this is
"true" any existing files will be opened with ios::append, otherwise they
will be opened with ios::trunc.
- Fixed Bug #805203 - "%q ConversionFormat does not accept modifiers"
Version 1.0.1 (December 18, 2003)
- Fixed Bug #831311 - "loggingserver.cxx clientsock.read()"
- Fixed Bug #851074 - "build problem HPUX 11, gcc 3.3"
- Fixed Bug #805242 - "Crash in log4cplus::helpers::SocketBuffer::appendSize_t"
- Fixed Bug #808119 - "TRACE_METHOD not displaying file name in log"
- Fixed Bug #827804 - "UMR in ConfigurationWatchdogThread"
- Fixed Bug #851116 - "Can not build"
- Added the OFF_LOG_LEVEL and the ALL_LOG_LEVEL LogLevels.
Version 1.0 (September 6 2003)
- Fix Bug #96934. (fileappender.cxx would not compile in a UNICODE build)
- Fixed compilation warning in MSVC for pointer.h
Version 0.9.10 (August 27 2003)
- Fixed singled-threaded build compilation issues
- The DailyRollingFileAppender no longer truncates files
- The DailyRollingFileAppender now performs a "rollover" on close(). If the
"rollover file" exists, then it will be renamed according to the pattern
that is used by the RollingFileAppender class. (Thanks Philip Green for
the suggestion.)
- Some socket-unix.cxx corrections.
- Fixed the *Factory initialization so that it compile with the HP aCC
compiler.
- Corrected the getCurrentThreadName() for MacOS X and DEC.
- "make install" now installs the header files.
Version 0.9.9 (August 9 2003)
- Fixed many MSVC++ compilation errors (6 and 7).
- Updated the MSVC++ projects
- Modified the Time::getFormattedTime() method to increase performance
- Modified Hierarcy::getInstanceImpl() to "deep copy" Logger names.
- Corrected some of the PatternLayout documentation to work better with
doxygen.
- Some Borland C++ Builder 6 fixes.
Version 0.9.8 (August 3 2003)
- Changed the LogLog class so that it is now reference counted.
- Restored the LOG4CPLUS_*_STR logging macros.
- Added support to disable the ERROR and FATAL macros by defining
LOG4CPLUS_DISABLE_*
- API Change: The LOG4CPLUS_TRACE macro now has behavior similar to all of
the other logging macros. If the old behavior is desired, then the new
LOG4CPLUS_TRACE_METHOD macro should be used.
- Modified Appender class to support the "Threshold" property.
- "localtime" is now the default time in log4cplus.
- The FileAppender no longer prints out the "header" when it opens a file.
- Added the "immediateFlush" field to the FileAppender class.
- Changed the API of the LogLevelManager class.
- Initial port work done to run on MacOS X.
- Added the HierarchyLocker class
- Added the ConfigureAndWatchThread class for runtime dynamic reconfiguration.
- Added several performance enhancements to the InternalLoggingEvent class.
- Renamed the PatternLayout "Pattern" configuration option to
"ConversionPattern".
- Added 3 new tests: configandwatch_test, customloglevel_test, and
performance_test. (No MSVC projects created for these tests, yet.)
Version 0.9.7 (June 28 2003)
- Added the log4cplus::DailyRollingFileAppender class.
- Added the log4cplus::helper::Time class. Now log with millisecond
granularity. (microsecond granularity if the gettimeofday() function is
available.)
- Changed log4cplus::spi::InternalLoggingEvent from a POD to a class and
introduced several performance ehancements to that class. This class
can now be extended to introduce "customized" logging.
- Fixed Bug #757989 - "TraceLogger should not hold a Logger reference"
- Added TYPE_SOCKLEN_T to configure.in (checking for whether <sys/socket.h>
defines `socklen_t').
- Added the "operator!=" to log4cplus::helpers::SharedObjectPtr.
- Made changes to make the DEC CXX 6.1 compiler happy.
- Renamed the tolower and toupper methods to avoid a name collision with a
macro with the DEC CXX compiler.
- Removed "-lstdc++" from the list of libraries in all Makefiles.
Version 0.9.6 (June 10 2003)
- Fixed multiple compiler warnings for the MSVC++ 7 compiler
- Modified configure.in so that it can now build on Solaris.
- Modified the configure script so that it can build a single-threaded
library (--enable-threads=no)
- Added "Filtering" to Appenders.
- Fixed Bug #741515 - "LogLog is causing a core on HP".
- Fixed Bug #733944 - "logging in system/local time"
- Fixed Bug #749040 - "Use of gmtime and localtime not thread-safe"
- Fixed Bug #750232 - "Copying of Hierarchy should not be allowed"
- Added an MSVC++ project to build log4cplus as a static library.
Version 0.9.5 (May 19 2003)
- Removed the LOG4CPLUS_*_STR logging macros.
- Added support to disable the TRACE, DEBUG, and INFO macros by defining
LOG4CPLUS_DISABLE_*
- Added a static doConfigure() method to PropertyConfigurator and
BasicConfigurator.
- Fixed problems with the configure script on several platforms.
- Optimized single-threaded mode.
- Fixed some problems with the MSVC++ 7 compiler.
Version 0.9.4 (May-5-2003)
Added SocketAppender class.
Now builds loggingserver to act as a source of logging messages from a
SocketAppender.
Numerous fixes needed for various compilers.
Version 0.9.3 (Apr-19-2003)
Added preliminary UNICODE support. (Little testing.) Thanks Michael CATANZARITI
Now built as a shared library instead of a static library.
Add support for Microsoft Visual C++ 6.0 back in. (Multi-threaded DLL)
Added SysLogAppender class.
Added NTEventLogAppender class. (Thanks Michael CATANZARITI)
Version 0.9.2 (Apr-5-2003)
Major API change: Changed the name of the Category class to Logger and
replaced the Priority class with LogLevel.
Added PropertyConfigurator class.
Added BasicConfigurator class.
Version 0.9.1 (Mar-22-2003)
Added PatternLayout class.
Version 0.9.0
Initial beta release.

365
libs/log4cplus/INSTALL Normal file
View File

@ -0,0 +1,365 @@
Installation Instructions
*************************
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
2006, 2007, 2008, 2009 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without warranty of any kind.
Basic Installation
==================
Briefly, the shell commands `./configure; make; make install' should
configure, build, and install this package. The following
more-detailed instructions are generic; see the `README' file for
instructions specific to this package. Some packages provide this
`INSTALL' file but do not implement all of the features documented
below. The lack of an optional feature in a given package is not
necessarily a bug. More recommendations for GNU packages can be found
in *note Makefile Conventions: (standards)Makefile Conventions.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure').
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. Caching is
disabled by default to prevent problems with accidental use of stale
cache files.
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If you are using the cache, and at
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You need `configure.ac' if
you want to change it or regenerate `configure' using a newer version
of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system.
Running `configure' might take a while. While running, it prints
some messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package, generally using the just-built uninstalled binaries.
4. Type `make install' to install the programs and any data files and
documentation. When installing into a prefix owned by root, it is
recommended that the package be configured and built as a regular
user, and only the `make install' phase executed with root
privileges.
5. Optionally, type `make installcheck' to repeat any self-tests, but
this time using the binaries in their final installed location.
This target does not install anything. Running this target as a
regular user, particularly if the prior `make install' required
root privileges, verifies that the installation completed
correctly.
6. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
7. Often, you can also type `make uninstall' to remove the installed
files again. In practice, not all packages have tested that
uninstallation works correctly, even though it is required by the
GNU Coding Standards.
8. Some packages, particularly those that use Automake, provide `make
distcheck', which can by used by developers to test that all other
targets like `make install' and `make uninstall' work correctly.
This target is generally not run by end users.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. Run `./configure --help'
for details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
is an example:
./configure CC=c99 CFLAGS=-g LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you can use GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'. This
is known as a "VPATH" build.
With a non-GNU `make', it is safer to compile the package for one
architecture at a time in the source code directory. After you have
installed the package for one architecture, use `make distclean' before
reconfiguring for another architecture.
On MacOS X 10.5 and later systems, you can create libraries and
executables that work on multiple system types--known as "fat" or
"universal" binaries--by specifying multiple `-arch' options to the
compiler but only a single `-arch' option to the preprocessor. Like
this:
./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
CPP="gcc -E" CXXCPP="g++ -E"
This is not guaranteed to produce working output in all cases, you
may have to build one architecture at a time and combine the results
using the `lipo' tool if you have problems.
Installation Names
==================
By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX', where PREFIX must be an
absolute file name.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
PREFIX as the prefix for installing programs and libraries.
Documentation and other data files still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=DIR' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them. In general, the
default for these options is expressed in terms of `${prefix}', so that
specifying just `--prefix' will affect all of the other directory
specifications that were not explicitly provided.
The most portable way to affect installation locations is to pass the
correct locations to `configure'; however, many packages provide one or
both of the following shortcuts of passing variable assignments to the
`make install' command line to change installation locations without
having to reconfigure or recompile.
The first method involves providing an override variable for each
affected directory. For example, `make install
prefix=/alternate/directory' will choose an alternate location for all
directory configuration variables that were expressed in terms of
`${prefix}'. Any directories that were specified during `configure',
but not in terms of `${prefix}', must each be overridden at install
time for the entire installation to be relocated. The approach of
makefile variable overrides for each directory variable is required by
the GNU Coding Standards, and ideally causes no recompilation.
However, some platforms have known limitations with the semantics of
shared libraries that end up requiring recompilation when using this
method, particularly noticeable in packages that use GNU Libtool.
The second method involves providing the `DESTDIR' variable. For
example, `make install DESTDIR=/alternate/directory' will prepend
`/alternate/directory' before all installation names. The approach of
`DESTDIR' overrides is not required by the GNU Coding Standards, and
does not work on platforms that have drive letters. On the other hand,
it does better at avoiding recompilation issues, and works well even
when some directory options were not specified in terms of `${prefix}'
at `configure' time.
Optional Features
=================
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Some packages offer the ability to configure how verbose the
execution of `make' will be. For these packages, running `./configure
--enable-silent-rules' sets the default to minimal output, which can be
overridden with `make V=1'; while running `./configure
--disable-silent-rules' sets the default to verbose, which can be
overridden with `make V=0'.
Particular systems
==================
On HP-UX, the default C compiler is not ANSI C compatible. If GNU
CC is not installed, it is recommended to use the following options in
order to use an ANSI C compiler:
./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
and if that doesn't work, install pre-built binaries of GCC for HP-UX.
On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
parse its `<wchar.h>' header file. The option `-nodtk' can be used as
a workaround. If GNU CC is not installed, it is therefore recommended
to try
./configure CC="cc"
and if that doesn't work, try
./configure CC="cc -nodtk"
On Solaris, don't put `/usr/ucb' early in your `PATH'. This
directory contains several dysfunctional programs; working variants of
these programs are available in `/usr/bin'. So, if you need `/usr/ucb'
in your `PATH', put it _after_ `/usr/bin'.
On Haiku, software installed for all users goes in `/boot/common',
not `/usr/local'. It is recommended to use the following options:
./configure --prefix=/boot/common
Specifying the System Type
==========================
There may be some features `configure' cannot figure out
automatically, but needs to determine by the type of machine the package
will run on. Usually, assuming the package is built to be run on the
_same_ architectures, `configure' can figure that out, but if it prints
a message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS
KERNEL-OS
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the option `--target=TYPE' to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
platform different from the build platform, you should specify the
"host" platform (i.e., that on which the generated programs will
eventually be run) with `--host=TYPE'.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script).
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
an Autoconf bug. Until the bug is fixed you can use this workaround:
CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
`configure' Invocation
======================
`configure' recognizes the following options to control how it
operates.
`--help'
`-h'
Print a summary of all of the options to `configure', and exit.
`--help=short'
`--help=recursive'
Print a summary of the options unique to this package's
`configure', and exit. The `short' variant lists options used
only in the top level, while the `recursive' variant lists options
also present in any nested packages.
`--version'
`-V'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`--cache-file=FILE'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`--prefix=DIR'
Use DIR as the installation prefix. *note Installation Names::
for more details, including other options available for fine-tuning
the installation locations.
`--no-create'
`-n'
Run the configure checks, but stop before creating any output
files.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.

452
libs/log4cplus/LICENSE Normal file
View File

@ -0,0 +1,452 @@
Contents
========
1. Log4j license
2. Log4cplus license
1. Log4j license
================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 1999-2005 The Apache Software Foundation
Licensed 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.
2. Log4cplus license
====================
Each file of log4cplus source is licensed using either two clause BSD license
or Apache license 2.0.
2.1 Two clause BSD license
==========================
Copyright (C) 1999-2009 Contributors to log4cplus project.
All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2.2 Apache 2.0 license
======================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 1999-2009 Contributors to log4cplus project
Licensed 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.

1
libs/log4cplus/NEWS Normal file
View File

@ -0,0 +1 @@
See http://log4cplus.sourceforge.net/ for the latest news.

105
libs/log4cplus/README Normal file
View File

@ -0,0 +1,105 @@
Short Description
=================
log4cplus is a simple to use C++ logging API providing thread-safe,
flexible, and arbitrarily granular control over log management and
configuration. It is modeled after the Java log4j API.
Latest Project Information
==========================
The latest up-to-date information for this project can be found at
http://log4cplus.sourceforge.net. Please submit bugs, patches,
feature requests, etc. there.
Current Status
==============
This library has now reached "Production" status.
Tested on the following platforms
=================================
- Linux/AMD64 with GCC 4.1.2 and 4.3.2
- FreeBSD/i386 and AMD64 with GCC 3.4.6, 4.2.1 and 4.3.3
- Windows XP with MS Visual C++ 8.0, 9.0 and 10.0
- OpenSolaris 5.11 with Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21,
with -library=stlport4
Notes
=====
Cygwin/MinGW
------------
Some version of GCC (3.4.x and probably some of 4.x series too) on
Windows (both Mingw and Cygwin) produces lots of warnings of the form
"warning: inline function 'void foo()' is declared as dllimport:
attribute ignored." This can be worked around by adding
-Wno-attributes option to GCC command. Unfortunatelly, not all
affected version of GCC have this option.
Threads and signals
-------------------
log4cplus is not safe to be used from async signals' handlers. This
is a property of most threaded programmes in general. If you are
going to use log4cplus in threaded application and if you want to use
log4cplus from signal handlers then your only option is to block
signals in all threads but one that will handle all signals. On POSIX
platforms, this is possible using the sigwait() call. log4cplus
enables this approach by blocking all signals in any threads created
through its threads helpers.
AIX
---
There appears to be a reentracy problem with AIX 5.3 and xlC 8 which
can result into a deadlock condition in some curcumstances. It is
unknown whether the problem manifests with other versions of either
the OS or the compiler, too. The problem was initially reported in a
bug report #3056687 ([1]).
The core of the problem is that IBM's/xlC's standard C++ IOStreams
implementation uses global non recursive lock to protect some of its
state. The application in the bug report was trying to do logging
using log4cplus from inside overflow() member function of a class
derived from std::streambuf class. log4cplus itself uses
std::ostringstream. This resulted into an attempt to recursivly lock
the global non recursive lock and a deadlock.
[1] <https://sourceforge.net/tracker/?func=detail&aid=3056687&group_id=40830&atid=429073>
Unsupported compilers
---------------------
log4cplus does not support too old and broken C++ compilers:
- Visual C++ prior to 7.1
- GCC prior to 3.2
- All Borland/CodeGear/Embarcadero C++ compilers
Unsupported platforms
---------------------
log4cplus requires some minimal set of C and/or C++ library
functions. Some systems/platforms fail to provide these functions and
thus log4cplus cannot be supported there:
- Windows CE - missing implementations of <time.h> functions
License
=======
This library is licensed under the Apache Public License 2.0 and two
clause BSD license. Please read the included LICENSE file for
details.

View File

@ -0,0 +1,212 @@
// Module: Log4CPLUS
// File: appender.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2010 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_APPENDER_HEADER_
#define _LOG4CPLUS_APPENDER_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/layout.h>
#include <log4cplus/loglevel.h>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/logloguser.h>
#include <log4cplus/helpers/pointer.h>
#include <log4cplus/helpers/property.h>
#include <log4cplus/spi/filter.h>
#include <memory>
namespace log4cplus {
/**
* This class is used to "handle" errors encountered in an {@link
* log4cplus::Appender}.
*/
class LOG4CPLUS_EXPORT ErrorHandler {
public:
virtual ~ErrorHandler();
virtual void error(const log4cplus::tstring& err) = 0;
virtual void reset() = 0;
};
class LOG4CPLUS_EXPORT OnlyOnceErrorHandler : public ErrorHandler,
protected log4cplus::helpers::LogLogUser
{
public:
// Ctor
OnlyOnceErrorHandler() : firstTime(true){}
virtual void error(const log4cplus::tstring& err);
virtual void reset();
private:
bool firstTime;
};
/**
* Extend this class for implementing your own strategies for printing log
* statements.
*/
class LOG4CPLUS_EXPORT Appender
: public virtual log4cplus::helpers::SharedObject
, protected log4cplus::helpers::LogLogUser
{
public:
// Ctor
Appender();
Appender(const log4cplus::helpers::Properties properties);
// Dtor
virtual ~Appender();
void destructorImpl();
// Methods
/**
* Release any resources allocated within the appender such as file
* handles, network connections, etc.
*
* It is a programming error to append to a closed appender.
*/
virtual void close() = 0;
/**
* This method performs threshold checks and invokes filters before
* delegating actual logging to the subclasses specific {@link
* #append} method.
*/
void doAppend(const log4cplus::spi::InternalLoggingEvent& event);
/**
* Get the name of this appender. The name uniquely identifies the
* appender.
*/
virtual log4cplus::tstring getName();
/**
* Set the name of this appender. The name is used by other
* components to identify this appender.
*/
virtual void setName(const log4cplus::tstring& name);
/**
* Set the {@link ErrorHandler} for this Appender.
*/
virtual void setErrorHandler(std::auto_ptr<ErrorHandler> eh);
/**
* Return the currently set {@link ErrorHandler} for this
* Appender.
*/
virtual ErrorHandler* getErrorHandler();
/**
* Set the layout for this appender. Note that some appenders have
* their own (fixed) layouts or do not use one. For example, the
* SocketAppender ignores the layout set here.
*/
virtual void setLayout(std::auto_ptr<Layout> layout);
/**
* Returns the layout of this appender. The value may be NULL.
*
* This class owns the returned pointer.
*/
virtual Layout* getLayout();
/**
* Set the filter chain on this Appender.
*/
void setFilter(log4cplus::spi::FilterPtr f) { filter = f; }
/**
* Get the filter chain on this Appender.
*/
log4cplus::spi::FilterPtr getFilter() const { return filter; }
/**
* Returns this appenders threshold LogLevel. See the {@link
* #setThreshold} method for the meaning of this option.
*/
LogLevel getThreshold() const { return threshold; }
/**
* Set the threshold LogLevel. All log events with lower LogLevel
* than the threshold LogLevel are ignored by the appender.
*
* In configuration files this option is specified by setting the
* value of the <b>Threshold</b> option to a LogLevel
* string, such as "DEBUG", "INFO" and so on.
*/
void setThreshold(LogLevel th) { threshold = th; }
/**
* Check whether the message LogLevel is below the appender's
* threshold. If there is no threshold set, then the return value is
* always <code>true</code>.
*/
bool isAsSevereAsThreshold(LogLevel ll) const {
return ((ll != NOT_SET_LOG_LEVEL) && (ll >= threshold));
}
protected:
// Methods
/**
* Subclasses of <code>Appender</code> should implement this
* method to perform actual logging.
* @see doAppend method.
*/
virtual void append(const log4cplus::spi::InternalLoggingEvent& event) = 0;
// Data
/** The layout variable does not need to be set if the appender
* implementation has its own layout. */
std::auto_ptr<Layout> layout;
/** Appenders are named. */
log4cplus::tstring name;
/** There is no LogLevel threshold filtering by default. */
LogLevel threshold;
/** The first filter in the filter chain. Set to <code>null</code>
* initially. */
log4cplus::spi::FilterPtr filter;
/** It is assumed and enforced that errorHandler is never null. */
std::auto_ptr<ErrorHandler> errorHandler;
/** Is this appender closed? */
bool closed;
};
/** This is a pointer to an Appender. */
typedef helpers::SharedObjectPtr<Appender> SharedAppenderPtr;
} // end namespace log4cplus
#endif // _LOG4CPLUS_APPENDER_HEADER_

View File

@ -0,0 +1,230 @@
/* include/log4cplus/config.h.in. Generated from configure.in by autoheader. */
#ifndef LOG4CPLUS_CONFIG_H
#define LOG4CPLUS_CONFIG_H
/* Define to 1 if you have the `clock_gettime' function. */
#undef HAVE_CLOCK_GETTIME
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the `ftime' function. */
#undef HAVE_FTIME
/* */
#undef HAVE_GETADDRINFO
/* */
#undef HAVE_GETHOSTBYNAME_R
/* Define to 1 if you have the `getpid' function. */
#undef HAVE_GETPID
/* Define to 1 if you have the `gettimeofday' function. */
#undef HAVE_GETTIMEOFDAY
/* Define to 1 if you have the `gmtime_r' function. */
#undef HAVE_GMTIME_R
/* Define to 1 if you have the `htonl' function. */
#undef HAVE_HTONL
/* Define to 1 if you have the `htons' function. */
#undef HAVE_HTONS
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `advapi32' library (-ladvapi32). */
#undef HAVE_LIBADVAPI32
/* Define to 1 if you have the `kernel32' library (-lkernel32). */
#undef HAVE_LIBKERNEL32
/* Define to 1 if you have the `ws2_32' library (-lws2_32). */
#undef HAVE_LIBWS2_32
/* Define to 1 if you have the `localtime_r' function. */
#undef HAVE_LOCALTIME_R
/* Define to 1 if you have the `lstat' function. */
#undef HAVE_LSTAT
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `ntohl' function. */
#undef HAVE_NTOHL
/* Define to 1 if you have the `ntohs' function. */
#undef HAVE_NTOHS
/* Define if you have POSIX threads libraries and header files. */
#undef HAVE_PTHREAD
/* Define to 1 if you have the `stat' function. */
#undef HAVE_STAT
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Defined for --enable-debugging builds. */
#undef LOG4CPLUS_DEBUGGING
/* Defined if the compiler understands __declspec(dllimport) or
__attribute__((visibility("default"))) construct. */
#undef LOG4CPLUS_DECLSPEC_EXPORT
/* Defined if the compiler understands __declspec(dllexport) or construct. */
#undef LOG4CPLUS_DECLSPEC_IMPORT
/* */
#undef LOG4CPLUS_HAVE_CLOCK_GETTIME
/* */
#undef LOG4CPLUS_HAVE_ENAMETOOLONG
/* */
#undef LOG4CPLUS_HAVE_ERRNO_H
/* */
#undef LOG4CPLUS_HAVE_FTIME
/* */
#undef LOG4CPLUS_HAVE_GETADDRINFO
/* */
#undef LOG4CPLUS_HAVE_GETHOSTBYNAME_R
/* */
#undef LOG4CPLUS_HAVE_GETPID
/* */
#undef LOG4CPLUS_HAVE_GETTIMEOFDAY
/* */
#undef LOG4CPLUS_HAVE_GMTIME_R
/* */
#undef LOG4CPLUS_HAVE_HTONL
/* */
#undef LOG4CPLUS_HAVE_HTONS
/* */
#undef LOG4CPLUS_HAVE_LOCALTIME_R
/* */
#undef LOG4CPLUS_HAVE_LSTAT
/* */
#undef LOG4CPLUS_HAVE_NETDB_H
/* */
#undef LOG4CPLUS_HAVE_NETINET_IN_H
/* */
#undef LOG4CPLUS_HAVE_NTOHL
/* */
#undef LOG4CPLUS_HAVE_NTOHS
/* */
#undef LOG4CPLUS_HAVE_STAT
/* */
#undef LOG4CPLUS_HAVE_STDARG_H
/* */
#undef LOG4CPLUS_HAVE_STDIO_H
/* */
#undef LOG4CPLUS_HAVE_SYSLOG_H
/* */
#undef LOG4CPLUS_HAVE_SYS_SOCKET_H
/* */
#undef LOG4CPLUS_HAVE_SYS_STAT_H
/* */
#undef LOG4CPLUS_HAVE_SYS_TIMEB_H
/* */
#undef LOG4CPLUS_HAVE_SYS_TIME_H
/* */
#undef LOG4CPLUS_HAVE_SYS_TYPES_H
/* */
#undef LOG4CPLUS_HAVE_TIME_H
/* */
#undef LOG4CPLUS_HAVE_UNISTD_H
/* */
#undef LOG4CPLUS_HAVE_WCHAR_H
/* Define if this is a single-threaded library. */
#undef LOG4CPLUS_SINGLE_THREADED
/* */
#undef LOG4CPLUS_USE_PTHREADS
/* Define for compilers/standard libraries that support more than just the "C"
locale. */
#undef LOG4CPLUS_WORKING_LOCALE
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#undef LT_OBJDIR
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define to necessary symbol if this constant uses a non-standard name on
your system. */
#undef PTHREAD_CREATE_JOINABLE
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define to int if undefined. */
#undef socklen_t
#endif // LOG4CPLUS_CONFIG_H

View File

@ -0,0 +1,50 @@
// Copyright (C) 2009, Vaclav Haisman. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modifica-
// tion, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef LOG4CPLUS_CONFIG_HXX
#define LOG4CPLUS_CONFIG_HXX
#if defined (_WIN32)
# include <log4cplus/config/win32.h>
#elif (defined(__MWERKS__) && defined(__MACOS__))
# include <log4cplus/config/macosx.h>
#else
# include <log4cplus/config/defines.hxx>
#endif
#if !defined(_WIN32)
# if !defined(LOG4CPLUS_SINGLE_THREADED)
# define LOG4CPLUS_USE_PTHREADS
# endif
# if defined (INSIDE_LOG4CPLUS)
# define LOG4CPLUS_EXPORT LOG4CPLUS_DECLSPEC_EXPORT
# else
# define LOG4CPLUS_EXPORT LOG4CPLUS_DECLSPEC_IMPORT
# endif // defined (INSIDE_LOG4CPLUS)
#endif // !_WIN32
#include <log4cplus/helpers/thread-config.h>
#endif // LOG4CPLUS_CONFIG_HXX

View File

@ -0,0 +1,113 @@
#ifndef LOG4CPLUS_CONFIG_DEFINES_HXX
#define LOG4CPLUS_CONFIG_DEFINES_HXX
/* */
#undef LOG4CPLUS_HAVE_SYSLOG_H
/* */
#undef LOG4CPLUS_HAVE_NETINET_IN_H
/* */
#undef LOG4CPLUS_HAVE_SYS_TYPES_H
/* */
#undef LOG4CPLUS_HAVE_SYS_SOCKET_H
/* */
#undef LOG4CPLUS_HAVE_SYS_STAT_H
/* */
#undef LOG4CPLUS_HAVE_SYS_TIMEB_H
/* */
#undef LOG4CPLUS_HAVE_SYS_TIME_H
/* */
#undef LOG4CPLUS_HAVE_TIME_H
/* */
#undef LOG4CPLUS_HAVE_NETDB_H
/* */
#undef LOG4CPLUS_HAVE_UNISTD_H
/* */
#undef LOG4CPLUS_HAVE_ERRNO_H
/* */
#undef LOG4CPLUS_HAVE_STDARG_H
/* */
#undef LOG4CPLUS_HAVE_STDIO_H
/* */
#undef LOG4CPLUS_HAVE_WCHAR_H
/* */
#undef LOG4CPLUS_HAVE_FTIME
/* */
#undef LOG4CPLUS_HAVE_GETADDRINFO
/* */
#undef LOG4CPLUS_HAVE_GETHOSTBYNAME_R
/* */
#undef LOG4CPLUS_HAVE_GETPID
/* */
#undef LOG4CPLUS_HAVE_GETTIMEOFDAY
/* */
#undef LOG4CPLUS_HAVE_GMTIME_R
/* */
#undef LOG4CPLUS_HAVE_HTONL
/* */
#undef LOG4CPLUS_HAVE_HTONS
/* */
#undef LOG4CPLUS_HAVE_LOCALTIME_R
/* */
#undef LOG4CPLUS_HAVE_LSTAT
/* */
#undef LOG4CPLUS_HAVE_NTOHL
/* */
#undef LOG4CPLUS_HAVE_NTOHS
/* */
#undef LOG4CPLUS_HAVE_STAT
/* Define if this is a single-threaded library. */
#undef LOG4CPLUS_SINGLE_THREADED
/* */
#undef LOG4CPLUS_USE_PTHREADS
/* Define for compilers/standard libraries that support more than just the "C"
locale. */
#undef LOG4CPLUS_WORKING_LOCALE
/* Define to int if undefined. */
#undef socklen_t
/* Defined for --enable-debugging builds. */
#undef LOG4CPLUS_DEBUGGING
/* Defined if the compiler understands __declspec(export) or __attribute__((export)) construct. */
#undef LOG4CPLUS_DECLSPEC_EXPORT
/* Defined if the compiler understands __declspec(import) or __attribute__((import)) construct. */
#undef LOG4CPLUS_DECLSPEC_IMPORT
/* Defined if the host OS provides ENAMETOOLONG errno value. */
#undef LOG4CPLUS_HAVE_ENAMETOOLONG
/* Define to 1 if you have the `clock_gettime' function. */
#undef LOG4CPLUS_HAVE_CLOCK_GETTIME
#endif // LOG4CPLUS_CONFIG_DEFINES_HXX

View File

@ -0,0 +1,25 @@
// Module: Log4CPLUS
// File: config-macosx.h
// Created: 7/2003
// Author: Christopher R. Bailey
//
//
// Copyright (C) Tad E. Smith All rights reserved.
//
// This software is published under the terms of the Apache Software
// License version 1.1, a copy of which has been included with this
// distribution in the LICENSE.APL file.
//
/** @file */
#ifndef LOG4CPLUS_CONFIG_MACOSX_HEADER_
#define LOG4CPLUS_CONFIG_MACOSX_HEADER_
#if (defined(__APPLE__) || (defined(__MWERKS__) && defined(__MACOS__)))
#define LOG4CPLUS_HAVE_GETTIMEOFDAY 1
#define socklen_t int
#endif // MACOSX
#endif // LOG4CPLUS_CONFIG_MACOSX_HEADER_

View File

@ -0,0 +1,96 @@
// Module: Log4CPLUS
// File: config-win32.h
// Created: 4/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2010 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef LOG4CPLUS_CONFIG_WIN32_HEADER_
#define LOG4CPLUS_CONFIG_WIN32_HEADER_
#ifdef _WIN32
#include <windows.h>
#if ! defined (_WIN32_WCE)
/* Define if you have the ftime function. */
#define LOG4CPLUS_HAVE_FTIME 1
#define LOG4CPLUS_HAVE_ERRNO_H
#define LOG4CPLUS_HAVE_SYS_STAT_H
#endif
#define LOG4CPLUS_HAVE_TIME_H
#define LOG4CPLUS_HAVE_STDLIB_H
#if defined (_WIN32_WCE)
# define LOG4CPLUS_DLLMAIN_HINSTANCE HANDLE
# undef LOG4CPLUS_HAVE_NT_EVENT_LOG
#else
# define LOG4CPLUS_DLLMAIN_HINSTANCE HINSTANCE
# define LOG4CPLUS_HAVE_NT_EVENT_LOG
# define LOG4CPLUS_HAVE_WIN32_CONSOLE
#endif
// Enable Win32DebugAppender
#define LOG4CPLUS_HAVE_OUTPUTDEBUGSTRING
// log4cplus_EXPORTS is used by the CMake build system. DLL_EXPORT is
// used by the autotools build system.
#if (defined (log4cplus_EXPORTS) || defined (DLL_EXPORT)) \
&& ! defined (LOG4CPLUS_STATIC)
# undef LOG4CPLUS_BUILD_DLL
# define LOG4CPLUS_BUILD_DLL
#endif
#if ! defined (LOG4CPLUS_BUILD_DLL)
# undef LOG4CPLUS_STATIC
# define LOG4CPLUS_STATIC
#endif
#if defined (LOG4CPLUS_STATIC) && defined (LOG4CPLUS_BUILD_DLL)
# error LOG4CPLUS_STATIC and LOG4CPLUS_BUILD_DLL cannot be defined both.
#endif
#if defined (LOG4CPLUS_BUILD_DLL)
# if defined (INSIDE_LOG4CPLUS)
# define LOG4CPLUS_EXPORT __declspec(dllexport)
# else
# define LOG4CPLUS_EXPORT __declspec(dllimport)
# endif
#else
# define LOG4CPLUS_EXPORT
#endif
#ifndef LOG4CPLUS_SINGLE_THREADED
# define LOG4CPLUS_USE_WIN32_THREADS
#endif
#if defined(_MSC_VER)
// Warning about: identifier was truncated to '255' characters in the debug information
# pragma warning( disable : 4786 )
// Warning about: <type1> needs to have dll-interface to be used by clients of class <type2>
# pragma warning( disable : 4251 )
# if _MSC_VER >= 1400 && ! defined (_WIN32_WCE)
# define LOG4CPLUS_WORKING_LOCALE
# endif
#endif
#endif // _WIN32
#endif // LOG4CPLUS_CONFIG_WIN32_HEADER_

View File

@ -0,0 +1,340 @@
// Module: Log4CPLUS
// File: configurator.h
// Created: 3/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2010 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _CONFIGURATOR_HEADER_
#define _CONFIGURATOR_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/appender.h>
#include <log4cplus/hierarchy.h>
#include <log4cplus/logger.h>
#include <log4cplus/helpers/logloguser.h>
#include <log4cplus/helpers/pointer.h>
#include <log4cplus/helpers/property.h>
#include <map>
namespace log4cplus
{
/**
* Provides configuration from an external file. See configure() for
* the expected format.
*
* <em>All option values admit variable substitution.</em> For
* example, if <code>userhome</code> environment property is set to
* <code>/home/xyz</code> and the File option is set to the string
* <code>${userhome}/test.log</code>, then File option will be
* interpreted as the string <code>/home/xyz/test.log</code>.
*
* The syntax of variable substitution is similar to that of UNIX
* shells. The string between an opening <b>&quot;${&quot;</b> and
* closing <b>&quot;}&quot;</b> is interpreted as a key. Its value is
* searched in the environment properties. The corresponding value replaces
* the ${variableName} sequence.
*/
class LOG4CPLUS_EXPORT PropertyConfigurator
: protected log4cplus::helpers::LogLogUser
{
public:
enum PCFlags
{
fRecursiveExpansion = 0x0001,
fShadowEnvironment = 0x0002,
fAllowEmptyVars = 0x0004
};
// ctor and dtor
PropertyConfigurator(const log4cplus::tstring& propertyFile,
Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
PropertyConfigurator(const log4cplus::helpers::Properties& props,
Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
PropertyConfigurator(log4cplus::tistream& propertyStream,
Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
virtual ~PropertyConfigurator();
/**
* This method eliminates the need to create a temporary
* <code>PropertyConfigurator</code> to configure log4cplus.
* It is equivalent to the following:<br>
* <code>
* PropertyConfigurator config("filename");
* config.configure();
* </code>
*/
static void doConfigure(const log4cplus::tstring& configFilename,
Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
/**
* Read configuration from a file. <b>The existing configuration is
* not cleared nor reset.</b> If you require a different behavior,
* then call {@link Hierarchy::resetConfiguration
* resetConfiguration} method before calling
* <code>doConfigure</code>.
*
* The configuration file consists of statements in the format
* <code>key=value</code>. The syntax of different configuration
* elements are discussed below.
*
* <h3>Appender configuration</h3>
*
* Appender configuration syntax is:
* <pre>
* # For appender named <i>appenderName</i>, set its class.
* # Note: The appender name can contain dots.
* log4cplus.appender.appenderName=fully.qualified.name.of.appender.class
*
* # Set appender specific options.
* log4cplus.appender.appenderName.option1=value1
* ...
* log4cplus.appender.appenderName.optionN=valueN
* </pre>
*
* For each named appender you can configure its {@link Layout}. The
* syntax for configuring an appender's layout is:
* <pre>
* log4cplus.appender.appenderName.layout=fully.qualified.name.of.layout.class
* log4cplus.appender.appenderName.layout.option1=value1
* ....
* log4cplus.appender.appenderName.layout.optionN=valueN
* </pre>
*
* <h3>Configuring loggers</h3>
*
* The syntax for configuring the root logger is:
* <pre>
* log4cplus.rootLogger=[LogLevel], appenderName, appenderName, ...
* </pre>
*
* This syntax means that an optional <em>LogLevel value</em> can
* be supplied followed by appender names separated by commas.
*
* The LogLevel value can consist of the string values FATAL,
* ERROR, WARN, INFO, DEBUG or a <em>custom LogLevel</em> value.
*
* If a LogLevel value is specified, then the root LogLevel is set
* to the corresponding LogLevel. If no LogLevel value is specified,
* then the root LogLevel remains untouched.
*
* The root logger can be assigned multiple appenders.
*
* Each <i>appenderName</i> (separated by commas) will be added to
* the root logger. The named appender is defined using the
* appender syntax defined above.
*
* For non-root loggers the syntax is almost the same:
* <pre>
* log4cplus.logger.logger_name=[LogLevel|INHERITED], appenderName, appenderName, ...
* </pre>
*
* The meaning of the optional LogLevel value is discussed above
* in relation to the root logger. In addition however, the value
* INHERITED can be specified meaning that the named logger should
* inherit its LogLevel from the logger hierarchy.
*
* By default loggers inherit their LogLevel from the
* hierarchy. However, if you set the LogLevel of a logger and
* later decide that that logger should inherit its LogLevel, then
* you should specify INHERITED as the value for the LogLevel value.
*
* Similar to the root logger syntax, each <i>appenderName</i>
* (separated by commas) will be attached to the named logger.
*
* See the <a href="../../../../manual.html#additivity">appender
* additivity rule</a> in the user manual for the meaning of the
* <code>additivity</code> flag.
*
* The user can override any of the {@link
* Hierarchy#disable} family of methods by setting the a key
* "log4cplus.disableOverride" to <code>true</code> or any value other
* than false. As in <pre>log4cplus.disableOverride=true </pre>
*
* <h3>Example</h3>
*
* An example configuration is given below.
*
* <pre>
*
* # Set options for appender named "A1".
* # Appender "A1" will be a SyslogAppender
* log4cplus.appender.A1=log4cplus::SyslogAppender
*
* # The syslog daemon resides on www.abc.net
* log4cplus.appender.A1.SyslogHost=www.abc.net
*
* # A1's layout is a PatternLayout, using the conversion pattern
* # <b>%r %-5p %c{2} %M.%L %x - %m\n</b>. Thus, the log output will
* # include # the relative time since the start of the application in
* # milliseconds, followed by the LogLevel of the log request,
* # followed by the two rightmost components of the logger name,
* # followed by the callers method name, followed by the line number,
* # the nested disgnostic context and finally the message itself.
* # Refer to the documentation of {@link PatternLayout} for further information
* # on the syntax of the ConversionPattern key.
* log4cplus.appender.A1.layout=log4cplus::PatternLayout
* log4cplus.appender.A1.layout.ConversionPattern=%-4r %-5p %c{2} %M.%L %x - %m\n
*
* # Set options for appender named "A2"
* # A2 should be a RollingFileAppender, with maximum file size of 10 MB
* # using at most one backup file. A2's layout is TTCC, using the
* # ISO8061 date format with context printing enabled.
* log4cplus.appender.A2=log4cplus::RollingFileAppender
* log4cplus.appender.A2.MaxFileSize=10MB
* log4cplus.appender.A2.MaxBackupIndex=1
* log4cplus.appender.A2.layout=log4cplus::TTCCLayout
* log4cplus.appender.A2.layout.ContextPrinting=enabled
* log4cplus.appender.A2.layout.DateFormat=ISO8601
*
* # Root logger set to DEBUG using the A2 appender defined above.
* log4cplus.rootLogger=DEBUG, A2
*
* # Logger definitions:
* # The SECURITY logger inherits is LogLevel from root. However, it's output
* # will go to A1 appender defined above. It's additivity is non-cumulative.
* log4cplus.logger.SECURITY=INHERIT, A1
* log4cplus.additivity.SECURITY=false
*
* # Only warnings or above will be logged for the logger "SECURITY.access".
* # Output will go to A1.
* log4cplus.logger.SECURITY.access=WARN
*
*
* # The logger "class.of.the.day" inherits its LogLevel from the
* # logger hierarchy. Output will go to the appender's of the root
* # logger, A2 in this case.
* log4cplus.logger.class.of.the.day=INHERIT
* </pre>
*
* Refer to the <b>setOption</b> method in each Appender and
* Layout for class specific options.
*
* Use the <code>#</code> character at the beginning of a line
* for comments.
*/
virtual void configure();
/**
* \return The return value is reference to Properties
* container of properties with the <code>"log4cplus."</code>
* prefix removed and references to other properties and/or
* environment variables expanded.
*/
log4cplus::helpers::Properties const & getProperties () const;
/**
* \return The return value is a reference to log4cplus::tstring
* containing filename of properties source file. It will be
* string "UNAVAILABLE" if the PropertyConfigurator instance has been
* constructed using one of the other constructors that do not take
* filename as parameter.
*/
log4cplus::tstring const & getPropertyFilename () const;
protected:
// Methods
void init(); // called by the ctor
void reconfigure();
void replaceEnvironVariables();
void configureLoggers();
void configureLogger(log4cplus::Logger logger, const log4cplus::tstring& config);
void configureAppenders();
void configureAdditivity();
virtual Logger getLogger(const log4cplus::tstring& name);
virtual void addAppender(Logger &logger, log4cplus::SharedAppenderPtr& appender);
// Types
typedef std::map<log4cplus::tstring, log4cplus::SharedAppenderPtr> AppenderMap;
// Data
Hierarchy& h;
log4cplus::tstring propertyFilename;
log4cplus::helpers::Properties properties;
AppenderMap appenders;
unsigned flags;
private:
// Disable copy
PropertyConfigurator(const PropertyConfigurator&);
PropertyConfigurator& operator=(PropertyConfigurator&);
};
/**
* Use this class to quickly configure the package. For file based
* configuration see PropertyConfigurator. BasicConfigurator
* automatically attaches ConsoleAppender to
* <code>rootLogger</code>, with output going to standard output,
* using DEBUG LogLevel value.
*/
class LOG4CPLUS_EXPORT BasicConfigurator : public PropertyConfigurator {
public:
// ctor and dtor
BasicConfigurator(Hierarchy& h = Logger::getDefaultHierarchy());
virtual ~BasicConfigurator();
/**
* This method eliminates the need to create a temporary
* <code>BasicConfigurator</code> object to configure log4cplus.
* It is equivalent to the following:<br>
* <code><pre>
* BasicConfigurator config;
* config.configure();
* </pre></code>
*/
static void doConfigure(Hierarchy& h = Logger::getDefaultHierarchy());
private:
// Disable copy
BasicConfigurator(const BasicConfigurator&);
BasicConfigurator& operator=(BasicConfigurator&);
};
#if !defined(LOG4CPLUS_SINGLE_THREADED)
// Forward Declarations
class ConfigurationWatchDogThread;
class LOG4CPLUS_EXPORT ConfigureAndWatchThread {
public:
// ctor and dtor
ConfigureAndWatchThread(const log4cplus::tstring& propertyFile,
unsigned int millis = 60 * 1000);
virtual ~ConfigureAndWatchThread();
private:
// Disallow copying of instances of this class
ConfigureAndWatchThread(const ConfigureAndWatchThread&);
ConfigureAndWatchThread& operator=(const ConfigureAndWatchThread&);
// Data
ConfigurationWatchDogThread * watchDogThread;
};
#endif
} // end namespace log4cplus
#endif // _CONFIGURATOR_HEADER_

View File

@ -0,0 +1,74 @@
// Module: Log4CPLUS
// File: consoleappender.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_CONSOLE_APPENDER_HEADER_
#define _LOG4CPLUS_CONSOLE_APPENDER_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/appender.h>
namespace log4cplus {
/**
* ConsoleAppender appends log events to <code>std::cout</code> or
* <code>std::cerr</code> using a layout specified by the
* user. The default target is <code>std::cout</code>.
*
* <h3>Properties</h3>
* <dl>
* <dt><tt>logToStdErr</tt></dt>
* <dd>When it is set true, the output stream will be
* <code>std::cerr</code> instead of <code>std::cout</code>.</dd>
*
* <dt><tt>ImmediateFlush</tt></dt>
* <dd>When it is set true, output stream will be flushed after
* each appended event.</dd>
*
* </dl>
*/
class LOG4CPLUS_EXPORT ConsoleAppender : public Appender {
public:
// Ctors
ConsoleAppender(bool logToStdErr = false, bool immediateFlush = false);
ConsoleAppender(const log4cplus::helpers::Properties properties);
// Dtor
~ConsoleAppender();
// Methods
virtual void close();
protected:
virtual void append(const spi::InternalLoggingEvent& event);
// Data
bool logToStdErr;
/**
* Immediate flush means that the underlying output stream
* will be flushed at the end of each append operation.
*/
bool immediateFlush;
};
} // end namespace log4cplus
#endif // _LOG4CPLUS_CONSOLE_APPENDER_HEADER_

View File

@ -0,0 +1,237 @@
// Module: Log4CPLUS
// File: fileappender.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2010 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_FILE_APPENDER_HEADER_
#define _LOG4CPLUS_FILE_APPENDER_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/appender.h>
#include <log4cplus/fstreams.h>
#include <log4cplus/helpers/property.h>
#include <log4cplus/helpers/timehelper.h>
#if defined(__DECCXX)
# define LOG4CPLUS_OPEN_MODE_TYPE LOG4CPLUS_FSTREAM_NAMESPACE::ios::open_mode
#else
# define LOG4CPLUS_OPEN_MODE_TYPE LOG4CPLUS_FSTREAM_NAMESPACE::ios::openmode
#endif
namespace log4cplus {
/**
* Appends log events to a file.
*
* <h3>Properties</h3>
* <dl>
* <dt><tt>File</tt></dt>
* <dd>This property specifies output file name.</dd>
*
* <dt><tt>ImmediateFlush</tt></dt>
* <dd>When it is set true, output stream will be flushed after
* each appended event.</dd>
*
* <dt><tt>Append</tt></dt>
* <dd>When it is set true, output file will be appended to
* instead of being truncated at opening.</dd>
*
* <dt><tt>ReopenDelay</tt></dt>
* <dd>This property sets a delay after which the appender will
* try to reopen log file again, after last logging failure. The
* default value is 1 second. Setting the delay to 0 makes the
* appender not to try reopening the stream.
* </dd>
*
* <dt><tt>BufferSize</tt></dt>
* <dd>Non-zero value of this property sets up buffering of output
* stream using a buffer of given size.
* </dd>
* </dl>
*/
class LOG4CPLUS_EXPORT FileAppender : public Appender {
public:
// Ctors
FileAppender(const log4cplus::tstring& filename,
LOG4CPLUS_OPEN_MODE_TYPE mode = LOG4CPLUS_FSTREAM_NAMESPACE::ios::trunc,
bool immediateFlush = true);
FileAppender(const log4cplus::helpers::Properties& properties,
LOG4CPLUS_OPEN_MODE_TYPE mode = LOG4CPLUS_FSTREAM_NAMESPACE::ios::trunc);
// Dtor
virtual ~FileAppender();
// Methods
virtual void close();
protected:
virtual void append(const spi::InternalLoggingEvent& event);
void open(LOG4CPLUS_OPEN_MODE_TYPE mode);
bool reopen();
// Data
/**
* Immediate flush means that the underlying writer or output stream
* will be flushed at the end of each append operation. Immediate
* flush is slower but ensures that each append request is actually
* written. If <code>immediateFlush</code> is set to
* <code>false</code>, then there is a good chance that the last few
* logs events are not actually written to persistent media if and
* when the application crashes.
*
* The <code>immediateFlush</code> variable is set to
* <code>true</code> by default.
*/
bool immediateFlush;
/**
* When any append operation fails, <code>reopenDelay</code> says
* for how many seconds the next attempt to re-open the log file and
* resume logging will be delayed. If <code>reopenDelay</code> is zero,
* each failed append operation will cause log file to be re-opened.
* By default, <code>reopenDelay</code> is 1 second.
*/
int reopenDelay;
unsigned long bufferSize;
log4cplus::tchar * buffer;
log4cplus::tofstream out;
log4cplus::tstring filename;
log4cplus::helpers::Time reopen_time;
private:
void init(const log4cplus::tstring& filename,
LOG4CPLUS_OPEN_MODE_TYPE mode);
// Disallow copying of instances of this class
FileAppender(const FileAppender&);
FileAppender& operator=(const FileAppender&);
};
/**
* RollingFileAppender extends FileAppender to backup the log
* files when they reach a certain size.
*
* <h3>Properties</h3>
* <p>Properties additional to {@link FileAppender}'s properties:
*
* <dl>
* <dt><tt>MaxFileSize</tt></dt>
* <dd>This property specifies maximal size of output file. The
* value is in bytes. It is possible to use <tt>MB</tt> and
* <tt>KB</tt> suffixes to specify the value in megabytes or
* kilobytes instead.</dd>
*
* <dt><tt>MaxBackupIndex</tt></dt>
* <dd>This property limits the number of backup output
* files; e.g. how many <tt>log.1</tt>, <tt>log.2</tt> etc. files
* will be kept.</dd>
* </dl>
*/
class LOG4CPLUS_EXPORT RollingFileAppender : public FileAppender {
public:
// Ctors
RollingFileAppender(const log4cplus::tstring& filename,
long maxFileSize = 10*1024*1024, // 10 MB
int maxBackupIndex = 1,
bool immediateFlush = true);
RollingFileAppender(const log4cplus::helpers::Properties& properties);
// Dtor
virtual ~RollingFileAppender();
protected:
virtual void append(const spi::InternalLoggingEvent& event);
void rollover();
// Data
long maxFileSize;
int maxBackupIndex;
private:
void init(long maxFileSize, int maxBackupIndex);
};
enum DailyRollingFileSchedule { MONTHLY, WEEKLY, DAILY,
TWICE_DAILY, HOURLY, MINUTELY};
/**
* DailyRollingFileAppender extends {@link FileAppender} so that the
* underlying file is rolled over at a user chosen frequency.
*
* <h3>Properties</h3>
* <p>Properties additional to {@link FileAppender}'s properties:
*
* <dl>
* <dt><tt>Schedule</tt></dt>
* <dd>This property specifies rollover schedule. The possible
* values are <tt>MONTHLY</tt>, <tt>WEEKLY</tt>, <tt>DAILY</tt>,
* <tt>TWICE_DAILY</tt>, <tt>HOURLY</tt> and
* <tt>MINUTELY</tt>.</dd>
*
* <dt><tt>MaxBackupIndex</tt></dt>
* <dd>This property limits how many backup files are kept per
* single logging period; e.g. how many <tt>log.2009-11-07.1</tt>,
* <tt>log.2009-11-07.2</tt> etc. files are kept.</dd>
*
* </dl>
*/
class LOG4CPLUS_EXPORT DailyRollingFileAppender : public FileAppender {
public:
// Ctors
DailyRollingFileAppender(const log4cplus::tstring& filename,
DailyRollingFileSchedule schedule = DAILY,
bool immediateFlush = true,
int maxBackupIndex = 10);
DailyRollingFileAppender(const log4cplus::helpers::Properties& properties);
// Dtor
virtual ~DailyRollingFileAppender();
// Methods
virtual void close();
protected:
virtual void append(const spi::InternalLoggingEvent& event);
void rollover();
log4cplus::helpers::Time calculateNextRolloverTime(const log4cplus::helpers::Time& t) const;
log4cplus::tstring getFilename(const log4cplus::helpers::Time& t) const;
// Data
DailyRollingFileSchedule schedule;
log4cplus::tstring scheduledFilename;
log4cplus::helpers::Time nextRolloverTime;
int maxBackupIndex;
private:
void init(DailyRollingFileSchedule schedule);
};
} // end namespace log4cplus
#endif // _LOG4CPLUS_FILE_APPENDER_HEADER_

View File

@ -0,0 +1,50 @@
// Module: Log4CPLUS
// File: fstreams.h
// Created: 4/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef LOG4CPLUS_FSTREAMS_HEADER_
#define LOG4CPLUS_FSTREAMS_HEADER_
#include <log4cplus/config.hxx>
#include <fstream>
#if defined(__DECCXX) && !defined(__USE_STD_IOSTREAM)
# define LOG4CPLUS_FSTREAM_NAMESPACE
#else
# define LOG4CPLUS_FSTREAM_NAMESPACE std
#endif
#ifdef UNICODE
namespace log4cplus {
typedef LOG4CPLUS_FSTREAM_NAMESPACE::wofstream tofstream;
typedef LOG4CPLUS_FSTREAM_NAMESPACE::wifstream tifstream;
}
#else
namespace log4cplus {
typedef LOG4CPLUS_FSTREAM_NAMESPACE::ofstream tofstream;
typedef LOG4CPLUS_FSTREAM_NAMESPACE::ifstream tifstream;
}
#endif // UNICODE
#endif // LOG4CPLUS_FSTREAMS_HEADER_

View File

@ -0,0 +1,112 @@
// Module: Log4CPLUS
// File: appenderattachableimpl.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_HELPERS_APPENDER_ATTACHABLE_IMPL_HEADER_
#define _LOG4CPLUS_HELPERS_APPENDER_ATTACHABLE_IMPL_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/layout.h>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/logloguser.h>
#include <log4cplus/helpers/pointer.h>
#include <log4cplus/helpers/threads.h>
#include <log4cplus/spi/appenderattachable.h>
#include <memory>
#include <vector>
namespace log4cplus {
namespace helpers {
/**
* This Interface is for attaching Appenders to objects.
*/
class LOG4CPLUS_EXPORT AppenderAttachableImpl
: public log4cplus::spi::AppenderAttachable,
protected log4cplus::helpers::LogLogUser
{
public:
// Data
LOG4CPLUS_MUTEX_PTR_DECLARE appender_list_mutex;
// Ctors
AppenderAttachableImpl();
// Dtor
virtual ~AppenderAttachableImpl();
// Methods
/**
* Add an appender. If the appender is already in the list in
* won't be added again.
*/
virtual void addAppender(SharedAppenderPtr newAppender);
/**
* Get all previously added appenders as an vectory.
*/
virtual SharedAppenderPtrList getAllAppenders();
/**
* Look for an attached appender named as <code>name</code>.
*
* Return the appender with that name if in the list. Return null
* otherwise.
*/
virtual SharedAppenderPtr getAppender(const log4cplus::tstring& name);
/**
* Remove all previously added appenders.
*/
virtual void removeAllAppenders();
/**
* Remove the appender passed as parameter from the list of appenders.
*/
virtual void removeAppender(SharedAppenderPtr appender);
/**
* Remove the appender with the name passed as parameter from the
* list of appenders.
*/
virtual void removeAppender(const log4cplus::tstring& name);
/**
* Call the <code>doAppend</code> method on all attached appenders.
*/
int appendLoopOnAppenders(const spi::InternalLoggingEvent& event) const;
protected:
// Types
typedef std::vector<SharedAppenderPtr> ListType;
// Data
/** Array of appenders. */
ListType appenderList;
}; // end class AppenderAttachableImpl
} // end namespace helpers
} // end namespace log4cplus
#endif // _LOG4CPLUS_HELPERS_APPENDER_ATTACHABLE_IMPL_HEADER_

View File

@ -0,0 +1,113 @@
// Module: Log4CPLUS
// File: loglog.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_HELPERS_LOGLOG
#define _LOG4CPLUS_HELPERS_LOGLOG
#include <log4cplus/config.hxx>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/pointer.h>
#include <log4cplus/helpers/threads.h>
namespace log4cplus {
namespace helpers {
/**
* This class used to output log statements from within the log4cplus package.
*
* Log4cplus components cannot make log4cplus logging calls. However, it is
* sometimes useful for the user to learn about what log4cplus is
* doing. You can enable log4cplus internal logging by defining the
* <b>log4cplus.configDebug</b> variable.
*
* All log4cplus internal debug calls go to <code>cout</code>
* where as internal error messages are sent to
* <code>cerr</code>. All internal messages are prepended with
* the string "log4clus: ".
*/
class LOG4CPLUS_EXPORT LogLog
: public virtual log4cplus::helpers::SharedObject
{
public:
// Static methods
/**
* Returns a reference to the <code>LogLog</code> singleton.
*/
static log4cplus::helpers::SharedObjectPtr<LogLog> getLogLog();
/**
* Allows to enable/disable log4cplus internal logging.
*/
void setInternalDebugging(bool enabled);
/**
* In quite mode no LogLog generates strictly no output, not even
* for errors.
*
* @param quietMode A true for not
*/
void setQuietMode(bool quietMode);
/**
* This method is used to output log4cplus internal debug
* statements. Output goes to <code>std::cout</code>.
*/
void debug(const log4cplus::tstring& msg);
/**
* This method is used to output log4cplus internal error
* statements. There is no way to disable error statements.
* Output goes to <code>std::cerr</code>.
*/
void error(const log4cplus::tstring& msg);
/**
* This method is used to output log4cplus internal warning
* statements. There is no way to disable warning statements.
* Output goes to <code>std::cerr</code>.
*/
void warn(const log4cplus::tstring& msg);
// Dtor
virtual ~LogLog();
// Data
LOG4CPLUS_MUTEX_PTR_DECLARE mutex;
private:
// Data
bool debugEnabled;
bool quietMode;
// Ctors
LogLog();
LogLog(const LogLog&);
};
} // end namespace helpers
} // end namespace log4cplus
#endif // _LOG4CPLUS_HELPERS_LOGLOG

View File

@ -0,0 +1,62 @@
// Module: Log4CPLUS
// File: logloguser.h
// Created: 6/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_HELPERS_LOGLOG_USER
#define _LOG4CPLUS_HELPERS_LOGLOG_USER
#include <log4cplus/config.hxx>
namespace log4cplus {
namespace helpers {
// forward declarations
class LogLog;
/**
* This class used to simplify the use of the LogLog class. Any class
* that uses the LogLog class should extend this class and retrieve
* their reference to LogLog using the method provided.
*/
class LOG4CPLUS_EXPORT LogLogUser {
public:
// ctor and dtor
LogLogUser();
LogLogUser(const LogLogUser&);
virtual ~LogLogUser();
// public methods
LogLog& getLogLog() const;
// operators
LogLogUser& operator=(const LogLogUser& rhs);
private:
// Data
void* loglogRef;
};
} // end namespace helpers
} // end namespace log4cplus
#endif // _LOG4CPLUS_HELPERS_LOGLOG_USER

View File

@ -0,0 +1,160 @@
// Module: Log4CPLUS
// File: pointer.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2009 Tad E. Smith
//
// Licensed 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.
//
// Note: Some of this code uses ideas from "More Effective C++" by Scott
// Myers, Addison Wesley Longmain, Inc., (c) 1996, Chapter 29, pp. 183-213
//
/** @file */
#ifndef _LOG4CPLUS_HELPERS_POINTERS_HEADER_
#define _LOG4CPLUS_HELPERS_POINTERS_HEADER_
#include <log4cplus/config.hxx>
#include <memory>
#include <stdexcept>
#include <string>
#include <algorithm>
#include <cassert>
namespace log4cplus {
namespace helpers {
/******************************************************************************
* Class SharedObject (from pp. 204-205) *
******************************************************************************/
class LOG4CPLUS_EXPORT SharedObject
{
public:
void addReference() const;
void removeReference() const;
protected:
// Ctor
SharedObject()
: access_mutex(LOG4CPLUS_MUTEX_CREATE)
, count(0)
{ }
SharedObject(const SharedObject&)
: access_mutex(LOG4CPLUS_MUTEX_CREATE)
, count(0)
{ }
// Dtor
virtual ~SharedObject();
// Operators
SharedObject& operator=(const SharedObject&) { return *this; }
public:
LOG4CPLUS_MUTEX_PTR_DECLARE access_mutex;
private:
mutable int count;
};
/******************************************************************************
* Template Class SharedObjectPtr (from pp. 203, 206) *
******************************************************************************/
template<class T>
class SharedObjectPtr
{
public:
// Ctor
explicit
SharedObjectPtr(T* realPtr = 0)
: pointee(realPtr)
{
addref ();
}
SharedObjectPtr(const SharedObjectPtr& rhs)
: pointee(rhs.pointee)
{
addref ();
}
// Dtor
~SharedObjectPtr()
{
if (pointee)
pointee->removeReference();
}
// Operators
bool operator==(const SharedObjectPtr& rhs) const { return (pointee == rhs.pointee); }
bool operator!=(const SharedObjectPtr& rhs) const { return (pointee != rhs.pointee); }
bool operator==(const T* rhs) const { return (pointee == rhs); }
bool operator!=(const T* rhs) const { return (pointee != rhs); }
T* operator->() const {assert (pointee); return pointee; }
T& operator*() const {assert (pointee); return *pointee; }
SharedObjectPtr& operator=(const SharedObjectPtr& rhs)
{
return this->operator = (rhs.pointee);
}
SharedObjectPtr& operator=(T* rhs)
{
SharedObjectPtr<T> (rhs).swap (*this);
return *this;
}
// Methods
T* get() const { return pointee; }
void swap (SharedObjectPtr & other) throw ()
{
std::swap (pointee, other.pointee);
}
typedef T * (SharedObjectPtr:: * unspec_bool_type) () const;
operator unspec_bool_type () const
{
return pointee ? &SharedObjectPtr::get : 0;
}
bool operator ! () const
{
return ! pointee;
}
private:
// Methods
void addref() const
{
if (pointee)
pointee->addReference();
}
// Data
T* pointee;
};
} // end namespace helpers
} // end namespace log4cplus
#endif // _LOG4CPLUS_HELPERS_POINTERS_HEADER_

View File

@ -0,0 +1,123 @@
// Module: Log4CPLUS
// File: property.h
// Created: 2/2002
// Author: Tad E. Smith
//
//
// Copyright 2002-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef LOG4CPLUS_HELPERS_PROPERTY_HEADER_
#define LOG4CPLUS_HELPERS_PROPERTY_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/streams.h>
#include <log4cplus/tstring.h>
#include <map>
#include <vector>
#if (defined(__MWERKS__) && defined(__MACOS__))
using std::size_t;
#endif
namespace log4cplus {
namespace helpers {
class LOG4CPLUS_EXPORT Properties {
public:
Properties();
explicit Properties(log4cplus::tistream& input);
explicit Properties(const log4cplus::tstring& inputFile);
virtual ~Properties();
// constants
static const tchar PROPERTIES_COMMENT_CHAR;
// methods
/**
* Tests to see if <code>key</code> can be found in this map.
*/
bool exists(const log4cplus::tstring& key) const {
return data.find(key) != data.end();
}
/**
* Returns the number of entries in this map.
*/
size_t size() const {
return data.size();
}
/**
* Searches for the property with the specified key in this property
* list. If the key is not found in this property list, the default
* property list, and its defaults, recursively, are then checked.
* The method returns <code>null</code> if the property is not found.
*/
log4cplus::tstring getProperty(const log4cplus::tstring& key) const;
/**
* Searches for the property with the specified key in this property
* list. If the key is not found in this property list, the default
* property list, and its defaults, recursively, are then checked.
* The method returns the default value argument if the property is
* not found.
*/
log4cplus::tstring getProperty(const log4cplus::tstring& key,
const log4cplus::tstring& defaultVal) const;
/**
* Returns all the keys in this property list.
*/
std::vector<log4cplus::tstring> propertyNames() const;
/**
* Inserts <code>value</code> into this map indexed by <code>key</code>.
*/
void setProperty(const log4cplus::tstring& key, const log4cplus::tstring& value);
/**
* Removed the property index by <code>key</code> from this map.
*/
bool removeProperty(const log4cplus::tstring& key);
/**
* Returns a subset of the "properties" whose keys start with
* "prefix". The returned "properties" have "prefix" trimmed from
* their keys.
*/
Properties getPropertySubset(const log4cplus::tstring& prefix) const;
protected:
// Types
// LOG4CPLUS_EXPIMP_TEMPLATE template class LOG4CPLUS_EXPORT std::map<log4cplus::tstring, log4cplus::tstring>;
typedef std::map<log4cplus::tstring, log4cplus::tstring> StringMap;
// Methods
void init(log4cplus::tistream& input);
// Data
StringMap data;
};
} // end namespace helpers
}
#endif // LOG4CPLUS_HELPERS_PROPERTY_HEADER_

View File

@ -0,0 +1,38 @@
// Module: Log4CPLUS
// File: sleep.h
// Created: 5/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_HELPERS_SLEEP_HEADER_
#define _LOG4CPLUS_HELPERS_SLEEP_HEADER_
#include <log4cplus/config.hxx>
namespace log4cplus {
namespace helpers {
LOG4CPLUS_EXPORT void sleep(unsigned long secs,
unsigned long nanosecs = 0);
LOG4CPLUS_EXPORT void sleepmillis(unsigned long millis);
} // end namespace helpers
} // end namespace log4cplus
#endif // _LOG4CPLUS_HELPERS_SLEEP_HEADER_

View File

@ -0,0 +1,128 @@
// Module: Log4CPLUS
// File: socket.h
// Created: 4/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef LOG4CPLUS_HELPERS_SOCKET_HEADER_
#define LOG4CPLUS_HELPERS_SOCKET_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/socketbuffer.h>
#if defined(_WIN32)
#include <winsock.h>
#endif
namespace log4cplus {
namespace helpers {
enum SocketState { ok,
not_opened,
bad_address,
connection_failed,
broken_pipe,
invalid_access_mode,
message_truncated
};
#if !defined(_WIN32)
typedef int SOCKET_TYPE;
#define INVALID_SOCKET -1
#else
typedef SOCKET SOCKET_TYPE;
#endif
class LOG4CPLUS_EXPORT AbstractSocket {
public:
// ctor and dtor
AbstractSocket();
AbstractSocket(SOCKET_TYPE sock, SocketState state, int err);
AbstractSocket(const AbstractSocket&);
virtual ~AbstractSocket() = 0;
// methods
/// Close socket
virtual void close();
virtual bool isOpen() const;
AbstractSocket& operator=(const AbstractSocket& rhs);
protected:
// Methods
virtual void copy(const AbstractSocket& rhs);
// Data
SOCKET_TYPE sock;
SocketState state;
int err;
};
/**
* This class implements client sockets (also called just "sockets").
* A socket is an endpoint for communication between two machines.
*/
class LOG4CPLUS_EXPORT Socket : public AbstractSocket {
public:
// ctor and dtor
Socket();
Socket(SOCKET_TYPE sock, SocketState state, int err);
Socket(const tstring& address, int port);
virtual ~Socket();
// methods
virtual bool read(SocketBuffer& buffer);
virtual bool write(const SocketBuffer& buffer);
};
/**
* This class implements server sockets. A server socket waits for
* requests to come in over the network. It performs some operation
* based on that request, and then possibly returns a result to the
* requester.
*/
class LOG4CPLUS_EXPORT ServerSocket : public AbstractSocket {
public:
// ctor and dtor
ServerSocket(int port);
virtual ~ServerSocket();
Socket accept();
};
LOG4CPLUS_EXPORT SOCKET_TYPE openSocket(unsigned short port, SocketState& state);
LOG4CPLUS_EXPORT SOCKET_TYPE connectSocket(const log4cplus::tstring& hostn,
unsigned short port, SocketState& state);
LOG4CPLUS_EXPORT SOCKET_TYPE acceptSocket(SOCKET_TYPE sock, SocketState& state);
LOG4CPLUS_EXPORT int closeSocket(SOCKET_TYPE sock);
LOG4CPLUS_EXPORT long read(SOCKET_TYPE sock, SocketBuffer& buffer);
LOG4CPLUS_EXPORT long write(SOCKET_TYPE sock, const SocketBuffer& buffer);
LOG4CPLUS_EXPORT tstring getHostname (bool fqdn);
} // end namespace helpers
} // end namespace log4cplus
#endif // LOG4CPLUS_HELPERS_SOCKET_HEADER_

View File

@ -0,0 +1,79 @@
// Module: Log4CPLUS
// File: socketbuffer.h
// Created: 5/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef LOG4CPLUS_HELPERS_SOCKET_BUFFER_HEADER_
#define LOG4CPLUS_HELPERS_SOCKET_BUFFER_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/logloguser.h>
namespace log4cplus {
namespace helpers {
/**
*
*/
class LOG4CPLUS_EXPORT SocketBuffer : protected log4cplus::helpers::LogLogUser
{
public:
SocketBuffer(size_t max);
SocketBuffer(const SocketBuffer& rhs);
~SocketBuffer();
SocketBuffer& operator=(const SocketBuffer& rhs);
char *getBuffer() const { return buffer; }
size_t getMaxSize() const { return maxsize; }
size_t getSize() const { return size; }
void setSize(size_t s) { size = s; }
size_t getPos() const { return pos; }
unsigned char readByte();
unsigned short readShort();
unsigned int readInt();
tstring readString(unsigned char sizeOfChar);
void appendByte(unsigned char val);
void appendShort(unsigned short val);
void appendInt(unsigned int val);
void appendSize_t(size_t val);
void appendString(const tstring& str);
void appendBuffer(const SocketBuffer& buffer);
private:
// Methods
void copy(const SocketBuffer& rhs);
// Data
size_t maxsize;
size_t size;
size_t pos;
char *buffer;
};
} // end namespace helpers
} // end namespace log4cplus
#endif // LOG4CPLUS_HELPERS_SOCKET_HEADER_

View File

@ -0,0 +1,239 @@
// Module: Log4CPLUS
// File: stringhelper.h
// Created: 3/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2010 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef LOG4CPLUS_HELPERS_STRINGHELPER_HEADER_
#define LOG4CPLUS_HELPERS_STRINGHELPER_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/tstring.h>
#include <algorithm>
#include <limits>
#include <iterator>
namespace log4cplus {
namespace helpers {
/**
* Returns <code>s</code> in upper case.
*/
LOG4CPLUS_EXPORT log4cplus::tstring toUpper(const log4cplus::tstring& s);
/**
* Returns <code>s</code> in lower case.
*/
LOG4CPLUS_EXPORT log4cplus::tstring toLower(const log4cplus::tstring& s);
/**
* Tokenize <code>s</code> using <code>c</code> as the delimiter and
* put the resulting tokens in <code>_result</code>. If
* <code>collapseTokens</code> is false, multiple adjacent delimiters
* will result in zero length tokens.
*
* <b>Example:</b>
* <pre>
* string s = // Set string with '.' as delimiters
* list<log4cplus::tstring> tokens;
* tokenize(s, '.', back_insert_iterator<list<string> >(tokens));
* </pre>
*/
template <class StringType, class OutputIter>
inline
void
tokenize(const StringType& s, typename StringType::value_type c,
OutputIter result, bool collapseTokens = true)
{
typedef typename StringType::size_type size_type;
size_type const slen = s.length();
size_type first = 0;
size_type i = 0;
for (i=0; i < slen; ++i)
{
if (s[i] == c)
{
*result = StringType (s, first, i - first);
++result;
if (collapseTokens)
while (i+1 < slen && s[i+1] == c)
++i;
first = i + 1;
}
}
if (first != i)
*result = StringType (s, first, i - first);
}
template <typename intType, bool isSigned>
struct ConvertIntegerToStringHelper;
template <typename intType>
struct ConvertIntegerToStringHelper<intType, true>
{
static inline
void
step1 (tchar * & it, intType & value)
{
// The sign of the result of the modulo operator is
// implementation defined. That's why we work with
// positive counterpart instead. Also, in twos
// complement arithmetic the smallest negative number
// does not have positive counterpart; the range is
// asymetric. That's why we handle the case of value
// == min() specially here.
if (value == (std::numeric_limits<intType>::min) ())
{
intType const r = value / 10;
intType const a = (-r) * 10;
intType const mod = -(a + value);
value = -r;
*(it - 1) = LOG4CPLUS_TEXT('0') + static_cast<tchar>(mod);
--it;
}
else
value = -value;
}
};
template <typename intType>
struct ConvertIntegerToStringHelper<intType, false>
{
static inline
void
step1 (tchar * &, intType &)
{
// This will never be called for unsigned types.
}
};
template<class intType>
inline
void
convertIntegerToString (tstring & str, intType value)
{
typedef std::numeric_limits<intType> intTypeLimits;
typedef ConvertIntegerToStringHelper<intType,
intTypeLimits::is_signed> HelperType;
const size_t buffer_size
= intTypeLimits::digits10 + 2;
tchar buffer[buffer_size];
tchar * it = &buffer[buffer_size];
tchar const * const buf_end = it;
if (value == 0)
{
--it;
*it = LOG4CPLUS_TEXT('0');
}
bool const negative = value < 0;
if (negative)
HelperType::step1 (it, value);
for (; value != 0; --it)
{
intType mod = value % 10;
value = value / 10;
*(it - 1) = LOG4CPLUS_TEXT('0') + static_cast<tchar>(mod);
}
if (negative)
{
--it;
*it = LOG4CPLUS_TEXT('-');
}
str.assign (static_cast<tchar const *>(it), buf_end);
}
template<class intType>
inline
tstring
convertIntegerToString (intType value)
{
tstring result;
convertIntegerToString (result, value);
return result;
}
/**
* This iterator can be used in place of the back_insert_iterator
* for compilers that don't have a std::basic_string class that
* has the <code>push_back</code> method.
*/
template <class Container>
class string_append_iterator
: public std::iterator<std::output_iterator_tag, void, void, void,
void>
{
public:
typedef Container container_type;
explicit string_append_iterator(container_type & c)
: container(&c)
{ }
string_append_iterator<container_type> &
operator = (const typename container_type::value_type& value)
{
*container += value;
return *this;
}
string_append_iterator<container_type> &
operator * ()
{
return *this;
}
string_append_iterator<container_type> &
operator ++ ()
{
return *this;
}
string_append_iterator<container_type>
operator ++ (int)
{
return *this;
}
protected:
container_type * container;
};
} // namespace helpers
} // namespace log4cplus
#endif // LOG4CPLUS_HELPERS_STRINGHELPER_HEADER_

View File

@ -0,0 +1,307 @@
// Copyright (C) 2009-2010, Vaclav Haisman. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modifica-
// tion, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//! @file
//! This file contains implementations of synchronization
//! primitives using the POSIX threads. It does not contain any
//! include guards because it is only a fragment to be included by
//! syncprims.h.
#include <limits>
#include <algorithm>
namespace log4cplus { namespace thread {
#define LOG4CPLUS_THROW_RTE(msg) \
do { detail::syncprims_throw_exception (msg, __FILE__, __LINE__); } while (0)
//
//
//
struct PthreadMutexAttr
{
PthreadMutexAttr ()
{
int ret = pthread_mutexattr_init (&attr);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("PthreadMutexAttr::PthreadMutexAttr");
}
~PthreadMutexAttr ()
try
{
int ret = pthread_mutexattr_destroy (&attr);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("PthreadMutexAttr::~PthreadMutexAttr");
}
catch (...)
{ }
void
set_type (Mutex::Type t)
{
int mutex_type;
switch (t)
{
case Mutex::RECURSIVE:
mutex_type = PTHREAD_MUTEX_RECURSIVE;
break;
default:
mutex_type = PTHREAD_MUTEX_DEFAULT;
}
int ret = pthread_mutexattr_settype (&attr, mutex_type);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("PthreadMutexAttr::set_type");
}
pthread_mutexattr_t attr;
};
//
//
//
inline
Mutex::Mutex (Mutex::Type t)
{
PthreadMutexAttr attr;
attr.set_type (t);
int ret = pthread_mutex_init (&mtx, &attr.attr);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("Mutex::Mutex");
}
inline
Mutex::~Mutex ()
{
int ret = pthread_mutex_destroy (&mtx);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("Mutex::~Mutex");
}
inline
void
Mutex::lock () const
{
int ret = pthread_mutex_lock (&mtx);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("Mutex::lock");
}
inline
void
Mutex::unlock () const
{
int ret = pthread_mutex_unlock (&mtx);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("Mutex::unlock");
}
//
//
//
inline
Semaphore::Semaphore (unsigned max, unsigned initial)
{
unsigned const sem_value_max =
#if defined (SEM_VALUE_MAX)
SEM_VALUE_MAX
#else
std::numeric_limits<int>::max ()
#endif
;
unsigned const limited_max = (std::min) (max, sem_value_max);
unsigned const limited_initial = (std::min) (initial, limited_max);
int ret = sem_init (&sem, 0, limited_initial);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("Semaphore::Semaphore");
}
inline
Semaphore::~Semaphore ()
try
{
int ret = sem_destroy (&sem);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("Semaphore::~Semaphore");
}
catch (...)
{ }
inline
void
Semaphore::unlock () const
{
int ret = sem_post (&sem);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("Semaphore::unlock");
}
inline
void
Semaphore::lock () const
{
int ret = sem_wait (&sem);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("Semaphore::lock");
}
//
//
//
inline
ManualResetEvent::ManualResetEvent (bool sig)
: mtx (Mutex::DEFAULT)
, sigcount (0)
, signaled (sig)
{
int ret = pthread_cond_init (&cv, 0);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("ManualResetEvent::ManualResetEvent");
}
inline
ManualResetEvent::~ManualResetEvent ()
try
{
int ret = pthread_cond_destroy (&cv);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("ManualResetEvent::~ManualResetEvent");
}
catch (...)
{ }
inline
void
ManualResetEvent::signal () const
{
MutexGuard mguard (mtx);
signaled = true;
sigcount += 1;
int ret = pthread_cond_broadcast (&cv);
if (ret != 0)
LOG4CPLUS_THROW_RTE ("ManualResetEVent::signal");
}
inline
void
ManualResetEvent::wait () const
{
MutexGuard mguard (mtx);
if (! signaled)
{
unsigned prev_count = sigcount;
do
{
int ret = pthread_cond_wait (&cv, &mtx.mtx);
if (ret != 0)
{
mguard.unlock ();
mguard.detach ();
LOG4CPLUS_THROW_RTE ("ManualResetEvent::wait");
}
}
while (prev_count == sigcount);
}
}
inline
bool
ManualResetEvent::timed_wait (unsigned long msec) const
{
MutexGuard mguard (mtx);
if (! signaled)
{
helpers::Time const wakeup_time (helpers::Time::gettimeofday ()
+ helpers::Time (msec / 1000, (msec % 1000) * 1000));
struct timespec const ts = {wakeup_time.sec (),
wakeup_time.usec () * 1000};
unsigned prev_count = sigcount;
do
{
int ret = pthread_cond_timedwait (&cv, &mtx.mtx, &ts);
switch (ret)
{
case 0:
break;
case ETIMEDOUT:
return false;
default:
mguard.unlock ();
mguard.detach ();
LOG4CPLUS_THROW_RTE ("ManualResetEvent::timed_wait");
}
}
while (prev_count == sigcount);
}
return true;
}
inline
void
ManualResetEvent::reset () const
{
MutexGuard mguard (mtx);
signaled = false;
}
#undef LOG4CPLUS_THROW_RTE
} } // namespace log4cplus { namespace thread {

View File

@ -0,0 +1,195 @@
// Copyright (C) 2009, Vaclav Haisman. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modifica-
// tion, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//! @file
//! This file contains implementations of synchronization
//! primitives using the Win32 API. It does not contain any include
//! guards because it is only a fragment to be included by
//! syncprims.h.
namespace log4cplus { namespace thread {
#define LOG4CPLUS_THROW_RTE(msg) \
do { detail::syncprims_throw_exception (msg, __FILE__, __LINE__); } while (0)
//
//
//
inline
Mutex::Mutex (Mutex::Type)
{
InitializeCriticalSection (&cs);
}
inline
Mutex::~Mutex ()
{
DeleteCriticalSection (&cs);
}
inline
void
Mutex::lock () const
{
EnterCriticalSection (&cs);
}
inline
void
Mutex::unlock () const
{
LeaveCriticalSection (&cs);
}
//
//
//
inline
Semaphore::Semaphore (unsigned max, unsigned initial)
{
sem = CreateSemaphore (0, initial, max, 0);
if (! sem)
LOG4CPLUS_THROW_RTE ("Semaphore::Semaphore");
}
inline
Semaphore::~Semaphore ()
{
try
{
if (! CloseHandle (sem))
LOG4CPLUS_THROW_RTE ("Semaphore::~Semaphore");
}
catch (...)
{ }
}
inline
void
Semaphore::unlock () const
{
DWORD ret = ReleaseSemaphore (sem, 1, 0);
if (! ret)
LOG4CPLUS_THROW_RTE ("Semaphore::unlock");
}
inline
void
Semaphore::lock () const
{
DWORD ret = WaitForSingleObject (sem, INFINITE);
if (ret != WAIT_OBJECT_0)
LOG4CPLUS_THROW_RTE ("Semaphore::lock");
}
//
//
//
inline
ManualResetEvent::ManualResetEvent (bool sig)
{
ev = CreateEvent (0, true, sig, 0);
if (! ev)
LOG4CPLUS_THROW_RTE ("ManualResetEvent::ManualResetEvent");
}
inline
ManualResetEvent::~ManualResetEvent ()
{
try
{
if (! CloseHandle (ev))
LOG4CPLUS_THROW_RTE ("ManualResetEvent::~ManualResetEvent");
}
catch (...)
{ }
}
inline
void
ManualResetEvent::signal () const
{
if (! SetEvent (ev))
LOG4CPLUS_THROW_RTE ("ManualResetEVent::signal");
}
inline
void
ManualResetEvent::wait () const
{
DWORD ret = WaitForSingleObject (ev, INFINITE);
if (ret != WAIT_OBJECT_0)
LOG4CPLUS_THROW_RTE ("ManualResetEvent::wait");
}
inline
bool
ManualResetEvent::timed_wait (unsigned long msec) const
{
DWORD ret = WaitForSingleObject (ev, static_cast<DWORD>(msec));
switch(ret)
{
case WAIT_OBJECT_0:
return true;
case WAIT_TIMEOUT:
return false;
default:
LOG4CPLUS_THROW_RTE ("ManualResetEvent::timed_wait");
// Silence warnings about not returning any value from function
// returning bool.
return false;
}
}
inline
void
ManualResetEvent::reset () const
{
if (! ResetEvent (ev))
LOG4CPLUS_THROW_RTE ("ManualResetEvent::reset");
}
#undef LOG4CPLUS_THROW_RTE
} } // namespace log4cplus { namespace thread {

View File

@ -0,0 +1,237 @@
// Copyright (C) 2009, Vaclav Haisman. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modifica-
// tion, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef LOG4CPLUS_THREAD_SYNCPRIMS_H
#define LOG4CPLUS_THREAD_SYNCPRIMS_H
#include <stdexcept>
#include <log4cplus/config.hxx>
#if defined (LOG4CPLUS_USE_PTHREADS)
# include <errno.h>
# include <pthread.h>
# include <semaphore.h>
# include <log4cplus/helpers/timehelper.h>
#elif defined (LOG4CPLUS_USE_WIN32_THREADS)
# undef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
namespace log4cplus { namespace thread {
namespace detail
{
LOG4CPLUS_EXPORT void syncprims_throw_exception (char const * const msg,
char const * const file, int line);
} // namespace detail
template <typename SP>
class SyncGuard
{
public:
SyncGuard (SP const &);
~SyncGuard ();
void lock ();
void unlock ();
void attach (SP const &);
void detach ();
private:
SP const * sp;
SyncGuard (SyncGuard const &);
SyncGuard & operator = (SyncGuard const &);
};
class ManualResetEvent;
class Mutex
{
public:
enum Type
{
DEFAULT,
RECURSIVE
};
explicit Mutex (Type = RECURSIVE);
~Mutex ();
void lock () const;
void unlock () const;
private:
#if defined (LOG4CPLUS_USE_PTHREADS)
mutable pthread_mutex_t mtx;
friend class ManualResetEvent;
#elif defined (LOG4CPLUS_USE_WIN32_THREADS)
mutable CRITICAL_SECTION cs;
#endif
Mutex (Mutex const &);
Mutex & operator = (Mutex &);
};
typedef SyncGuard<Mutex> MutexGuard;
class Semaphore
{
public:
Semaphore (unsigned max, unsigned initial);
~Semaphore ();
void lock () const;
void unlock () const;
private:
#if defined (LOG4CPLUS_USE_PTHREADS)
mutable sem_t sem;
#elif defined (LOG4CPLUS_USE_WIN32_THREADS)
HANDLE sem;
#endif
Semaphore (Semaphore const &);
Semaphore & operator = (Semaphore const &);
};
typedef SyncGuard<Semaphore> SemaphoreGuard;
class ManualResetEvent
{
public:
ManualResetEvent (bool = false);
~ManualResetEvent ();
void signal () const;
void wait () const;
bool timed_wait (unsigned long msec) const;
void reset () const;
private:
#if defined (LOG4CPLUS_USE_PTHREADS)
mutable pthread_cond_t cv;
mutable Mutex mtx;
mutable volatile unsigned sigcount;
mutable volatile bool signaled;
#elif defined (LOG4CPLUS_USE_WIN32_THREADS)
HANDLE ev;
#endif
ManualResetEvent (ManualResetEvent const &);
ManualResetEvent & operator = (ManualResetEvent const &);
};
} } // namespace log4cplus { namespace thread {
// Include the appropriate implementations of the classes declared
// above.
#if defined (LOG4CPLUS_USE_PTHREADS)
# include <log4cplus/helpers/syncprims-pthreads.h>
#elif defined (LOG4CPLUS_USE_WIN32_THREADS)
# include <log4cplus/helpers/syncprims-win32.h>
#endif
namespace log4cplus { namespace thread {
//
//
//
template <typename SP>
inline
SyncGuard<SP>::SyncGuard (SP const & m)
: sp (&m)
{
sp->lock ();
}
template <typename SP>
inline
SyncGuard<SP>::~SyncGuard ()
{
if (sp)
sp->unlock ();
}
template <typename SP>
inline
void
SyncGuard<SP>::lock ()
{
sp->lock ();
}
template <typename SP>
inline
void
SyncGuard<SP>::unlock ()
{
sp->unlock ();
}
template <typename SP>
inline
void
SyncGuard<SP>::attach (SP const & m)
{
sp = &m;
}
template <typename SP>
inline
void
SyncGuard<SP>::detach ()
{
sp = 0;
}
} } // namespace log4cplus { namespace thread {
#endif // LOG4CPLUS_THREAD_SYNCPRIMS_H

View File

@ -0,0 +1,143 @@
// Module: Log4CPLUS
// File: thread-config.h
// Created: 4/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef LOG4CPLUS_HELPERS_THREAD_CONFIG_HEADER_
#define LOG4CPLUS_HELPERS_THREAD_CONFIG_HEADER_
#ifdef LOG4CPLUS_USE_PTHREADS
# include <pthread.h>
# include <semaphore.h>
# define LOG4CPLUS_MUTEX_PTR_DECLARE pthread_mutex_t*
# define LOG4CPLUS_MUTEX_CREATE ::log4cplus::thread::createNewMutex()
# define LOG4CPLUS_MUTEX_LOCK(mutex) pthread_mutex_lock(mutex)
# define LOG4CPLUS_MUTEX_UNLOCK(mutex) pthread_mutex_unlock(mutex)
# define LOG4CPLUS_MUTEX_FREE(mutex) ::log4cplus::thread::deleteMutex(mutex)
# define LOG4CPLUS_THREAD_HANDLE_TYPE pthread_t
# define LOG4CPLUS_THREAD_KEY_TYPE pthread_t
# define LOG4CPLUS_GET_CURRENT_THREAD_NAME \
::log4cplus::thread::getCurrentThreadName()
# define LOG4CPLUS_GET_CURRENT_THREAD pthread_self()
# define LOG4CPLUS_THREAD_LOCAL_TYPE pthread_key_t*
# define LOG4CPLUS_THREAD_LOCAL_INIT(cleanup) \
::log4cplus::thread::createPthreadKey(cleanup)
# define LOG4CPLUS_GET_THREAD_LOCAL_VALUE(key) pthread_getspecific(*(key))
# define LOG4CPLUS_SET_THREAD_LOCAL_VALUE(key, value) \
pthread_setspecific(*(key), value)
# define LOG4CPLUS_THREAD_LOCAL_CLEANUP(key) \
do { pthread_key_t * pthkey (key); pthread_key_delete(*pthkey); \
delete pthkey; } while(0)
namespace log4cplus {
namespace thread {
LOG4CPLUS_EXPORT LOG4CPLUS_MUTEX_PTR_DECLARE createNewMutex();
LOG4CPLUS_EXPORT void deleteMutex(LOG4CPLUS_MUTEX_PTR_DECLARE);
LOG4CPLUS_EXPORT LOG4CPLUS_THREAD_LOCAL_TYPE createPthreadKey(void (*) (void *));
}
}
#elif defined(LOG4CPLUS_USE_WIN32_THREADS)
# undef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# define LOG4CPLUS_MUTEX_PTR_DECLARE CRITICAL_SECTION*
# define LOG4CPLUS_MUTEX_CREATE ::log4cplus::thread::createNewMutex()
# define LOG4CPLUS_MUTEX_LOCK(mutex) EnterCriticalSection(mutex)
# define LOG4CPLUS_MUTEX_UNLOCK(mutex) LeaveCriticalSection(mutex)
# define LOG4CPLUS_MUTEX_FREE(mutex) ::log4cplus::thread::deleteMutex(mutex)
# define LOG4CPLUS_THREAD_HANDLE_TYPE HANDLE
# define LOG4CPLUS_THREAD_KEY_TYPE DWORD
# define LOG4CPLUS_GET_CURRENT_THREAD GetCurrentThreadId()
# define LOG4CPLUS_GET_CURRENT_THREAD_NAME \
::log4cplus::thread::getCurrentThreadName()
# define LOG4CPLUS_THREAD_LOCAL_TYPE DWORD
# define LOG4CPLUS_THREAD_LOCAL_INIT(cleanup) TlsAlloc()
# define LOG4CPLUS_GET_THREAD_LOCAL_VALUE(key) TlsGetValue(key)
# define LOG4CPLUS_SET_THREAD_LOCAL_VALUE(key, value) \
TlsSetValue(key, static_cast<LPVOID>(value))
# define LOG4CPLUS_THREAD_LOCAL_CLEANUP(key) TlsFree(key)
# if defined (_MSC_VER)
# undef LOG4CPLUS_HAVE_TLS_SUPPORT
# undef LOG4CPLUS_THREAD_LOCAL_VAR
// Comment out the following two lines if you do intend to use log4cplus.dll
// for loading using LoadLibrary(). The __declspec(thread) functionality is not
// compatible with such DLL use. For more information why is this necessary see
// <http://msdn.microsoft.com/en-us/library/2s9wt68x(vs.80).aspx>.
# define LOG4CPLUS_HAVE_TLS_SUPPORT 1
# define LOG4CPLUS_THREAD_LOCAL_VAR __declspec(thread)
# endif
namespace log4cplus { namespace thread {
LOG4CPLUS_EXPORT LOG4CPLUS_MUTEX_PTR_DECLARE createNewMutex();
LOG4CPLUS_EXPORT void deleteMutex(LOG4CPLUS_MUTEX_PTR_DECLARE);
} } // namespace log4cplus { namespace thread {
#elif defined(LOG4CPLUS_SINGLE_THREADED)
# define LOG4CPLUS_MUTEX_PTR_DECLARE int*
# define LOG4CPLUS_MUTEX_CREATE NULL
# define LOG4CPLUS_MUTEX_LOCK(mutex)
# define LOG4CPLUS_MUTEX_UNLOCK(mutex)
# define LOG4CPLUS_MUTEX_FREE(mutex)
# define LOG4CPLUS_THREAD_HANDLE_TYPE void *
# define LOG4CPLUS_THREAD_KEY_TYPE int
# define LOG4CPLUS_GET_CURRENT_THREAD 1
# define LOG4CPLUS_GET_CURRENT_THREAD_NAME \
LOG4CPLUS_C_STR_TO_TSTRING("single")
# define LOG4CPLUS_THREAD_LOCAL_TYPE void*
# define LOG4CPLUS_THREAD_LOCAL_INIT(cleanup) NULL
# define LOG4CPLUS_GET_THREAD_LOCAL_VALUE(key) (key)
# define LOG4CPLUS_SET_THREAD_LOCAL_VALUE(key, value) \
do { (key) = (value); } while (0)
# define LOG4CPLUS_THREAD_LOCAL_CLEANUP(key) do { (key) = NULL; } while (0)
# undef LOG4CPLUS_HAVE_TLS_SUPPORT
# undef LOG4CPLUS_THREAD_LOCAL_VAR
#else
# error "You Must define a Threading model"
#endif
/**
* @def LOG4CPLUS_BEGIN_SYNCHRONIZE_ON_MUTEX(mutex)
* Begin a block synchronized on a mutex.
*
* @see LOG4CPLUS_END_SYNCHRONIZE_ON_MUTEX
*
* @def LOG4CPLUS_END_SYNCHRONIZE_ON_MUTEX
* End a block synchronized on a mutex.
*
* @see LOG4CPLUS_BEGIN_SYNCHRONIZE_ON_MUTEX
*/
#ifndef LOG4CPLUS_SINGLE_THREADED
# define LOG4CPLUS_BEGIN_SYNCHRONIZE_ON_MUTEX(mutex) \
do { ::log4cplus::thread::Guard _sync_guard_object(mutex);
#else
# define LOG4CPLUS_BEGIN_SYNCHRONIZE_ON_MUTEX(mutex) do { (void)(mutex);
#endif
#define LOG4CPLUS_END_SYNCHRONIZE_ON_MUTEX } while (0)
#endif // LOG4CPLUS_HELPERS_THREAD_CONFIG_HEADER_

View File

@ -0,0 +1,133 @@
// Module: Log4CPLUS
// File: threads.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2010 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_THREADS_HEADER_
#define _LOG4CPLUS_THREADS_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/pointer.h>
namespace log4cplus { namespace thread {
/**
* This is used to lock a mutex. The dtor unlocks the mutex.
*/
class Guard
{
public:
/** "locks" <code>mutex</code>. */
Guard(LOG4CPLUS_MUTEX_PTR_DECLARE mutex)
: _mutex (mutex)
{
LOG4CPLUS_MUTEX_LOCK( _mutex );
}
/** "unlocks" <code>mutex</code>. */
~Guard()
{
LOG4CPLUS_MUTEX_UNLOCK( _mutex );
}
private:
LOG4CPLUS_MUTEX_PTR_DECLARE _mutex;
// disable copy
Guard(const Guard&);
Guard& operator=(const Guard&);
};
#ifndef LOG4CPLUS_SINGLE_THREADED
LOG4CPLUS_EXPORT void blockAllSignals();
LOG4CPLUS_EXPORT void yield();
LOG4CPLUS_EXPORT tstring getCurrentThreadName();
struct ThreadStart;
/**
* There are many cross-platform C++ Threading libraries. The goal of
* this class is not to replace (or match in functionality) those
* libraries. The goal of this class is to provide a simple Threading
* class with basic functionality.
*/
class LOG4CPLUS_EXPORT AbstractThread
: public virtual log4cplus::helpers::SharedObject
{
public:
AbstractThread();
bool isRunning() const { return (flags & fRUNNING) != 0; }
LOG4CPLUS_THREAD_KEY_TYPE getThreadId() const;
LOG4CPLUS_THREAD_HANDLE_TYPE getThreadHandle () const;
virtual void start();
void join ();
protected:
// Force objects to be constructed on the heap
virtual ~AbstractThread();
virtual void run() = 0;
private:
enum Flags
{
fRUNNING = 0x01,
fJOINED = 0x02
};
unsigned flags;
// Friends.
friend struct ThreadStart;
# ifdef LOG4CPLUS_USE_PTHREADS
pthread_t handle;
# elif defined(LOG4CPLUS_USE_WIN32_THREADS)
HANDLE handle;
# if defined (_WIN32_WCE)
DWORD thread_id;
# else
unsigned thread_id;
# endif
# endif
// Disallow copying of instances of this class.
AbstractThread(const AbstractThread&);
AbstractThread& operator=(const AbstractThread&);
};
typedef helpers::SharedObjectPtr<AbstractThread> AbstractThreadPtr;
#endif // LOG4CPLUS_SINGLE_THREADED
} } // namespace log4cplus { namespace thread {
#endif // _LOG4CPLUS_THREADS_HEADER_

View File

@ -0,0 +1,179 @@
// Module: Log4CPLUS
// File: timehelper.h
// Created: 6/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_HELPERS_TIME_HELPER_HEADER_
#define _LOG4CPLUS_HELPERS_TIME_HELPER_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/tstring.h>
#if defined (LOG4CPLUS_HAVE_TIME_H)
//#include <time.h>
#endif
#if ! defined (_WIN32_WCE)
//#include <ctime>
#endif
namespace log4cplus {
namespace helpers {
#if defined (_WIN32_WCE)
using ::time_t;
using ::tm;
#else
//using std::time_t;
//using std::tm;
#endif
/**
* This class represents a Epoch time with microsecond accuracy.
*/
class LOG4CPLUS_EXPORT Time {
public:
Time();
Time(time_t tv_sec, long tv_usec);
explicit Time(time_t time);
/**
* Returns the current time using the <code>gettimeofday()</code>
* method if it is available on the current platform. (Not on
* WIN32.)
*/
static Time gettimeofday();
// Methods
/**
* Returns <i>seconds</i> value.
*/
time_t sec() const { return tv_sec; }
/**
* Returns <i>microseconds</i> value.
*/
long usec() const { return tv_usec; }
/**
* Sets the <i>seconds</i> value.
*/
void sec(time_t s) { tv_sec = s; }
/**
* Sets the <i>microseconds</i> value.
*/
void usec(long us) { tv_usec = us; }
/**
* Sets this Time using the <code>mktime</code> function.
*/
time_t setTime(tm* t);
/**
* Returns this Time as a <code>time_t</code> value.
*/
time_t getTime() const;
/**
* Populates <code>tm</code> using the <code>gmtime()</code>
* function.
*/
void gmtime(tm* t) const;
/**
* Populates <code>tm</code> using the <code>localtime()</code>
* function.
*/
void localtime(tm* t) const;
/**
* Returns a string with a "formatted time" specified by
* <code>fmt</code>. It used the <code>strftime()</code>
* function to do this.
*
* Look at your platform's <code>strftime()</code> documentation
* for the formatting options available.
*
* The following additional options are provided:<br>
* <code>%q</code> - 3 character field that provides milliseconds
* <code>%Q</code> - 7 character field that provides fractional
* milliseconds.
*/
log4cplus::tstring getFormattedTime(const log4cplus::tstring& fmt,
bool use_gmtime = false) const;
// Operators
Time& operator+=(const Time& rhs);
Time& operator-=(const Time& rhs);
Time& operator/=(long rhs);
Time& operator*=(long rhs);
private:
void build_q_value (log4cplus::tstring & q_str) const;
void build_uc_q_value (log4cplus::tstring & uc_q_str) const;
// Data
time_t tv_sec; /* seconds */
long tv_usec; /* microseconds */
};
LOG4CPLUS_EXPORT const log4cplus::helpers::Time operator+
(const log4cplus::helpers::Time& lhs,
const log4cplus::helpers::Time& rhs);
LOG4CPLUS_EXPORT const log4cplus::helpers::Time operator-
(const log4cplus::helpers::Time& lhs,
const log4cplus::helpers::Time& rhs);
LOG4CPLUS_EXPORT const log4cplus::helpers::Time operator/
(const log4cplus::helpers::Time& lhs,
long rhs);
LOG4CPLUS_EXPORT const log4cplus::helpers::Time operator*
(const log4cplus::helpers::Time& lhs,
long rhs);
LOG4CPLUS_EXPORT bool operator<(const log4cplus::helpers::Time& lhs,
const log4cplus::helpers::Time& rhs);
LOG4CPLUS_EXPORT bool operator<=(const log4cplus::helpers::Time& lhs,
const log4cplus::helpers::Time& rhs);
LOG4CPLUS_EXPORT bool operator>(const log4cplus::helpers::Time& lhs,
const log4cplus::helpers::Time& rhs);
LOG4CPLUS_EXPORT bool operator>=(const log4cplus::helpers::Time& lhs,
const log4cplus::helpers::Time& rhs);
LOG4CPLUS_EXPORT bool operator==(const log4cplus::helpers::Time& lhs,
const log4cplus::helpers::Time& rhs);
LOG4CPLUS_EXPORT bool operator!=(const log4cplus::helpers::Time& lhs,
const log4cplus::helpers::Time& rhs);
} // namespace helpers
} // namespace log4cplus
#endif // _LOG4CPLUS_HELPERS_TIME_HELPER_HEADER_

View File

@ -0,0 +1,316 @@
// Module: Log4CPLUS
// File: hierarchy.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_HIERARCHY_HEADER_
#define _LOG4CPLUS_HIERARCHY_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/logger.h>
#include <log4cplus/helpers/logloguser.h>
#include <log4cplus/helpers/pointer.h>
#include <log4cplus/helpers/threads.h>
#include <map>
#include <memory>
#include <vector>
namespace log4cplus {
// Forward Declarations
class HierarchyLocker;
/**
* This class is specialized in retrieving loggers by name and
* also maintaining the logger hierarchy.
*
* <em>The casual user should not have to deal with this class
* directly.</em> However, if you are in an environment where
* multiple applications run in the same process, then read on.
*
* The structure of the logger hierarchy is maintained by the
* {@link #getInstance} method. The hierarchy is such that children
* link to their parent but parents do not have any pointers to their
* children. Moreover, loggers can be instantiated in any order, in
* particular descendant before ancestor.
*
* In case a descendant is created before a particular ancestor,
* then it creates a provision node for the ancestor and adds itself
* to the provision node. Other descendants of the same ancestor add
* themselves to the previously created provision node.
*/
class LOG4CPLUS_EXPORT Hierarchy : protected log4cplus::helpers::LogLogUser {
public:
// DISABLE_OFF should be set to a value lower than all possible
// priorities.
static const LogLevel DISABLE_OFF;
static const LogLevel DISABLE_OVERRIDE;
// Ctors
/**
* Create a new Logger hierarchy.
*/
Hierarchy();
// Dtor
virtual ~Hierarchy();
// Methods
/**
* This call will clear all logger definitions from the internal
* hashtable. Invoking this method will irrevocably mess up the
* logger hierarchy.
*
* You should <em>really</em> know what you are doing before
* invoking this method.
*/
virtual void clear();
/**
* Returns <code>true </code>if the named logger exists
* (in the default hierarchy).
*
* @param name The name of the logger to search for.
*/
virtual bool exists(const log4cplus::tstring& name);
/**
* Similar to {@link #disable(LogLevel)} except that the LogLevel
* argument is given as a log4cplus::tstring.
*/
virtual void disable(const log4cplus::tstring& loglevelStr);
/**
* Disable all logging requests of LogLevel <em>equal to or
* below</em> the ll parameter <code>p</code>, for
* <em>all</em> loggers in this hierarchy. Logging requests of
* higher LogLevel then <code>p</code> remain unaffected.
*
* Nevertheless, if the {@link
* BasicConfigurator#DISABLE_OVERRIDE_KEY} system property is set to
* "true" or any value other than "false", then logging requests are
* evaluated as usual, i.e. according to the <a
* href="../../../../manual.html#selectionRule">Basic Selection Rule</a>.
*
* The "disable" family of methods are there for speed. They
* allow printing methods such as debug, info, etc. to return
* immediately after an integer comparison without walking the
* logger hierarchy. In most modern computers an integer
* comparison is measured in nanoseconds where as a logger walk is
* measured in units of microseconds.
*/
virtual void disable(LogLevel ll);
/**
* Disable all logging requests regardless of logger and LogLevel.
* This method is equivalent to calling {@link #disable} with the
* argument FATAL_LOG_LEVEL, the highest possible LogLevel.
*/
virtual void disableAll();
/**
* Disable all Debug logging requests regardless of logger.
* This method is equivalent to calling {@link #disable} with the
* argument DEBUG_LOG_LEVEL.
*/
virtual void disableDebug();
/**
* Disable all Info logging requests regardless of logger.
* This method is equivalent to calling {@link #disable} with the
* argument INFO_LOG_LEVEL.
*/
virtual void disableInfo();
/**
* Undoes the effect of calling any of {@link #disable}, {@link
* #disableAll}, {@link #disableDebug} and {@link #disableInfo}
* methods. More precisely, invoking this method sets the Logger
* class internal variable called <code>disable</code> to its
* default "off" value.
*/
virtual void enableAll();
/**
* Return a new logger instance named as the first parameter using
* the default factory.
*
* If a logger of that name already exists, then it will be
* returned. Otherwise, a new logger will be instantiated and
* then linked with its existing ancestors as well as children.
*
* @param name The name of the logger to retrieve.
*/
virtual Logger getInstance(const log4cplus::tstring& name);
/**
* Return a new logger instance named as the first parameter using
* <code>factory</code>.
*
* If a logger of that name already exists, then it will be
* returned. Otherwise, a new logger will be instantiated by the
* <code>factory</code> parameter and linked with its existing
* ancestors as well as children.
*
* @param name The name of the logger to retrieve.
* @param factory The factory that will make the new logger instance.
*/
virtual Logger getInstance(const log4cplus::tstring& name, spi::LoggerFactory& factory);
/**
* Returns all the currently defined loggers in this hierarchy.
*
* The root logger is <em>not</em> included in the returned list.
*/
virtual LoggerList getCurrentLoggers();
/**
* Is the LogLevel specified by <code>level</code> enabled?
*/
virtual bool isDisabled(int level);
/**
* Get the root of this hierarchy.
*/
virtual Logger getRoot() const;
/**
* Reset all values contained in this hierarchy instance to their
* default. This removes all appenders from all loggers, sets
* the LogLevel of all non-root loggers to <code>NOT_SET_LOG_LEVEL</code>,
* sets their additivity flag to <code>true</code> and sets the LogLevel
* of the root logger to DEBUG_LOG_LEVEL. Moreover, message disabling
* is set its default "off" value.
*
* Existing loggers are not removed. They are just reset.
*
* This method should be used sparingly and with care as it will
* block all logging until it is completed.</p>
*/
virtual void resetConfiguration();
/**
* Set the default LoggerFactory instance.
*/
virtual void setLoggerFactory(std::auto_ptr<spi::LoggerFactory> factory);
/**
* Returns the default LoggerFactory instance.
*/
virtual spi::LoggerFactory* getLoggerFactory() { return defaultFactory.get(); }
/**
* Shutting down a hierarchy will <em>safely</em> close and remove
* all appenders in all loggers including the root logger.
*
* Some appenders such as SocketAppender need to be closed before the
* application exits. Otherwise, pending logging events might be
* lost.
*
* The <code>shutdown</code> method is careful to close nested
* appenders before closing regular appenders. This is allows
* configurations where a regular appender is attached to a logger
* and again to a nested appender.
*/
virtual void shutdown();
private:
// Types
typedef std::vector<Logger> ProvisionNode;
typedef std::map<log4cplus::tstring, ProvisionNode> ProvisionNodeMap;
typedef std::map<log4cplus::tstring, Logger> LoggerMap;
// Methods
/**
* This is the implementation of the <code>getInstance()</code> method.
* NOTE: This method does not lock the <code>hashtable_mutex</code>.
*/
virtual Logger getInstanceImpl(const log4cplus::tstring& name,
spi::LoggerFactory& factory);
/**
* This is the implementation of the <code>getCurrentLoggers()</code>.
* NOTE: This method does not lock the <code>hashtable_mutex</code>.
*/
virtual void initializeLoggerList(LoggerList& list) const;
/**
* This method loops through all the *potential* parents of
* logger'. There 3 possible cases:
*
* 1) No entry for the potential parent of 'logger' exists
*
* We create a ProvisionNode for this potential parent and insert
* 'logger' in that provision node.
*
* 2) There is an entry of type Logger for the potential parent.
*
* The entry is 'logger's nearest existing parent. We update logger's
* parent field with this entry. We also break from the loop
* because updating our parent's parent is our parent's
* responsibility.
*
* 3) There entry is of type ProvisionNode for this potential parent.
*
* We add 'logger' to the list of children for this potential parent.
*/
void updateParents(Logger logger);
/**
* We update the links for all the children that placed themselves
* in the provision node 'pn'. The second argument 'logger' is a
* reference for the newly created Logger, parent of all the
* children in 'pn'
*
* We loop on all the children 'c' in 'pn':
*
* If the child 'c' has been already linked to a child of
* 'logger' then there is no need to update 'c'.
*
* Otherwise, we set logger's parent field to c's parent and set
* c's parent field to logger.
*/
void updateChildren(ProvisionNode& pn, Logger logger);
// Data
LOG4CPLUS_MUTEX_PTR_DECLARE hashtable_mutex;
std::auto_ptr<spi::LoggerFactory> defaultFactory;
ProvisionNodeMap provisionNodes;
LoggerMap loggerPtrs;
Logger root;
int disableValue;
bool emittedNoAppenderWarning;
bool emittedNoResourceBundleWarning;
// Disallow copying of instances of this class
Hierarchy(const Hierarchy&);
Hierarchy& operator=(const Hierarchy&);
// Friends
friend class log4cplus::spi::LoggerImpl;
friend class log4cplus::HierarchyLocker;
};
} // end namespace log4cplus
#endif // _LOG4CPLUS_HIERARCHY_HEADER_

View File

@ -0,0 +1,67 @@
// Module: Log4CPLUS
// File: hierarchylocker.h
// Created: 8/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_HIERARCHY_LOCKER_HEADER_
#define _LOG4CPLUS_HIERARCHY_LOCKER_HEADER_
#include <log4cplus/hierarchy.h>
namespace log4cplus {
/**
* This is used to lock a Hierarchy. The dtor unlocks the Hierarchy.
*/
class LOG4CPLUS_EXPORT HierarchyLocker {
public:
// ctor & dtor
HierarchyLocker(Hierarchy& h);
~HierarchyLocker();
/**
* Calls the <code>resetConfiguration()</code> method on the locked Hierarchy.
*/
void resetConfiguration();
/**
* Calls the <code>getInstance()</code> method on the locked Hierarchy.
*/
Logger getInstance(const log4cplus::tstring& name);
/**
* Calls the <code>getInstance()</code> method on the locked Hierarchy.
*/
Logger getInstance(const log4cplus::tstring& name, spi::LoggerFactory& factory);
void addAppender(Logger &logger, log4cplus::SharedAppenderPtr& appender);
private:
// Data
Hierarchy& h;
log4cplus::thread::Guard hierarchyLocker;
LoggerList loggerList;
};
} // end namespace log4cplus
#endif // _LOG4CPLUS_HIERARCHY_LOCKER_HEADER_

View File

@ -0,0 +1,532 @@
// Module: Log4CPLUS
// File: Layout.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_LAYOUT_HEADER_
#define _LOG4CPLUS_LAYOUT_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/loglevel.h>
#include <log4cplus/streams.h>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/logloguser.h>
#include <log4cplus/helpers/property.h>
#include <log4cplus/helpers/timehelper.h>
#include <log4cplus/spi/loggingevent.h>
#include <vector>
namespace log4cplus {
// Forward Declarations
namespace pattern {
class PatternConverter;
}
/**
* This class is used to layout strings sent to an {@link
* log4cplus::Appender}.
*/
class LOG4CPLUS_EXPORT Layout : protected :: log4cplus::helpers::LogLogUser {
public:
Layout() : llmCache(getLogLevelManager()) {}
Layout(const log4cplus::helpers::Properties&)
: llmCache(getLogLevelManager()) {}
virtual ~Layout() {}
virtual void formatAndAppend(log4cplus::tostream& output,
const log4cplus::spi::InternalLoggingEvent& event) = 0;
protected:
LogLevelManager& llmCache;
private:
// Disable copy
Layout(const Layout&);
Layout& operator=(Layout&);
};
/**
* SimpleLayout consists of the LogLevel of the log statement,
* followed by " - " and then the log message itself. For example,
*
* <pre>
* DEBUG - Hello world
* </pre>
*
* {@link PatternLayout} offers a much more powerful alternative.
*/
class LOG4CPLUS_EXPORT SimpleLayout : public Layout {
public:
SimpleLayout() {}
SimpleLayout(const log4cplus::helpers::Properties& properties) : Layout(properties) {}
virtual void formatAndAppend(log4cplus::tostream& output,
const log4cplus::spi::InternalLoggingEvent& event);
private:
// Disallow copying of instances of this class
SimpleLayout(const SimpleLayout&);
SimpleLayout& operator=(const SimpleLayout&);
};
/**
* TTCC layout format consists of time, thread, Logger and nested
* diagnostic context information, hence the name.
*
* The time format depends on the <code>DateFormat</code> used. Use the
* <code>Use_gmtime</code> to specify whether messages should be logged using
* <code>localtime</code> or <code>gmtime</code>.
*
* Here is an example TTCCLayout output:
*
* <pre>
* 176 [main] INFO org.apache.log4j.examples.Sort - Populating an array of 2 elements in reverse order.
* 225 [main] INFO org.apache.log4j.examples.SortAlgo - Entered the sort method.
* 262 [main] DEBUG org.apache.log4j.examples.SortAlgo.OUTER i=1 - Outer loop.
* 276 [main] DEBUG org.apache.log4j.examples.SortAlgo.SWAP i=1 j=0 - Swapping intArray[0] = 1 and intArray[1] = 0
* 290 [main] DEBUG org.apache.log4j.examples.SortAlgo.OUTER i=0 - Outer loop.
* 304 [main] INFO org.apache.log4j.examples.SortAlgo.DUMP - Dump of interger array:
* 317 [main] INFO org.apache.log4j.examples.SortAlgo.DUMP - Element [0] = 0
* 331 [main] INFO org.apache.log4j.examples.SortAlgo.DUMP - Element [1] = 1
* 343 [main] INFO org.apache.log4j.examples.Sort - The next log statement should be an error message.
* 346 [main] ERROR org.apache.log4j.examples.SortAlgo.DUMP - Tried to dump an uninitialized array.
* 467 [main] INFO org.apache.log4j.examples.Sort - Exiting main method.
* </pre>
*
* The first field is the number of milliseconds elapsed since the
* start of the program. The second field is the thread outputting the
* log statement. The third field is the LogLevel, the fourth field is
* the logger to which the statement belongs.
*
* The fifth field (just before the '-') is the nested diagnostic
* context. Note the nested diagnostic context may be empty as in the
* first two statements. The text after the '-' is the message of the
* statement.
*
* PatternLayout offers a much more flexible alternative.
*/
class LOG4CPLUS_EXPORT TTCCLayout : public Layout {
public:
// Ctor and dtor
TTCCLayout(bool use_gmtime = false);
TTCCLayout(const log4cplus::helpers::Properties& properties);
virtual ~TTCCLayout();
virtual void formatAndAppend(log4cplus::tostream& output,
const log4cplus::spi::InternalLoggingEvent& event);
protected:
log4cplus::tstring dateFormat;
bool use_gmtime;
private:
// Disallow copying of instances of this class
TTCCLayout(const TTCCLayout&);
TTCCLayout& operator=(const TTCCLayout&);
};
/**
* A flexible layout configurable with pattern string.
*
* The goal of this class is to format a InternalLoggingEvent and return
* the results as a string. The results depend on the <em>conversion
* pattern</em>.
*
* The conversion pattern is closely related to the conversion
* pattern of the printf function in C. A conversion pattern is
* composed of literal text and format control expressions called
* <em>conversion specifiers</em>.
*
* <i>You are free to insert any literal text within the conversion
* pattern.</i>
*
* Each conversion specifier starts with a percent sign (%%) and is
* followed by optional <em>format modifiers</em> and a <em>conversion
* character</em>. The conversion character specifies the type of
* data, e.g. Logger, LogLevel, date, thread name. The format
* modifiers control such things as field width, padding, left and
* right justification. The following is a simple example.
*
* Let the conversion pattern be <b>"%-5p [%t]: %m%n"</b> and assume
* that the log4cplus environment was set to use a PatternLayout. Then the
* statements
* <code><pre>
* Logger root = Logger.getRoot();
* LOG4CPLUS_DEBUG(root, "Message 1");
* LOG4CPLUS_WARN(root, "Message 2");
* </pre></code>
* would yield the output
* <tt><pre>
* DEBUG [main]: Message 1
* WARN [main]: Message 2
* </pre></tt>
*
* Note that there is no explicit separator between text and
* conversion specifiers. The pattern parser knows when it has reached
* the end of a conversion specifier when it reads a conversion
* character. In the example above the conversion specifier
* <b>"%-5p"</b> means the LogLevel of the logging event should be left
* justified to a width of five characters.
*
* The recognized conversion characters are
*
*
* <table border="1" CELLPADDING="8">
* <tr>
* <td>Conversion Character</td>
* <td>Effect</td>
* </tr>
*
* <tr>
* <td align=center><b>b</b></td>
*
* <td>Used to output file name component of path name.
* E.g. <tt>main.cxx</tt> from path <tt>../../main.cxx</tt>.</td>
* </tr>
*
* <tr>
* <td align=center><b>c</b></td>
*
* <td>Used to output the logger of the logging event. The
* logger conversion specifier can be optionally followed by
* <em>precision specifier</em>, that is a decimal constant in
* brackets.
*
* If a precision specifier is given, then only the corresponding
* number of right most components of the logger name will be
* printed. By default the logger name is printed in full.
*
* For example, for the logger name "a.b.c" the pattern
* <b>%c{2}</b> will output "b.c".
*
* </td>
* </tr>
*
* <tr>
* <td align=center><b>d</b></td>
*
* <td>Used to output the date of the logging event in <b>UTC</b>.
*
* The date conversion specifier may be followed by a <em>date format
* specifier</em> enclosed between braces. For example, <b>%%d{%%H:%%M:%%s}</b>
* or <b>%%d{%%d&nbsp;%%b&nbsp;%%Y&nbsp;%%H:%%M:%%s}</b>. If no date format
* specifier is given then <b>%%d{%%d&nbsp;%%m&nbsp;%%Y&nbsp;%%H:%%M:%%s}</b>
* is assumed.
*
* The Following format options are possible:
* <ul>
* <li>%%a -- Abbreviated weekday name</li>
* <li>%%A -- Full weekday name</li>
* <li>%%b -- Abbreviated month name</li>
* <li>%%B -- Full month name</li>
* <li>%%c -- Standard date and time string</li>
* <li>%%d -- Day of month as a decimal(1-31)</li>
* <li>%%H -- Hour(0-23)</li>
* <li>%%I -- Hour(1-12)</li>
* <li>%%j -- Day of year as a decimal(1-366)</li>
* <li>%%m -- Month as decimal(1-12)</li>
* <li>%%M -- Minute as decimal(0-59)</li>
* <li>%%p -- Locale's equivalent of AM or PM</li>
* <li>%%q -- milliseconds as decimal(0-999) -- <b>Log4CPLUS specific</b>
* <li>%%Q -- fractional milliseconds as decimal(0-999.999) -- <b>Log4CPLUS specific</b>
* <li>%%S -- Second as decimal(0-59)</li>
* <li>%%U -- Week of year, Sunday being first day(0-53)</li>
* <li>%%w -- Weekday as a decimal(0-6, Sunday being 0)</li>
* <li>%%W -- Week of year, Monday being first day(0-53)</li>
* <li>%%x -- Standard date string</li>
* <li>%%X -- Standard time string</li>
* <li>%%y -- Year in decimal without century(0-99)</li>
* <li>%%Y -- Year including century as decimal</li>
* <li>%%Z -- Time zone name</li>
* <li>%% -- The percent sign</li>
* </ul>
*
* Lookup the documentation for the <code>strftime()</code> function
* found in the <code>&lt;ctime&gt;</code> header for more information.
* </td>
* </tr>
*
* <tr>
* <td align=center><b>D</b></td>
*
* <td>Used to output the date of the logging event in <b>local</b> time.
*
* All of the above information applies.
* </td>
* </tr>
*
* <tr>
* <td align=center><b>F</b></td>
*
* <td>Used to output the file name where the logging request was
* issued.
*
* <b>NOTE</b> Unlike log4j, there is no performance penalty for
* calling this method.
*
* </tr>
*
* <tr>
* <td align=center><b>h</b></td>
*
* <td>Used to output the hostname of this system (as returned
* by gethostname(2)).
*
* <b>NOTE</b> The hostname is only retrieved once at
* initialization.
*
* </td>
* </tr>
*
* <tr>
* <td align=center><b>H</b></td>
*
* <td>Used to output the fully-qualified domain name of this
* system (as returned by gethostbyname(2) for the hostname
* returned by gethostname(2)).
*
* <b>NOTE</b> The hostname is only retrieved once at
* initialization.
*
* </td>
* </tr>
*
* <tr>
* <td align=center><b>l</b></td>
*
* <td>Equivalent to using "%F:%L"
*
* <b>NOTE:</b> Unlike log4j, there is no performance penalty for
* calling this method.
*
* </td>
* </tr>
*
* <tr>
* <td align=center><b>L</b></td>
*
* <td>Used to output the line number from where the logging request
* was issued.
*
* <b>NOTE:</b> Unlike log4j, there is no performance penalty for
* calling this method.
*
* </tr>
*
*
* <tr>
* <td align=center><b>m</b></td>
* <td>Used to output the application supplied message associated with
* the logging event.</td>
* </tr>
*
* <tr>
* <td align=center><b>n</b></td>
*
* <td>Outputs the platform dependent line separator character or
* characters.
* </tr>
*
* <tr>
* <td align=center><b>p</b></td>
* <td>Used to output the LogLevel of the logging event.</td>
* </tr>
*
* <tr>
* <td align=center><b>t</b></td>
*
* <td>Used to output the name of the thread that generated the
* logging event.</td>
* </tr>
*
* <tr>
* <td align=center><b>i</b></td>
*
* <td>Used to output the process ID of the process that generated the
* logging event.</td>
* </tr>
*
* <tr>
* <td align=center><b>x</b></td>
*
* <td>Used to output the NDC (nested diagnostic context) associated
* with the thread that generated the logging event.
* </td>
* </tr>
*
* <tr>
* <td align=center><b>"%%"</b></td>
* <td>The sequence "%%" outputs a single percent sign.
* </td>
* </tr>
*
* </table>
*
* By default the relevant information is output as is. However,
* with the aid of format modifiers it is possible to change the
* minimum field width, the maximum field width and justification.
*
* The optional format modifier is placed between the percent sign
* and the conversion character.
*
* The first optional format modifier is the <em>left justification
* flag</em> which is just the minus (-) character. Then comes the
* optional <em>minimum field width</em> modifier. This is a decimal
* constant that represents the minimum number of characters to
* output. If the data item requires fewer characters, it is padded on
* either the left or the right until the minimum width is
* reached. The default is to pad on the left (right justify) but you
* can specify right padding with the left justification flag. The
* padding character is space. If the data item is larger than the
* minimum field width, the field is expanded to accommodate the
* data. The value is never truncated.
*
* This behavior can be changed using the <em>maximum field
* width</em> modifier which is designated by a period followed by a
* decimal constant. If the data item is longer than the maximum
* field, then the extra characters are removed from the
* <em>beginning</em> of the data item and not from the end. For
* example, it the maximum field width is eight and the data item is
* ten characters long, then the first two characters of the data item
* are dropped. This behavior deviates from the printf function in C
* where truncation is done from the end.
*
* Below are various format modifier examples for the logger
* conversion specifier.
*
*
* <TABLE BORDER=1 CELLPADDING=8>
* <tr>
* <td>Format modifier</td>
* <td>left justify</td>
* <td>minimum width</td>
* <td>maximum width</td>
* <td>comment</td>
* </tr>
*
* <tr>
* <td align=center>%20c</td>
* <td align=center>false</td>
* <td align=center>20</td>
* <td align=center>none</td>
*
* <td>Left pad with spaces if the logger name is less than 20
* characters long.
* </tr>
*
* <tr> <td align=center>%-20c</td> <td align=center>true</td> <td
* align=center>20</td> <td align=center>none</td> <td>Right pad with
* spaces if the logger name is less than 20 characters long.
* </tr>
*
* <tr>
* <td align=center>%.30c</td>
* <td align=center>NA</td>
* <td align=center>none</td>
* <td align=center>30</td>
*
* <td>Truncate from the beginning if the logger name is longer than 30
* characters.
* </tr>
*
* <tr>
* <td align=center>%20.30c</td>
* <td align=center>false</td>
* <td align=center>20</td>
* <td align=center>30</td>
*
* <td>Left pad with spaces if the logger name is shorter than 20
* characters. However, if logger name is longer than 30 characters,
* then truncate from the beginning.
* </tr>
*
* <tr>
* <td align=center>%-20.30c</td>
* <td align=center>true</td>
* <td align=center>20</td>
* <td align=center>30</td>
*
* <td>Right pad with spaces if the logger name is shorter than 20
* characters. However, if logger name is longer than 30 characters,
* then truncate from the beginning.
* </tr>
*
* </table>
*
* Below are some examples of conversion patterns.
*
* <dl>
*
* <dt><b>"%r [%t] %-5p %c %x - %m%n"</b>
* <dd>This is essentially the TTCC layout.
*
* <dt><b>"%-6r [%15.15t] %-5p %30.30c %x - %m%n"</b>
*
* <dd>Similar to the TTCC layout except that the relative time is
* right padded if less than 6 digits, thread name is right padded if
* less than 15 characters and truncated if longer and the logger
* name is left padded if shorter than 30 characters and truncated if
* longer.
*
* </dl>
*
* The above text is largely inspired from Peter A. Darnell and
* Philip E. Margolis' highly recommended book "C -- a Software
* Engineering Approach", ISBN 0-387-97389-3.
*/
class LOG4CPLUS_EXPORT PatternLayout : public Layout {
public:
// Ctors and dtor
PatternLayout(const log4cplus::tstring& pattern);
PatternLayout(const log4cplus::helpers::Properties& properties);
virtual ~PatternLayout();
virtual void formatAndAppend(log4cplus::tostream& output,
const log4cplus::spi::InternalLoggingEvent& event);
protected:
void init(const log4cplus::tstring& pattern, unsigned ndcMaxDepth = 0);
// Data
log4cplus::tstring pattern;
std::vector<pattern::PatternConverter*> parsedPattern;
private:
// Disallow copying of instances of this class
PatternLayout(const PatternLayout&);
PatternLayout& operator=(const PatternLayout&);
};
} // end namespace log4cplus
#endif // _LOG4CPLUS_LAYOUT_HEADER_

View File

@ -0,0 +1,344 @@
// Module: Log4CPLUS
// File: logger.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2010 Tad E. Smith
//
// Licensed 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.
/** @file
* This header defines the Logger class and the logging macros. */
#ifndef _LOG4CPLUS_LOGGERHEADER_
#define _LOG4CPLUS_LOGGERHEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/loglevel.h>
#include <log4cplus/tstring.h>
#include <log4cplus/spi/appenderattachable.h>
#include <log4cplus/spi/loggerfactory.h>
#include <vector>
namespace log4cplus
{
// Forward declarations
class Appender;
class Hierarchy;
class HierarchyLocker;
class DefaultLoggerFactory;
namespace spi
{
class LoggerImpl;
}
/** \typedef std::vector<Logger> LoggerList
* This is a list of {@link Logger Loggers}. */
typedef std::vector<Logger> LoggerList;
/**
* This is the central class in the log4cplus package. One of the
* distintive features of log4cplus are hierarchical loggers and their
* evaluation.
*
* See the <a href="../../../../manual.html">user manual</a> for an
* introduction on this class.
*/
class LOG4CPLUS_EXPORT Logger
: public log4cplus::spi::AppenderAttachable
{
public:
// Static Methods
/**
* Returns <code>true </code>if the named logger exists
* (in the default hierarchy).
*
* @param name The name of the logger to search for.
*/
static bool exists(const log4cplus::tstring& name);
/*
* Returns all the currently defined loggers in the default
* hierarchy.
*
* The root logger is <em>not</em> included in the returned
* list.
*/
static LoggerList getCurrentLoggers();
/**
* Return the default Hierarchy instance.
*/
static Hierarchy& getDefaultHierarchy();
/**
* Retrieve a logger with name <code>name</code>. If the named
* logger already exists, then the existing instance will be returned.
* Otherwise, a new instance is created.
*
* By default, loggers do not have a set LogLevel but inherit
* it from the hierarchy. This is one of the central features of
* log4cplus.
*
* @param name The name of the logger to retrieve.
*/
static Logger getInstance(const log4cplus::tstring& name);
/**
* Like getInstance() except that the type of logger
* instantiated depends on the type returned by the {@link
* spi::LoggerFactory#makeNewLoggerInstance} method of the
* <code>factory</code> parameter.
*
* This method is intended to be used by sub-classes.
*
* @param name The name of the logger to retrieve.
* @param factory A {@link spi::LoggerFactory} implementation that will
* actually create a new Instance.
*/
static Logger getInstance(const log4cplus::tstring& name, spi::LoggerFactory& factory);
/**
* Return the root of the default logger hierrachy.
*
* The root logger is always instantiated and available. It's
* name is "root".
*
* Nevertheless, calling {@link #getInstance
* Logger.getInstance("root")} does not retrieve the root logger
* but a logger just under root named "root".
*/
static Logger getRoot();
/**
* Calling this method will <em>safely</em> close and remove all
* appenders in all the loggers including root contained in the
* default hierachy.
*
* Some appenders such as SocketAppender need to be closed before the
* application exits. Otherwise, pending logging events might be
* lost.
*
* The <code>shutdown</code> method is careful to close nested
* appenders before closing regular appenders. This is allows
* configurations where a regular appender is attached to a logger
* and again to a nested appender.
*/
static void shutdown();
// Non-Static Methods
/**
* If <code>assertionVal</code> parameter is <code>false</code>, then
* logs <code>msg</code> with FATAL_LOG_LEVEL log level.
*
* @param assertionVal Truth value of assertion condition.
* @param msg The message to print if <code>assertion</code> is
* false.
*/
void assertion(bool assertionVal, const log4cplus::tstring& msg) const;
/**
* Close all attached appenders implementing the AppenderAttachable
* interface.
*/
void closeNestedAppenders() const;
/**
* Check whether this logger is enabled for a given
* LogLevel passed as parameter.
*
* @return boolean True if this logger is enabled for <code>ll</code>.
*/
bool isEnabledFor(LogLevel ll) const;
/**
* This generic form is intended to be used by wrappers.
*/
void log(LogLevel ll, const log4cplus::tstring& message,
const char* file=NULL, int line=-1) const;
/**
* This method creates a new logging event and logs the event
* without further checks.
*/
void forcedLog(LogLevel ll, const log4cplus::tstring& message,
const char* file=NULL, int line=-1) const;
/**
* Call the appenders in the hierrachy starting at
* <code>this</code>. If no appenders could be found, emit a
* warning.
*
* This method calls all the appenders inherited from the
* hierarchy circumventing any evaluation of whether to log or not
* to log the particular log request.
*
* @param event the event to log.
*/
void callAppenders(const spi::InternalLoggingEvent& event) const;
/**
* Starting from this logger, search the logger hierarchy for a
* "set" LogLevel and return it. Otherwise, return the LogLevel of the
* root logger.
*
* The Logger class is designed so that this method executes as
* quickly as possible.
*/
LogLevel getChainedLogLevel() const;
/**
* Returns the assigned LogLevel, if any, for this Logger.
*
* @return LogLevel - the assigned LogLevel, can be <code>NOT_SET_LOG_LEVEL</code>.
*/
LogLevel getLogLevel() const;
/**
* Set the LogLevel of this Logger.
*/
void setLogLevel(LogLevel ll);
/**
* Return the the {@link Hierarchy} where this <code>Logger</code> instance is
* attached.
*/
Hierarchy& getHierarchy() const;
/**
* Return the logger name.
*/
log4cplus::tstring getName() const;
/**
* Get the additivity flag for this Logger instance.
*/
bool getAdditivity() const;
/**
* Set the additivity flag for this Logger instance.
*/
void setAdditivity(bool additive);
// AppenderAttachable Methods
virtual void addAppender(SharedAppenderPtr newAppender);
virtual SharedAppenderPtrList getAllAppenders();
virtual SharedAppenderPtr getAppender(const log4cplus::tstring& name);
virtual void removeAllAppenders();
virtual void removeAppender(SharedAppenderPtr appender);
virtual void removeAppender(const log4cplus::tstring& name);
Logger ();
Logger(const Logger& rhs);
Logger& operator=(const Logger& rhs);
virtual ~Logger();
void swap (Logger &);
/**
* Used to retrieve the parent of this Logger in the
* Logger tree.
*/
Logger getParent() const;
protected:
// Data
/** This is a pointer to the implementation class. */
spi::LoggerImpl * value;
private:
// Ctors
/**
* This constructor created a new <code>Logger</code> instance
* with a pointer to a Logger implementation.
*
* You should not create loggers directly.
*
* @param ptr A pointer to the Logger implementation. This value
* cannot be NULL.
*/
Logger(spi::LoggerImpl * ptr);
// Friends
friend class log4cplus::spi::LoggerImpl;
friend class log4cplus::Hierarchy;
friend class log4cplus::HierarchyLocker;
friend class log4cplus::DefaultLoggerFactory;
};
/**
* This class is used to create the default implementation of
* the Logger class
*/
class LOG4CPLUS_EXPORT DefaultLoggerFactory : public spi::LoggerFactory {
public:
Logger makeNewLoggerInstance(const log4cplus::tstring& name, Hierarchy& h);
};
/**
* This class is used to produce "Trace" logging. When an instance of
* this class is created, it will log a <code>"ENTER: " + msg</code>
* log message if TRACE_LOG_LEVEL is enabled for <code>logger</code>.
* When an instance of this class is destroyed, it will log a
* <code>"ENTER: " + msg</code> log message if TRACE_LOG_LEVEL is enabled
* for <code>logger</code>.
*
* @see LOG4CPLUS_TRACE
*/
class TraceLogger
{
public:
TraceLogger(const Logger& l, const log4cplus::tstring& _msg,
const char* _file=NULL, int _line=-1)
: logger(l), msg(_msg), file(_file), line(_line)
{ if(logger.isEnabledFor(TRACE_LOG_LEVEL))
logger.forcedLog(TRACE_LOG_LEVEL, LOG4CPLUS_TEXT("ENTER: ") + msg, file, line);
}
~TraceLogger()
{ if(logger.isEnabledFor(TRACE_LOG_LEVEL))
logger.forcedLog(TRACE_LOG_LEVEL, LOG4CPLUS_TEXT("EXIT: ") + msg, file, line);
}
private:
Logger logger;
log4cplus::tstring msg;
const char* file;
int line;
};
} // end namespace log4cplus
#include <log4cplus/loggingmacros.h>
#endif // _LOG4CPLUS_LOGGERHEADER_

View File

@ -0,0 +1,191 @@
// Module: Log4CPLUS
// File: loggingmacros.h
// Created: 8/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2009 Tad E. Smith
//
// Licensed 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.
/** @file
* This header defines the logging macros. */
#ifndef _LOG4CPLUS_LOGGING_MACROS_HEADER_
#define _LOG4CPLUS_LOGGING_MACROS_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/streams.h>
#if defined(LOG4CPLUS_DISABLE_FATAL) && !defined(LOG4CPLUS_DISABLE_ERROR)
#define LOG4CPLUS_DISABLE_ERROR
#endif
#if defined(LOG4CPLUS_DISABLE_ERROR) && !defined(LOG4CPLUS_DISABLE_WARN)
#define LOG4CPLUS_DISABLE_WARN
#endif
#if defined(LOG4CPLUS_DISABLE_WARN) && !defined(LOG4CPLUS_DISABLE_INFO)
#define LOG4CPLUS_DISABLE_INFO
#endif
#if defined(LOG4CPLUS_DISABLE_INFO) && !defined(LOG4CPLUS_DISABLE_DEBUG)
#define LOG4CPLUS_DISABLE_DEBUG
#endif
#if defined(LOG4CPLUS_DISABLE_DEBUG) && !defined(LOG4CPLUS_DISABLE_TRACE)
#define LOG4CPLUS_DISABLE_TRACE
#endif
#if defined (LOG4CPLUS_SINGLE_THREADED)
namespace log4cplus
{
extern LOG4CPLUS_EXPORT tostringstream _macros_oss;
LOG4CPLUS_EXPORT void _clear_tostringstream (tostringstream &);
} // namespace log4cplus
#define LOG4CPLUS_MACRO_BODY(logger, logEvent, logLevel) \
do { \
if((logger).isEnabledFor(log4cplus::logLevel##_LOG_LEVEL)) { \
log4cplus::_clear_tostringstream (log4cplus::_macros_oss); \
log4cplus::_macros_oss << logEvent; \
(logger).forcedLog(log4cplus::logLevel##_LOG_LEVEL, \
log4cplus::_macros_oss.str(), __FILE__, __LINE__); \
} \
} while (0)
#else // defined (LOG4CPLUS_SINGLE_THREADED)
#define LOG4CPLUS_MACRO_BODY(logger, logEvent, logLevel) \
do { \
if((logger).isEnabledFor(log4cplus::logLevel##_LOG_LEVEL)) { \
log4cplus::tostringstream _log4cplus_buf; \
_log4cplus_buf << logEvent; \
(logger).forcedLog(log4cplus::logLevel##_LOG_LEVEL, \
_log4cplus_buf.str(), __FILE__, __LINE__); \
} \
} while (0)
#endif // defined (LOG4CPLUS_SINGLE_THREADED)
#define LOG4CPLUS_MACRO_STR_BODY(logger, logEvent, logLevel) \
do { \
if((logger).isEnabledFor(log4cplus::logLevel##_LOG_LEVEL)) { \
(logger).forcedLog(log4cplus::logLevel##_LOG_LEVEL, \
logEvent, __FILE__, __LINE__); \
} \
} while(0)
/**
* @def LOG4CPLUS_TRACE(logger, logEvent) This macro creates a TraceLogger
* to log a TRACE_LOG_LEVEL message to <code>logger</code> upon entry and
* exiting of a method.
* <code>logEvent</code> will be streamed into an <code>ostream</code>.
*/
#if !defined(LOG4CPLUS_DISABLE_TRACE)
#define LOG4CPLUS_TRACE_METHOD(logger, logEvent) \
log4cplus::TraceLogger _log4cplus_trace_logger(logger, logEvent, \
__FILE__, __LINE__);
#define LOG4CPLUS_TRACE(logger, logEvent) \
LOG4CPLUS_MACRO_BODY (logger, logEvent, TRACE)
#define LOG4CPLUS_TRACE_STR(logger, logEvent) \
LOG4CPLUS_MACRO_STR_BODY (logger, logEvent, TRACE)
#else
#define LOG4CPLUS_TRACE_METHOD(logger, logEvent) do { } while (0)
#define LOG4CPLUS_TRACE(logger, logEvent) do { } while (0)
#define LOG4CPLUS_TRACE_STR(logger, logEvent) do { } while (0)
#endif
/**
* @def LOG4CPLUS_DEBUG(logger, logEvent) This macro is used to log a
* DEBUG_LOG_LEVEL message to <code>logger</code>.
* <code>logEvent</code> will be streamed into an <code>ostream</code>.
*/
#if !defined(LOG4CPLUS_DISABLE_DEBUG)
#define LOG4CPLUS_DEBUG(logger, logEvent) \
LOG4CPLUS_MACRO_BODY (logger, logEvent, DEBUG)
#define LOG4CPLUS_DEBUG_STR(logger, logEvent) \
LOG4CPLUS_MACRO_STR_BODY (logger, logEvent, DEBUG)
#else
#define LOG4CPLUS_DEBUG(logger, logEvent) do { } while (0)
#define LOG4CPLUS_DEBUG_STR(logger, logEvent) do { } while (0)
#endif
/**
* @def LOG4CPLUS_INFO(logger, logEvent) This macro is used to log a
* INFO_LOG_LEVEL message to <code>logger</code>.
* <code>logEvent</code> will be streamed into an <code>ostream</code>.
*/
#if !defined(LOG4CPLUS_DISABLE_INFO)
#define LOG4CPLUS_INFO(logger, logEvent) \
LOG4CPLUS_MACRO_BODY (logger, logEvent, INFO)
#define LOG4CPLUS_INFO_STR(logger, logEvent) \
LOG4CPLUS_MACRO_STR_BODY (logger, logEvent, INFO)
#else
#define LOG4CPLUS_INFO(logger, logEvent) do { } while (0)
#define LOG4CPLUS_INFO_STR(logger, logEvent) do { } while (0)
#endif
/**
* @def LOG4CPLUS_WARN(logger, logEvent) This macro is used to log a
* WARN_LOG_LEVEL message to <code>logger</code>.
* <code>logEvent</code> will be streamed into an <code>ostream</code>.
*/
#if !defined(LOG4CPLUS_DISABLE_WARN)
#define LOG4CPLUS_WARN(logger, logEvent) \
LOG4CPLUS_MACRO_BODY (logger, logEvent, WARN)
#define LOG4CPLUS_WARN_STR(logger, logEvent) \
LOG4CPLUS_MACRO_STR_BODY (logger, logEvent, WARN)
#else
#define LOG4CPLUS_WARN(logger, logEvent) do { } while (0)
#define LOG4CPLUS_WARN_STR(logger, logEvent) do { } while (0)
#endif
/**
* @def LOG4CPLUS_ERROR(logger, logEvent) This macro is used to log a
* ERROR_LOG_LEVEL message to <code>logger</code>.
* <code>logEvent</code> will be streamed into an <code>ostream</code>.
*/
#if !defined(LOG4CPLUS_DISABLE_ERROR)
#define LOG4CPLUS_ERROR(logger, logEvent) \
LOG4CPLUS_MACRO_BODY (logger, logEvent, ERROR)
#define LOG4CPLUS_ERROR_STR(logger, logEvent) \
LOG4CPLUS_MACRO_STR_BODY (logger, logEvent, ERROR)
#else
#define LOG4CPLUS_ERROR(logger, logEvent) do { } while (0)
#define LOG4CPLUS_ERROR_STR(logger, logEvent) do { } while (0)
#endif
/**
* @def LOG4CPLUS_FATAL(logger, logEvent) This macro is used to log a
* FATAL_LOG_LEVEL message to <code>logger</code>.
* <code>logEvent</code> will be streamed into an <code>ostream</code>.
*/
#if !defined(LOG4CPLUS_DISABLE_FATAL)
#define LOG4CPLUS_FATAL(logger, logEvent) \
LOG4CPLUS_MACRO_BODY (logger, logEvent, FATAL)
#define LOG4CPLUS_FATAL_STR(logger, logEvent) \
LOG4CPLUS_MACRO_STR_BODY (logger, logEvent, FATAL)
#else
#define LOG4CPLUS_FATAL(logger, logEvent) do { } while (0)
#define LOG4CPLUS_FATAL_STR(logger, logEvent) do { } while (0)
#endif
#endif /* _LOG4CPLUS_LOGGING_MACROS_HEADER_ */

View File

@ -0,0 +1,183 @@
// Module: Log4CPLUS
// File: loglevel.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2010 Tad E. Smith
//
// Licensed 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.
/** @file
* This header defines the LogLevel type.
*/
#ifndef LOG4CPLUS_LOGLEVEL_HEADER_
#define LOG4CPLUS_LOGLEVEL_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/tstring.h>
#include <vector>
namespace log4cplus {
/**
* \typedef int LogLevel
* Defines the minimum set of priorities recognized by the system,
* that is {@link #FATAL_LOG_LEVEL}, {@link #ERROR_LOG_LEVEL}, {@link
* #WARN_LOG_LEVEL}, {@link #INFO_LOG_LEVEL}, {@link #DEBUG_LOG_LEVEL},
* and {@link #TRACE_LOG_LEVEL}.
*/
typedef int LogLevel;
/** \var const LogLevel OFF_LOG_LEVEL
* The <code>OFF_LOG_LEVEL</code> LogLevel is used during configuration to
* turn off logging. */
const LogLevel OFF_LOG_LEVEL = 60000;
/** \var const LogLevel FATAL_LOG_LEVEL
* The <code>FATAL_LOG_LEVEL</code> LogLevel designates very severe error
* events that will presumably lead the application to abort. */
const LogLevel FATAL_LOG_LEVEL = 50000;
/** \var const LogLevel ERROR_LOG_LEVEL
* The <code>ERROR_LOG_LEVEL</code> LogLevel designates error events that
* might still allow the application to continue running. */
const LogLevel ERROR_LOG_LEVEL = 40000;
/** \var const LogLevel WARN_LOG_LEVEL
* The <code>WARN_LOG_LEVEL</code> LogLevel designates potentially harmful
* situations. */
const LogLevel WARN_LOG_LEVEL = 30000;
/** \var const LogLevel INFO_LOG_LEVEL
* The <code>INFO_LOG_LEVEL</code> LogLevel designates informational
* messages that highlight the progress of the application at
* coarse-grained level. */
const LogLevel INFO_LOG_LEVEL = 20000;
/** \var const LogLevel DEBUG_LOG_LEVEL
* The <code>DEBUG_LOG_LEVEL</code> LogLevel designates fine-grained
* informational events that are most useful to debug an application. */
const LogLevel DEBUG_LOG_LEVEL = 10000;
/** \var const LogLevel TRACE_LOG_LEVEL
* The <code>TRACE_LOG_LEVEL</code> LogLevel is used to "trace" entry
* and exiting of methods. */
const LogLevel TRACE_LOG_LEVEL = 0;
/** \var const LogLevel ALL_LOG_LEVEL
* The <code>ALL_LOG_LEVEL</code> LogLevel is used during configuration to
* turn on all logging. */
const LogLevel ALL_LOG_LEVEL = TRACE_LOG_LEVEL;
/** \var const LogLevel NOT_SET_LOG_LEVEL
* The <code>NOT_SET_LOG_LEVEL</code> LogLevel is used to indicated that
* no particular LogLevel is desired and that the default should be used.
*/
const LogLevel NOT_SET_LOG_LEVEL = -1;
/**
* This method type defined the signature of methods that convert LogLevels
* into strings.
*
* <b>Note:</b> Must return an empty <code>tstring</code> for unrecognized values.
*/
typedef log4cplus::tstring (*LogLevelToStringMethod)(LogLevel);
/**
* This method type defined the signature of methods that convert strings
* into LogLevels.
*
* <b>Note:</b> Must return <code>NOT_SET_LOG_LEVEL</code> for unrecognized values.
*/
typedef LogLevel (*StringToLogLevelMethod)(const log4cplus::tstring&);
/**
* This class is used to "manage" LogLevel definitions. This class is also
* how "derived" LogLevels are created. Here are the steps to creating a
* "derived" LogLevel:
* <ol>
* <li>Create a LogLevel constant (greater than 0)</li>
* <li>Define a string to represent that constant</li>
* <li>Implement a LogLevelToStringMethod method.</li>
* <li>Implement a StringToLogLevelMethod method.</li>
* <li>create a "static initializer" that registers those 2 methods
* with the LogLevelManager singleton.</li>
* </ol>
*/
class LOG4CPLUS_EXPORT LogLevelManager {
public:
LogLevelManager();
~LogLevelManager();
/**
* This method is called by all Layout classes to convert a LogLevel
* into a string.
*
* Note: It traverses the list of <code>LogLevelToStringMethod</code>
* to do this, so all "derived" LogLevels are recognized as well.
*/
log4cplus::tstring toString(LogLevel ll) const;
/**
* This method is called by all classes internally to log4cplus to
* convert a string into a LogLevel.
*
* Note: It traverses the list of <code>StringToLogLevelMethod</code>
* to do this, so all "derived" LogLevels are recognized as well.
*/
LogLevel fromString(const log4cplus::tstring& s) const;
/**
* When creating a "derived" LogLevel, a <code>LogLevelToStringMethod</code>
* should be defined and registered with the LogLevelManager by calling
* this method.
*
* @see pushFromStringMethod
*/
void pushToStringMethod(LogLevelToStringMethod newToString);
/**
* When creating a "derived" LogLevel, a <code>StringToLogLevelMethod</code>
* should be defined and registered with the LogLevelManager by calling
* this method.
*
* @see pushToStringMethod
*/
void pushFromStringMethod(StringToLogLevelMethod newFromString);
private:
// Data
void* toStringMethods;
void* fromStringMethods;
// Disable Copy
LogLevelManager(const LogLevelManager&);
LogLevelManager& operator=(const LogLevelManager&);
};
/**
* Returns the singleton LogLevelManager.
*/
LOG4CPLUS_EXPORT LogLevelManager& getLogLevelManager();
}
#endif // LOG4CPLUS_LOGLEVEL_HEADER_

View File

@ -0,0 +1,318 @@
// Module: Log4CPLUS
// File: ndc.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2010 Tad E. Smith
//
// Licensed 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.
/** @file
* This header defined the NDC class.
*/
#ifndef _LO4CPLUS_NDC_HEADER_
#define _LO4CPLUS_NDC_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/logloguser.h>
#include <map>
#include <stack>
#if (defined(__MWERKS__) && defined(__MACOS__))
using std::size_t;
#endif
namespace log4cplus {
// Forward declarations
class NDC;
struct DiagnosticContext;
typedef std::stack<DiagnosticContext> DiagnosticContextStack;
#if defined (_MSC_VER) || defined (__HP_aCC)
LOG4CPLUS_EXPORT NDC& getNDC();
#endif
/**
* The NDC class implements <i>nested diagnostic contexts</i> as
* defined by Neil Harrison in the article "Patterns for Logging
* Diagnostic Messages" part of the book "<i>Pattern Languages of
* Program Design 3</i>" edited by Martin et al.
*
* A Nested Diagnostic Context, or NDC in short, is an instrument
* to distinguish interleaved log output from different sources. Log
* output is typically interleaved when a server handles multiple
* clients near-simultaneously.
*
* Interleaved log output can still be meaningful if each log entry
* from different contexts had a distinctive stamp. This is where NDCs
* come into play.
*
* <em><b>Note that NDCs are managed on a per thread
* basis</b></em>. NDC operations such as {@link #push}, {@link
* #pop}, {@link #clear}, {@link #getDepth} and {@link #setMaxDepth}
* affect the NDC of the <em>current</em> thread only. NDCs of other
* threads remain unaffected.
*
* For example, a server can build a per client request NDC
* consisting the clients host name and other information contained in
* the the request. <em>Cookies</em> are another source of distinctive
* information. To build an NDC one uses the {@link #push}
* operation. Simply put,
*
* <ul>
* <li>Contexts can be nested.
*
* <li>When entering a context, call <code>getNDC().push()</code>. As a
* side effect, if there is no nested diagnostic context for the
* current thread, this method will create it.
*
* <li>When leaving a context, call <code>getNDC().pop()</code>.
*
* <li><b>When exiting a thread make sure to call {@link #remove
* NDC.remove()}</b>.
* </ul>
*
* There is no penalty for forgetting to match each
* <code>push</code> operation with a corresponding <code>pop</code>,
* except the obvious mismatch between the real application context
* and the context set in the NDC. Use of the {@link NDCContextCreator}
* class can automate this process and make your code exception-safe.
*
* If configured to do so, {@link log4cplus::PatternLayout} and {@link
* log4cplus::TTCCLayout} instances automatically retrieve the nested diagnostic
* context for the current thread without any user intervention.
* Hence, even if a server is serving multiple clients
* simultaneously, the logs emanating from the same code (belonging to
* the same logger) can still be distinguished because each client
* request will have a different NDC tag.
*
* Heavy duty systems should call the {@link #remove} method when
* leaving the run method of a thread. This ensures that the memory
* used by the thread can be freed.
*
* A thread may inherit the nested diagnostic context of another
* (possibly parent) thread using the {@link #inherit inherit}
* method. A thread may obtain a copy of its NDC with the {@link
* #cloneStack cloneStack} method and pass the reference to any other
* thread, in particular to a child.
*/
class LOG4CPLUS_EXPORT NDC : protected log4cplus::helpers::LogLogUser {
public:
/**
* Clear any nested diagnostic information if any. This method is
* useful in cases where the same thread can be potentially used
* over and over in different unrelated contexts.
*
* This method is equivalent to calling the {@link #setMaxDepth}
* method with a zero <code>maxDepth</code> argument.
*/
void clear();
/**
* Clone the diagnostic context for the current thread.
*
* Internally a diagnostic context is represented as a stack. A
* given thread can supply the stack (i.e. diagnostic context) to a
* child thread so that the child can inherit the parent thread's
* diagnostic context.
*
* The child thread uses the {@link #inherit inherit} method to
* inherit the parent's diagnostic context.
*
* @return Stack A clone of the current thread's diagnostic context.
*/
DiagnosticContextStack cloneStack();
/**
* Inherit the diagnostic context of another thread.
*
* The parent thread can obtain a reference to its diagnostic
* context using the {@link #cloneStack} method. It should
* communicate this information to its child so that it may inherit
* the parent's diagnostic context.
*
* The parent's diagnostic context is cloned before being
* inherited. In other words, once inherited, the two diagnostic
* contexts can be managed independently.
*
* @param stack The diagnostic context of the parent thread.
*/
void inherit(const DiagnosticContextStack& stack);
/**
* Used when printing the diagnostic context.
*/
log4cplus::tstring get();
/**
* Get the current nesting depth of this diagnostic context.
*
* @see #setMaxDepth
*/
size_t getDepth();
/**
* Clients should call this method before leaving a diagnostic
* context.
*
* The returned value is the value that was pushed last. If no
* context is available, then the empty string "" is
* returned. If each call to push() is paired with a call to
* pop() (even in presence of thrown exceptions), the last
* pop() call frees the memory used by NDC for this
* thread. Otherwise, remove() must be called at the end of
* the thread to free the memory used by NDC for the thread.
*
* @return String The innermost diagnostic context.
*
* @see NDCContextCreator, remove(), push()
*/
log4cplus::tstring pop();
/**
* Looks at the last diagnostic context at the top of this NDC
* without removing it.
*
* The returned value is the value that was pushed last. If no
* context is available, then the empty string "" is returned.
*
* @return String The innermost diagnostic context.
*/
log4cplus::tstring peek();
/**
* Push new diagnostic context information for the current thread.
*
* The contents of the <code>message</code> parameter is
* determined solely by the client. Each call to push() should
* be paired with a call to pop().
*
* @param message The new diagnostic context information.
*
* @see NDCContextCreator, pop(), remove()
*/
void push(const log4cplus::tstring& message);
/**
* Remove the diagnostic context for this thread.
*
* Each thread that created a diagnostic context by calling
* push() should call this method before exiting. Otherwise,
* the memory used by the thread cannot be reclaimed. It is
* possible to omit this call if and only if each push() call
* is always paired with a pop() call (even in presence of
* thrown exceptions). Then the memory used by NDC will be
* returned by the last pop() call and a call to remove() will
* be no-op.
*/
void remove();
/**
* Set maximum depth of this diagnostic context. If the current
* depth is smaller or equal to <code>maxDepth</code>, then no
* action is taken.
*
* This method is a convenient alternative to multiple {@link
* #pop} calls. Moreover, it is often the case that at the end of
* complex call sequences, the depth of the NDC is
* unpredictable. The <code>setMaxDepth</code> method circumvents
* this problem.
*
* For example, the combination
* <pre>
* void foo() {
* &nbsp; size_t depth = NDC.getDepth();
*
* &nbsp; ... complex sequence of calls
*
* &nbsp; NDC.setMaxDepth(depth);
* }
* </pre>
*
* ensures that between the entry and exit of foo the depth of the
* diagnostic stack is conserved.
*
* <b>Note:</b> Use of the {@link NDCContextCreator} class will solve
* this particular problem.
*
* @see #getDepth
*/
void setMaxDepth(size_t maxDepth);
// Dtor
~NDC();
private:
// Methods
DiagnosticContextStack* getPtr();
// Data
LOG4CPLUS_THREAD_LOCAL_TYPE threadLocal;
// Disallow construction (and copying) except by getNDC()
NDC();
NDC(const NDC&);
NDC& operator=(const NDC&);
// Friends
#if defined (_MSC_VER) || defined (__HP_aCC)
friend LOG4CPLUS_EXPORT NDC& getNDC();
#else
friend NDC& getNDC();
#endif
};
/**
* Return a reference to the singleton object.
*/
LOG4CPLUS_EXPORT NDC& getNDC();
/**
* This is the internal object that is stored on the NDC stack.
*/
struct LOG4CPLUS_EXPORT DiagnosticContext {
// Ctors
DiagnosticContext(const log4cplus::tstring& message, DiagnosticContext *parent);
DiagnosticContext(const log4cplus::tstring& message);
// Data
log4cplus::tstring message; /*!< The message at this context level. */
log4cplus::tstring fullMessage; /*!< The entire message stack. */
};
/**
* This class ensures that a {@link NDC#push} call is always matched with
* a {@link NDC#pop} call even in the face of exceptions.
*/
class LOG4CPLUS_EXPORT NDCContextCreator {
public:
/** Pushes <code>msg</code> onto the NDC stack. */
NDCContextCreator(const log4cplus::tstring& msg);
/** Pops the NDC stack. */
~NDCContextCreator();
};
} // end namespace log4cplus
#endif // _LO4CPLUS_NDC_HEADER_

View File

@ -0,0 +1,81 @@
// Module: Log4CPLUS
// File: nteventlogappender.h
// Created: 4/2003
// Author: Michael CATANZARITI
//
// Copyright 2003-2009 Michael CATANZARITI
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_NT_EVENT_LOG_APPENDER_HEADER_
#define _LOG4CPLUS_NT_EVENT_LOG_APPENDER_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/appender.h>
#if defined(_WIN32)
# if ! defined (LOG4CPLUS_HAVE_NT_EVENT_LOG)
# error "Your platform does not support NT event log."
# else
namespace log4cplus {
/**
* Appends log events to NT EventLog.
*/
class LOG4CPLUS_EXPORT NTEventLogAppender : public Appender {
public:
// ctors
NTEventLogAppender(const log4cplus::tstring& server,
const log4cplus::tstring& log,
const log4cplus::tstring& source);
NTEventLogAppender(const log4cplus::helpers::Properties properties);
// dtor
virtual ~NTEventLogAppender();
// public Methods
virtual void close();
protected:
virtual void append(const spi::InternalLoggingEvent& event);
virtual WORD getEventType(const spi::InternalLoggingEvent& event);
virtual WORD getEventCategory(const spi::InternalLoggingEvent& event);
void init();
/*
* Add this source with appropriate configuration keys to the registry.
*/
void addRegistryInfo();
// Data
log4cplus::tstring server;
log4cplus::tstring log;
log4cplus::tstring source;
HANDLE hEventLog;
SID* pCurrentUserSID;
private:
// Disallow copying of instances of this class
NTEventLogAppender(const NTEventLogAppender&);
NTEventLogAppender& operator=(const NTEventLogAppender&);
};
} // end namespace log4cplus
#endif // LOG4CPLUS_HAVE_NT_EVENT_LOG
#endif // _WIN32
#endif //_LOG4CPLUS_NT_EVENT_LOG_APPENDER_HEADER_

View File

@ -0,0 +1,60 @@
// Module: Log4CPLUS
// File: nullappender.h
// Created: 6/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_NULL_APPENDER_HEADER_
#define _LOG4CPLUS_NULL_APPENDER_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/appender.h>
#include <log4cplus/helpers/property.h>
namespace log4cplus {
/**
* Appends log events to a file.
*/
class LOG4CPLUS_EXPORT NullAppender : public Appender {
public:
// Ctors
NullAppender();
NullAppender(const log4cplus::helpers::Properties& properties);
// Dtor
virtual ~NullAppender();
// Methods
virtual void close();
protected:
virtual void append(const log4cplus::spi::InternalLoggingEvent& event);
private:
// Disallow copying of instances of this class
NullAppender(const NullAppender&);
NullAppender& operator=(const NullAppender&);
};
} // end namespace log4cplus
#endif // _LOG4CPLUS_NULL_APPENDER_HEADER_

View File

@ -0,0 +1,161 @@
// Module: LOG4CPLUS
// File: socketappender.h
// Created: 5/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_SOCKET_APPENDER_HEADER_
#define _LOG4CPLUS_SOCKET_APPENDER_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/appender.h>
#include <log4cplus/helpers/socket.h>
#include <log4cplus/helpers/syncprims.h>
#ifndef UNICODE
# define LOG4CPLUS_MAX_MESSAGE_SIZE (8*1024)
#else
# define LOG4CPLUS_MAX_MESSAGE_SIZE (2*8*1024)
#endif
namespace log4cplus {
/**
* Sends {@link spi::InternalLoggingEvent} objects to a remote a log server.
*
* The SocketAppender has the following properties:
*
* <ul>
*
* <li>Remote logging is non-intrusive as far as the log event
* is concerned. In other words, the event will be logged with
* the same time stamp, NDC, location info as if it were logged
* locally by the client.
*
* <li>SocketAppenders do not use a layout.
*
* <li>Remote logging uses the TCP protocol. Consequently, if
* the server is reachable, then log events will eventually arrive
* at the server.
*
* <li>If the remote server is down, the logging requests are
* simply dropped. However, if and when the server comes back up,
* then event transmission is resumed transparently. This
* transparent reconneciton is performed by a <em>connector</em>
* thread which periodically attempts to connect to the server.
*
* <li>Logging events are automatically <em>buffered</em> by the
* native TCP implementation. This means that if the link to server
* is slow but still faster than the rate of (log) event production
* by the client, the client will not be affected by the slow
* network connection. However, if the network connection is slower
* then the rate of event production, then the client can only
* progress at the network rate. In particular, if the network link
* to the the server is down, the client will be blocked.
*
* <li>On the other hand, if the network link is up, but the server
* is down, the client will not be blocked when making log requests
* but the log events will be lost due to server unavailability.
* </ul>
*
* <h3>Properties</h3>
* <dl>
* <dt><tt>host</tt></dt>
* <dd>Remote host name to connect and send events to.</dd>
*
* <dt><tt>port</tt></dt>
* <dd>Port on remote host to send events to.</dd>
*
* <dt><tt>ServerName</tt></dt>
* <dd>Host name of event's origin prepended to each event.</dd>
*
* </dl>
*/
class LOG4CPLUS_EXPORT SocketAppender : public Appender {
public:
// Ctors
SocketAppender(const log4cplus::tstring& host, int port,
const log4cplus::tstring& serverName = tstring());
SocketAppender(const log4cplus::helpers::Properties & properties);
// Dtor
~SocketAppender();
// Methods
virtual void close();
protected:
void openSocket();
void initConnector ();
virtual void append(const spi::InternalLoggingEvent& event);
// Data
log4cplus::helpers::Socket socket;
log4cplus::tstring host;
int port;
log4cplus::tstring serverName;
#if ! defined (LOG4CPLUS_SINGLE_THREADED)
class LOG4CPLUS_EXPORT ConnectorThread;
friend class ConnectorThread;
class LOG4CPLUS_EXPORT ConnectorThread
: public thread::AbstractThread
, public helpers::LogLogUser
{
public:
ConnectorThread (SocketAppender &);
virtual ~ConnectorThread ();
virtual void run();
void terminate ();
void trigger ();
protected:
SocketAppender & sa;
thread::ManualResetEvent trigger_ev;
bool exit_flag;
};
volatile bool connected;
helpers::SharedObjectPtr<ConnectorThread> connector;
#endif
private:
// Disallow copying of instances of this class
SocketAppender(const SocketAppender&);
SocketAppender& operator=(const SocketAppender&);
};
namespace helpers {
LOG4CPLUS_EXPORT
SocketBuffer convertToBuffer(const log4cplus::spi::InternalLoggingEvent& event,
const log4cplus::tstring& serverName);
LOG4CPLUS_EXPORT
log4cplus::spi::InternalLoggingEvent readFromBuffer(SocketBuffer& buffer);
} // end namespace helpers
} // end namespace log4cplus
#endif // _LOG4CPLUS_SOCKET_APPENDER_HEADER_

View File

@ -0,0 +1,84 @@
// Module: Log4CPLUS
// File: appenderattachable.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2009 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef _LOG4CPLUS_SPI_APPENDER_ATTACHABLE_HEADER_
#define _LOG4CPLUS_SPI_APPENDER_ATTACHABLE_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/appender.h>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/pointer.h>
#include <vector>
namespace log4cplus {
// Forward Declarations
typedef helpers::SharedObjectPtr<Appender> SharedAppenderPtr;
typedef std::vector<log4cplus::SharedAppenderPtr> SharedAppenderPtrList;
namespace spi {
/**
* This Interface is for attaching Appenders to objects.
*/
class LOG4CPLUS_EXPORT AppenderAttachable {
public:
// Methods
/**
* Add an appender.
*/
virtual void addAppender(SharedAppenderPtr newAppender) = 0;
/**
* Get all previously added appenders as an Enumeration.
*/
virtual SharedAppenderPtrList getAllAppenders() = 0;
/**
* Get an appender by name.
*/
virtual SharedAppenderPtr getAppender(const log4cplus::tstring& name) = 0;
/**
* Remove all previously added appenders.
*/
virtual void removeAllAppenders() = 0;
/**
* Remove the appender passed as parameter from the list of appenders.
*/
virtual void removeAppender(SharedAppenderPtr appender) = 0;
/**
* Remove the appender with the name passed as parameter from the
* list of appenders.
*/
virtual void removeAppender(const log4cplus::tstring& name) = 0;
// Dtor
virtual ~AppenderAttachable() = 0;
};
} // end namespace spi
} // end namespace log4cplus
#endif // _LOG4CPLUS_SPI_APPENDER_ATTACHABLE_HEADER_

View File

@ -0,0 +1,185 @@
// Module: Log4CPLUS
// File: factory.h
// Created: 2/2002
// Author: Tad E. Smith
//
//
// Copyright 2002-2010 Tad E. Smith
//
// Licensed 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.
/** @file */
#ifndef LOG4CPLUS_SPI_FACTORY_HEADER_
#define LOG4CPLUS_SPI_FACTORY_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/appender.h>
#include <log4cplus/layout.h>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/property.h>
#include <log4cplus/helpers/threads.h>
#include <log4cplus/spi/filter.h>
#include <log4cplus/spi/objectregistry.h>
#include <map>
#include <memory>
#include <vector>
namespace log4cplus {
namespace spi {
/**
* This is the base class for all factories.
*/
class LOG4CPLUS_EXPORT BaseFactory {
public:
virtual ~BaseFactory() = 0;
/**
* Returns the typename of the objects this factory creates.
*/
virtual log4cplus::tstring getTypeName() = 0;
};
/**
* This abstract class defines the "Factory" interface to create "Appender"
* objects.
*/
class LOG4CPLUS_EXPORT AppenderFactory : public BaseFactory {
public:
typedef Appender ProductType;
typedef SharedAppenderPtr ProductPtr;
AppenderFactory();
virtual ~AppenderFactory() = 0;
/**
* Create an "Appender" object.
*/
virtual SharedAppenderPtr createObject(const log4cplus::helpers::Properties& props) = 0;
};
/**
* This abstract class defines the "Factory" interface to create "Layout"
* objects.
*/
class LOG4CPLUS_EXPORT LayoutFactory : public BaseFactory {
public:
typedef Layout ProductType;
typedef std::auto_ptr<Layout> ProductPtr;
LayoutFactory();
virtual ~LayoutFactory() = 0;
/**
* Create a "Layout" object.
*/
virtual std::auto_ptr<Layout> createObject(const log4cplus::helpers::Properties& props) = 0;
};
/**
* This abstract class defines the "Factory" interface to create "Appender"
* objects.
*/
class LOG4CPLUS_EXPORT FilterFactory : public BaseFactory {
public:
typedef Filter ProductType;
typedef FilterPtr ProductPtr;
FilterFactory();
virtual ~FilterFactory() = 0;
/**
* Create a "Filter" object.
*/
virtual FilterPtr createObject(const log4cplus::helpers::Properties& props) = 0;
};
/**
* This template class is used as a "Factory Registry". Objects are
* "entered" into the registry with a "name" using the
* <code>put()</code> method. (The registry then owns the object.)
* These object can then be retrieved using the <code>get()</code>
* method.
*
* <b>Note:</b> This class is Thread-safe.
*/
template<class T>
class LOG4CPLUS_EXPORT FactoryRegistry : ObjectRegistryBase {
public:
typedef T product_type;
virtual ~FactoryRegistry() {
clear();
}
// public methods
/**
* Used to enter an object into the registry. (The registry now
* owns <code>object</code>.)
*/
bool put(std::auto_ptr<T> object) {
bool putValResult = putVal(object->getTypeName(), object.get());
object.release();
return putValResult;
}
/**
* Used to retrieve an object from the registry. (The registry
* owns the returned pointer.)
*/
T* get(const log4cplus::tstring& name) const {
return static_cast<T*>(getVal(name));
}
protected:
virtual void deleteObject(void *object) const {
delete static_cast<T*>(object);
}
};
typedef FactoryRegistry<AppenderFactory> AppenderFactoryRegistry;
typedef FactoryRegistry<LayoutFactory> LayoutFactoryRegistry;
typedef FactoryRegistry<FilterFactory> FilterFactoryRegistry;
/**
* Returns the "singleton" <code>AppenderFactoryRegistry</code>.
*/
LOG4CPLUS_EXPORT AppenderFactoryRegistry& getAppenderFactoryRegistry();
/**
* Returns the "singleton" <code>LayoutFactoryRegistry</code>.
*/
LOG4CPLUS_EXPORT LayoutFactoryRegistry& getLayoutFactoryRegistry();
/**
* Returns the "singleton" <code>FilterFactoryRegistry</code>.
*/
LOG4CPLUS_EXPORT FilterFactoryRegistry& getFilterFactoryRegistry();
}
}
#endif // LOG4CPLUS_SPI_FACTORY_HEADER_

View File

@ -0,0 +1,273 @@
// Module: Log4CPLUS
// File: filter.h
// Created: 5/2003
// Author: Tad E. Smith
//
//
// Copyright 1999-2010 Tad E. Smith
//
// Licensed 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.
/** @file
* This header defines Filter and all of it's subclasses. */
#ifndef LOG4CPLUS_SPI_FILTER_HEADER_
#define LOG4CPLUS_SPI_FILTER_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/helpers/pointer.h>
#include <log4cplus/helpers/property.h>
#include <log4cplus/spi/loggingevent.h>
namespace log4cplus {
namespace spi {
enum FilterResult { DENY, /**< The log event must be dropped immediately
* without consulting with the remaining
* filters, if any, in the chain. */
NEUTRAL, /**< This filter is neutral with respect to
* the log event; the remaining filters, if
* if any, should be consulted for a final
* decision. */
ACCEPT /**< The log event must be logged immediately
* without consulting with the remaining
* filters, if any, in the chain. */
};
// Forward Declarations
class Filter;
/**
* This method is used to filter an InternalLoggingEvent.
*
* Note: <code>filter</code> can be NULL.
*/
LOG4CPLUS_EXPORT FilterResult checkFilter(const Filter* filter,
const InternalLoggingEvent& event);
typedef helpers::SharedObjectPtr<Filter> FilterPtr;
/**
* Users should extend this class to implement customized logging
* event filtering. Note that the {@link Logger} and {@link
* Appender} classes have built-in filtering rules. It is suggested
* that you first use and understand the built-in rules before rushing
* to write your own custom filters.
*
* This abstract class assumes and also imposes that filters be
* organized in a linear chain. The {@link #decide
* decide(LoggingEvent)} method of each filter is called sequentially,
* in the order of their addition to the chain.
*
* If the value {@link #DENY} is returned, then the log event is
* dropped immediately without consulting with the remaining
* filters.
*
* If the value {@link #NEUTRAL} is returned, then the next filter
* in the chain is consulted. If there are no more filters in the
* chain, then the log event is logged. Thus, in the presence of no
* filters, the default behaviour is to log all logging events.
*
* If the value {@link #ACCEPT} is returned, then the log
* event is logged without consulting the remaining filters.
*
* The philosophy of log4cplus filters is largely inspired from the
* Linux ipchains.
*/
class LOG4CPLUS_EXPORT Filter
: public virtual log4cplus::helpers::SharedObject
{
public:
// ctor and dtor
Filter();
virtual ~Filter();
// Methods
/**
* Appends <code>filter</code> to the end of this filter chain.
*/
void appendFilter(FilterPtr filter);
/**
* If the decision is <code>DENY</code>, then the event will be
* dropped. If the decision is <code>NEUTRAL</code>, then the next
* filter, if any, will be invoked. If the decision is ACCEPT then
* the event will be logged without consulting with other filters in
* the chain.
*
* @param event The LoggingEvent to decide upon.
* @return The decision of the filter.
*/
virtual FilterResult decide(const InternalLoggingEvent& event) const = 0;
// Data
/**
* Points to the next filter in the filter chain.
*/
FilterPtr next;
};
/**
* This filter drops all logging events.
*
* You can add this filter to the end of a filter chain to
* switch from the default "accept all unless instructed otherwise"
* filtering behaviour to a "deny all unless instructed otherwise"
* behaviour.
*/
class LOG4CPLUS_EXPORT DenyAllFilter : public Filter {
public:
DenyAllFilter ();
DenyAllFilter (const log4cplus::helpers::Properties&);
/**
* Always returns the {@link #DENY} regardless of the
* {@link InternalLoggingEvent} parameter.
*/
virtual FilterResult decide(const InternalLoggingEvent& event) const;
};
/**
* This is a very simple filter based on LogLevel matching.
*
* The filter admits two options <b>LogLevelToMatch</b> and
* <b>AcceptOnMatch</b>. If there is an exact match between the value
* of the LogLevelToMatch option and the LogLevel of the {@link
* spi::InternalLoggingEvent}, then the {@link #decide} method returns
* {@link #ACCEPT} in case the <b>AcceptOnMatch</b> option value is set
* to <code>true</code>, if it is <code>false</code> then {@link #DENY}
* is returned. If there is no match, {@link #NEUTRAL