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

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} is returned.
*/
class LOG4CPLUS_EXPORT LogLevelMatchFilter : public Filter {
public:
LogLevelMatchFilter();
LogLevelMatchFilter(const log4cplus::helpers::Properties& p);
/**
* Return the decision of this filter.
*
* Returns {@link #NEUTRAL} if the <b>LogLevelToMatch</b>
* option is not set or if there is no match. Otherwise, if
* there is a match, then the returned decision is {@link #ACCEPT}
* if the <b>AcceptOnMatch</b> property is set to <code>true</code>.
* The returned decision is {@link #DENY} if the <b>AcceptOnMatch</b>
* property is set to <code>false</code>.
*/
virtual FilterResult decide(const InternalLoggingEvent& event) const;
private:
// Methods
void init();
// Data
/** Do we return ACCEPT when a match occurs. Default is <code>true</code>. */
bool acceptOnMatch;
LogLevel logLevelToMatch;
};
/**
* This is a very simple filter based on LogLevel matching, which can be
* used to reject messages with LogLevels outside a certain range.
*
* The filter admits three options <b>LogLevelMin</b>, <b>LogLevelMax</b>
* and <b>AcceptOnMatch</b>.
*
* If the LogLevel of the Logging event is not between Min and Max
* (inclusive), then {@link #DENY} is returned.
*
* If the Logging event LogLevel is within the specified range, then if
* <b>AcceptOnMatch</b> is true, {@link #ACCEPT} is returned, and if
* <b>AcceptOnMatch</b> is false, {@link #NEUTRAL} is returned.
*
* If <code>LogLevelMin</code> is not defined, then there is no
* minimum acceptable LogLevel (ie a LogLevel is never rejected for
* being too "low"/unimportant). If <code>LogLevelMax</code> is not
* defined, then there is no maximum acceptable LogLevel (ie a
* LogLevel is never rejected for beeing too "high"/important).
*
* Refer to the {@link
* Appender#setThreshold setThreshold} method
* available to <code>all</code> appenders for a more convenient way to
* filter out events by LogLevel.
*/
class LOG4CPLUS_EXPORT LogLevelRangeFilter : public Filter {
public:
// ctors
LogLevelRangeFilter();
LogLevelRangeFilter(const log4cplus::helpers::Properties& p);
/**
* Return the decision of this filter.
*/
virtual FilterResult decide(const InternalLoggingEvent& event) const;
private:
// Methods
void init();
// Data
/** Do we return ACCEPT when a match occurs. Default is <code>true</code>. */
bool acceptOnMatch;
LogLevel logLevelMin;
LogLevel logLevelMax;
};
/**
* This is a very simple filter based on string matching.
*
* The filter admits two options <b>StringToMatch</b> and
* <b>AcceptOnMatch</b>. If there is a match between the value of the
* StringToMatch option and the message of the Logging event,
* then the {@link #decide} method returns {@link #ACCEPT} if
* the <b>AcceptOnMatch</b> option value is true, if it is false then
* {@link #DENY} is returned. If there is no match, {@link #NEUTRAL}
* is returned.
*/
class LOG4CPLUS_EXPORT StringMatchFilter : public Filter {
public:
// ctors
StringMatchFilter();
StringMatchFilter(const log4cplus::helpers::Properties& p);
/**
* Returns {@link #NEUTRAL} is there is no string match.
*/
virtual FilterResult decide(const InternalLoggingEvent& event) const;
private:
// Methods
void init();
// Data
/** Do we return ACCEPT when a match occurs. Default is <code>true</code>. */
bool acceptOnMatch;
log4cplus::tstring stringToMatch;
};
} // end namespace spi
} // end namespace log4cplus
#endif /* LOG4CPLUS_SPI_FILTER_HEADER_ */

View File

@ -0,0 +1,55 @@
// Module: Log4CPLUS
// File: loggerfactory.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_LOGGER_FACTORY_HEADER
#define _LOG4CPLUS_SPI_LOGGER_FACTORY_HEADER
#include <log4cplus/config.hxx>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/pointer.h>
namespace log4cplus {
// Forward Declarations
class Logger;
class Hierarchy;
namespace spi {
/**
* Implement this interface to create new instances of Logger or
* a sub-class of Logger.
*/
class LOG4CPLUS_EXPORT LoggerFactory {
public:
/**
* Creates a new <code>Logger</code> object.
*/
virtual Logger makeNewLoggerInstance(const log4cplus::tstring& name,
Hierarchy& h) = 0;
virtual ~LoggerFactory() = 0;
};
} // end namespace spi
} // end namespace log4cplus
#endif // _LOG4CPLUS_SPI_LOGGER_FACTORY_HEADER

View File

@ -0,0 +1,209 @@
// Module: Log4CPLUS
// File: loggerimpl.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_LOGGER_HEADER_
#define _LOG4CPLUS_SPI_LOGGER_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/appenderattachableimpl.h>
#include <log4cplus/helpers/pointer.h>
#include <log4cplus/spi/loggerfactory.h>
#include <memory>
#include <vector>
namespace log4cplus {
class DefaultLoggerFactory;
namespace spi {
/**
* 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 LoggerImpl
: public virtual log4cplus::helpers::SharedObject,
public log4cplus::helpers::AppenderAttachableImpl
{
public:
typedef helpers::SharedObjectPtr<LoggerImpl> SharedLoggerImplPtr;
// Methods
/**
* 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.
*/
virtual void callAppenders(const InternalLoggingEvent& event);
/**
* Close all attached appenders implementing the AppenderAttachable
* interface.
*/
virtual void closeNestedAppenders();
/**
* 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>.
*/
virtual bool isEnabledFor(LogLevel ll) const;
/**
* This generic form is intended to be used by wrappers.
*/
virtual void log(LogLevel ll, const log4cplus::tstring& message,
const char* file=NULL, int line=-1);
/**
* 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.
*/
virtual LogLevel getChainedLogLevel() const;
/**
* Returns the assigned LogLevel, if any, for this Logger.
*
* @return LogLevel - the assigned LogLevel.
*/
LogLevel getLogLevel() const { return this->ll; }
/**
* Set the LogLevel of this Logger.
*/
void setLogLevel(LogLevel _ll) { this->ll = _ll; }
/**
* Return the the {@link Hierarchy} where this <code>Logger</code>
* instance is attached.
*/
virtual Hierarchy& getHierarchy() const;
/**
* Return the logger name.
*/
log4cplus::tstring getName() const { return name; }
/**
* Get the additivity flag for this Logger instance.
*/
bool getAdditivity() const;
/**
* Set the additivity flag for this Logger instance.
*/
void setAdditivity(bool additive);
virtual ~LoggerImpl();
protected:
// Ctors
/**
* This constructor created a new <code>Logger</code> instance and
* sets its name.
*
* It is intended to be used by sub-classes only. You should not
* create loggers directly.
*
* @param name The name of the logger.
* @param h Hierarchy
*/
LoggerImpl(const log4cplus::tstring& name, Hierarchy& h);
// Methods
/**
* This method creates a new logging event and logs the event
* without further checks.
*/
virtual void forcedLog(LogLevel ll,
const log4cplus::tstring& message,
const char* file=NULL,
int line=-1);
// Data
/** The name of this logger */
log4cplus::tstring name;
/**
* The assigned LogLevel of this logger.
*/
LogLevel ll;
/**
* The parent of this logger. All loggers have at least one
* ancestor which is the root logger.
*/
SharedLoggerImplPtr parent;
/**
* Additivity is set to true by default, that is children inherit
* the appenders of their ancestors by default. If this variable is
* set to <code>false</code> then the appenders found in the
* ancestors of this logger are not used. However, the children
* of this logger will inherit its appenders, unless the children
* have their additivity flag set to <code>false</code> too. See
* the user manual for more details.
*/
bool additive;
private:
// Data
/** Loggers need to know what Hierarchy they are in. */
Hierarchy& hierarchy;
// Disallow copying of instances of this class
LoggerImpl(const LoggerImpl&);
LoggerImpl& operator=(const LoggerImpl&);
// Friends
friend class log4cplus::Logger;
friend class log4cplus::DefaultLoggerFactory;
friend class log4cplus::Hierarchy;
};
typedef LoggerImpl::SharedLoggerImplPtr SharedLoggerImplPtr;
} // end namespace spi
} // end namespace log4cplus
#endif // _LOG4CPLUS_SPI_LOGGER_HEADER_

View File

@ -0,0 +1,198 @@
// Module: Log4CPLUS
// File: loggingevent.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_INTERNAL_LOGGING_EVENT_HEADER_
#define _LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/loglevel.h>
#include <log4cplus/ndc.h>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/timehelper.h>
#include <log4cplus/helpers/threads.h>
namespace log4cplus {
namespace spi {
/**
* The internal representation of logging events. When an affirmative
* decision is made to log then a <code>InternalLoggingEvent</code>
* instance is created. This instance is passed around to the
* different log4cplus components.
*
* This class is of concern to those wishing to extend log4cplus.
*/
class LOG4CPLUS_EXPORT InternalLoggingEvent {
public:
// Ctors
/**
* Instantiate a LoggingEvent from the supplied parameters.
*
* @param logger The logger of this event.
* @param ll_ The LogLevel of this event.
* @param message_ The message of this event.
* @param filename Name of file where this event has occurred,
* can be NULL.
* @param line_ Line number in file specified by
* the <code>filename</code> parameter.
*/
InternalLoggingEvent(const log4cplus::tstring& logger,
LogLevel ll_,
const log4cplus::tstring& message_,
const char* filename,
int line_)
: message(message_),
loggerName(logger),
ll(ll_),
ndc(),
thread(),
timestamp(log4cplus::helpers::Time::gettimeofday()),
file( ( filename
? LOG4CPLUS_C_STR_TO_TSTRING(filename)
: log4cplus::tstring()) ),
line(line_),
threadCached(false),
ndcCached(false)
{
}
InternalLoggingEvent(const log4cplus::tstring& logger,
LogLevel ll_,
const log4cplus::tstring& ndc_,
const log4cplus::tstring& message_,
const log4cplus::tstring& thread_,
log4cplus::helpers::Time time,
const log4cplus::tstring& file_,
int line_)
: message(message_),
loggerName(logger),
ll(ll_),
ndc(ndc_),
thread(thread_),
timestamp(time),
file(file_),
line(line_),
threadCached(true),
ndcCached(true)
{
}
InternalLoggingEvent(const log4cplus::spi::InternalLoggingEvent& rhs)
: message(rhs.getMessage()),
loggerName(rhs.getLoggerName()),
ll(rhs.getLogLevel()),
ndc(rhs.getNDC()),
thread(rhs.getThread()),
timestamp(rhs.getTimestamp()),
file(rhs.getFile()),
line(rhs.getLine()),
threadCached(true),
ndcCached(true)
{
}
virtual ~InternalLoggingEvent();
// public virtual methods
/** The application supplied message of logging event. */
virtual const log4cplus::tstring& getMessage() const;
/** Returns the 'type' of InternalLoggingEvent. Derived classes
* should override this method. (NOTE: Values <= 1000 are
* reserved for log4cplus and should not be used.)
*/
virtual unsigned int getType() const;
/** Returns a copy of this object. Derived classes
* should override this method.
*/
virtual std::auto_ptr<InternalLoggingEvent> clone() const;
// public methods
/** The logger of the logging event. It is set by
* the LoggingEvent constructor.
*/
const log4cplus::tstring& getLoggerName() const { return loggerName; }
/** LogLevel of logging event. */
LogLevel getLogLevel() const { return ll; }
/** The nested diagnostic context (NDC) of logging event. */
const log4cplus::tstring& getNDC() const {
if(!ndcCached) {
ndc = log4cplus::getNDC().get();
ndcCached = true;
}
return ndc;
}
/** The name of thread in which this logging event was generated. */
const log4cplus::tstring& getThread() const {
if(!threadCached) {
thread = LOG4CPLUS_GET_CURRENT_THREAD_NAME;
threadCached = true;
}
return thread;
}
/** The number of milliseconds elapsed from 1/1/1970 until logging event
* was created. */
const log4cplus::helpers::Time& getTimestamp() const { return timestamp; }
/** The is the file where this log statement was written */
const log4cplus::tstring& getFile() const { return file; }
/** The is the line where this log statement was written */
int getLine() const { return line; }
// public operators
log4cplus::spi::InternalLoggingEvent&
operator=(const log4cplus::spi::InternalLoggingEvent& rhs);
// static methods
static unsigned int getDefaultType();
protected:
// Data
log4cplus::tstring message;
private:
log4cplus::tstring loggerName;
LogLevel ll;
mutable log4cplus::tstring ndc;
mutable log4cplus::tstring thread;
log4cplus::helpers::Time timestamp;
log4cplus::tstring file;
int line;
/** Indicates whether or not the Threadname has been retrieved. */
mutable bool threadCached;
/** Indicates whether or not the NDC has been retrieved. */
mutable bool ndcCached;
};
} // end namespace spi
} // end namespace log4cplus
#endif // _LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_

View File

@ -0,0 +1,96 @@
// Module: Log4CPLUS
// File: objectregistry.h
// Created: 3/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_SPI_OBJECT_REGISTRY_HEADER_
#define LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/threads.h>
#include <map>
#include <memory>
#include <vector>
namespace log4cplus {
namespace spi {
/**
* This is the base class used to implement the functionality required
* by the ObjectRegistry template class.
*/
class LOG4CPLUS_EXPORT ObjectRegistryBase {
public:
// public methods
/**
* Tests to see whether or not an object is bound in the
* registry as <code>name</code>.
*/
bool exists(const log4cplus::tstring& name) const;
/**
* Returns the names of all registered objects.
*/
std::vector<log4cplus::tstring> getAllNames() const;
protected:
// Ctor and Dtor
ObjectRegistryBase();
virtual ~ObjectRegistryBase();
// protected methods
/**
* Used to enter an object into the registry. (The registry now
* owns <code>object</code>.)
*/
bool putVal(const log4cplus::tstring& name, void* object);
/**
* Used to retrieve an object from the registry. (The registry
* owns the returned pointer.)
*/
void* getVal(const log4cplus::tstring& name) const;
/**
* Deletes <code>object</code>.
*/
virtual void deleteObject(void *object) const = 0;
/**
* Deletes all objects from this registry.
*/
virtual void clear();
// Types
typedef std::map<log4cplus::tstring, void*> ObjectMap;
// Data
LOG4CPLUS_MUTEX_PTR_DECLARE mutex;
ObjectMap data;
};
}
}
#endif // LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_

View File

@ -0,0 +1,70 @@
// Module: Log4CPLUS
// File: rootlogger.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_ROOT_LOGGER_HEADER_
#define _LOG4CPLUS_SPI_ROOT_LOGGER_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/helpers/loglog.h>
#include <log4cplus/spi/loggerimpl.h>
namespace log4cplus {
namespace spi {
/**
* RootLogger sits at the top of the logger hierachy. It is a
* regular logger except that it provides several guarantees.
*
* First, it cannot be assigned a <code>NOT_SET_LOG_LEVEL</code>
* LogLevel. Second, since root logger cannot have a parent, the
* getChainedLogLevel method always returns the value of the
* ll field without walking the hierarchy.
*/
class LOG4CPLUS_EXPORT RootLogger : public LoggerImpl {
public:
// Ctors
/**
* The root logger names itself as "root". However, the root
* logger cannot be retrieved by name.
*/
RootLogger(Hierarchy& h, LogLevel ll);
// Methods
/**
* Return the assigned LogLevel value without walking the logger
* hierarchy.
*/
virtual LogLevel getChainedLogLevel() const;
/**
* Setting a NOT_SET_LOG_LEVEL value to the LogLevel of the root logger
* may have catastrophic results. We prevent this here.
*/
void setLogLevel(LogLevel ll);
};
} // end namespace spi
} // end namespace log4cplus
#endif // _LOG4CPLUS_SPI_ROOT_LOGGER_HEADER_

View File

@ -0,0 +1,55 @@
// Module: Log4CPLUS
// File: streams.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_STREAMS_HEADER_
#define LOG4CPLUS_STREAMS_HEADER_
#include <log4cplus/config.hxx>
#include <log4cplus/tstring.h>
#include <iostream>
#include <sstream>
#define LOG4CPLUS_STREAM_NAMESPACE std
#ifdef UNICODE
namespace log4cplus {
typedef LOG4CPLUS_STREAM_NAMESPACE::wostream tostream;
typedef LOG4CPLUS_STREAM_NAMESPACE::wistream tistream;
typedef LOG4CPLUS_STREAM_NAMESPACE::wostringstream tostringstream;
static tostream &tcout = LOG4CPLUS_STREAM_NAMESPACE::wcout;
static tostream &tcerr = LOG4CPLUS_STREAM_NAMESPACE::wcerr;
}
LOG4CPLUS_EXPORT log4cplus::tostream& operator <<(log4cplus::tostream&, const char* psz );
#else
namespace log4cplus {
typedef LOG4CPLUS_STREAM_NAMESPACE::ostream tostream;
typedef LOG4CPLUS_STREAM_NAMESPACE::istream tistream;
static tostream &tcout = LOG4CPLUS_STREAM_NAMESPACE::cout;
static tostream &tcerr = LOG4CPLUS_STREAM_NAMESPACE::cerr;
typedef LOG4CPLUS_STREAM_NAMESPACE::ostringstream tostringstream;
}
#endif // UNICODE
#endif // LOG4CPLUS_STREAMS_HEADER_

View File

@ -0,0 +1,82 @@
// Module: Log4CPLUS
// File: syslogappender.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_SYSLOG_APPENDER_HEADER_
#define _LOG4CPLUS_SYSLOG_APPENDER_HEADER_
#include <log4cplus/config.hxx>
#if defined(LOG4CPLUS_HAVE_SYSLOG_H) && !defined(_WIN32)
#include <log4cplus/appender.h>
namespace log4cplus {
/**
* Appends log events to a file.
*
* <h3>Properties</h3>
* <dl>
* <dt><tt>ident</tt></dt>
* <dd>First argument to <code>openlog()</code>, a string that
* will be prepended to every message.</dd>
*
* <dt><tt>facility</tt></dt>
* <dd>Facility is used in combination with syslog level in first
* argument to syslog(). It can be one of the supported facility
* names (case insensitive), e.g. auth, cron, kern, mail, news
* etc.</dd>
* </dl>
*/
class LOG4CPLUS_EXPORT SysLogAppender : public Appender {
public:
// Ctors
SysLogAppender(const tstring& ident);
SysLogAppender(const log4cplus::helpers::Properties & properties);
// Dtor
virtual ~SysLogAppender();
// Methods
virtual void close();
protected:
virtual int getSysLogLevel(const LogLevel& ll) const;
virtual void append(const spi::InternalLoggingEvent& event);
// Data
tstring ident;
int facility;
private:
// Disallow copying of instances of this class
SysLogAppender(const SysLogAppender&);
SysLogAppender& operator=(const SysLogAppender&);
std::string identStr;
};
} // end namespace log4cplus
#endif // defined(HAVE_SYSLOG_H)
#endif // _LOG4CPLUS_SYSLOG_APPENDER_HEADER_

View File

@ -0,0 +1,85 @@
// Module: Log4CPLUS
// File: tstring.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_TSTRING_HEADER_
#define LOG4CPLUS_TSTRING_HEADER_
#include <log4cplus/config.hxx>
#include <string>
#ifdef UNICODE
# ifdef LOG4CPLUS_WORKING_LOCALE
# include <locale>
# endif // LOG4CPLUS_WORKING_LOCALE
# define LOG4CPLUS_TEXT2(STRING) L##STRING
#else
# define LOG4CPLUS_TEXT2(STRING) STRING
#endif // UNICODE
#define LOG4CPLUS_TEXT(STRING) LOG4CPLUS_TEXT2(STRING)
#ifdef UNICODE
namespace log4cplus {
typedef wchar_t tchar;
typedef std::wstring tstring;
namespace helpers {
#ifdef LOG4CPLUS_WORKING_LOCALE
LOG4CPLUS_EXPORT std::string tostring(const std::wstring&,
std::locale const & = std::locale ());
LOG4CPLUS_EXPORT std::string tostring (wchar_t const *,
std::locale const & = std::locale ());
LOG4CPLUS_EXPORT std::wstring towstring(const std::string&,
std::locale const & = std::locale ());
LOG4CPLUS_EXPORT std::wstring towstring(char const *,
std::locale const & = std::locale ());
#else // LOG4CPLUS_WORKING_LOCALE
LOG4CPLUS_EXPORT std::string tostring(const std::wstring&);
LOG4CPLUS_EXPORT std::string tostring(wchar_t const *);
LOG4CPLUS_EXPORT std::wstring towstring(const std::string&);
LOG4CPLUS_EXPORT std::wstring towstring(char const *);
#endif // LOG4CPLUS_WORKING_LOCALE
}
}
#define LOG4CPLUS_C_STR_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING)
#define LOG4CPLUS_STRING_TO_TSTRING(STRING) log4cplus::helpers::towstring(STRING)
#define LOG4CPLUS_TSTRING_TO_STRING(STRING) log4cplus::helpers::tostring(STRING)
#else // UNICODE
namespace log4cplus {
typedef char tchar;
typedef std::string tstring;
}
#define LOG4CPLUS_C_STR_TO_TSTRING(STRING) std::string(STRING)
#define LOG4CPLUS_STRING_TO_TSTRING(STRING) STRING
#define LOG4CPLUS_TSTRING_TO_STRING(STRING) STRING
#endif // UNICODE
#endif // LOG4CPLUS_TSTRING_HEADER_

View File

@ -0,0 +1,49 @@
// Copyright (C) 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.
#if ! defined (LOG4CPLUS_VERSION_H)
#define LOG4CPLUS_VERSION_H
#include <log4cplus/config.hxx>
#define LOG4CPLUS_MAKE_VERSION(major, minor, point) \
(major * 1000 * 1000u + minor * 1000u + point)
#define LOG4CPLUS_MAKE_VERSION_STR(major, minor, point) \
#major "." #minor "." #point
#define LOG4CPLUS_VERSION LOG4CPLUS_MAKE_VERSION(1, 0, 4)
#define LOG4CPLUS_VERSION_STR LOG4CPLUS_MAKE_VERSION_STR(1, 0, 4)
namespace log4cplus
{
extern LOG4CPLUS_EXPORT unsigned const version;
extern LOG4CPLUS_EXPORT char const versionStr[];
}
#endif

View File

@ -0,0 +1,77 @@
// 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.
#ifndef LOG4CPLUS_WIN32CONSOLEAPPENDER_H
#define LOG4CPLUS_WIN32CONSOLEAPPENDER_H
#include <log4cplus/config.hxx>
#if defined(_WIN32) && defined (LOG4CPLUS_HAVE_WIN32_CONSOLE)
#include <log4cplus/appender.h>
#include <log4cplus/helpers/property.h>
namespace log4cplus
{
/**
* Prints events to Win32 console.
*
* <h3>Properties</h3>
* <dl>
* <dt><tt>AllocConsole</tt></dt>
* <dd>This boolean property specifies whether or not this appender
* will try to allocate new console using the
* <code>AllocConsole()</code> Win32 function.</dd>
*
* </dl>
*/
class LOG4CPLUS_EXPORT Win32ConsoleAppender
: public Appender
{
public:
explicit Win32ConsoleAppender (bool allocConsole = true);
Win32ConsoleAppender (helpers::Properties const & properties);
virtual ~Win32ConsoleAppender ();
virtual void close ();
protected:
virtual void append (spi::InternalLoggingEvent const &);
void write_handle (HANDLE, tchar const *, size_t);
void write_console (HANDLE, tchar const *, size_t);
bool alloc_console;
private:
Win32ConsoleAppender (Win32ConsoleAppender const &);
Win32ConsoleAppender & operator = (Win32ConsoleAppender const &);
};
} // namespace log4cplus
#endif
#endif // LOG4CPLUS_WIN32CONSOLEAPPENDER_H

View File

@ -0,0 +1,65 @@
// Module: Log4CPLUS
// File: win32debugappender.h
// Created: 12/2003
// Author: Eduardo Francos, Odalio SARL
//
//
// Copyright 2003-2010 Odalio SARL
//
// 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_WIN32DEBUG_APPENDER_HEADER_
#define _LOG4CPLUS_WIN32DEBUG_APPENDER_HEADER_
#include <log4cplus/config.hxx>
#if defined (LOG4CPLUS_HAVE_WIN32_CONSOLE)
#include <log4cplus/appender.h>
#include <log4cplus/helpers/property.h>
namespace log4cplus {
/**
* Prints log events using OutputDebugString().
*/
class LOG4CPLUS_EXPORT Win32DebugAppender
: public Appender
{
public:
// Ctors
Win32DebugAppender();
Win32DebugAppender(const log4cplus::helpers::Properties& properties);
// Dtor
virtual ~Win32DebugAppender();
// Methods
virtual void close();
protected:
virtual void append(const log4cplus::spi::InternalLoggingEvent& event);
private:
// Disallow copying of instances of this class
Win32DebugAppender(const Win32DebugAppender&);
Win32DebugAppender& operator=(const Win32DebugAppender&);
};
} // end namespace log4cplus
#endif // LOG4CPLUS_HAVE_WIN32_CONSOLE
#endif // _LOG4CPLUS_WIN32DEBUG_APPENDER_HEADER_