code
stringlengths
1
2.06M
language
stringclasses
1 value
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_TRANSFORM_H #define _LOG4CXX_HELPERS_TRANSFORM_H #include <log4cxx/logstring.h> namespace log4cxx { namespace helpers { /** Utility class for transforming strings. */ class LOG4CXX_EXPORT Transform { public: /** * This method takes a string which may contain HTML tags (ie, * &lt;b&gt;, &lt;table&gt;, etc) and replaces any '<' and '>' * characters with respective predefined entity references. * * @param buf output stream where to write the modified string. * @param input The text to be converted. * @return The input string with the characters '<' and '>' replaced with * &amp;lt; and &amp;gt; respectively. * */ static void appendEscapingTags( LogString& buf, const LogString& input); /** * Ensures that embeded CDEnd strings (]]>) are handled properly * within message, NDC and throwable tag text. * * @param buf output stream holding the XML data to this point. The * initial CDStart (<![CDATA[) and final CDEnd (]]>) of the CDATA * section are the responsibility of the calling method. * @param input The String that is inserted into an existing CDATA * Section within buf. */ static void appendEscapingCDATA( LogString& buf, const LogString& input); }; // class Transform } // namespace helpers } //namespace log4cxx #endif // _LOG4CXX_HELPERS_TRANSFORM_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_SOCKET_H #define _LOG4CXX_HELPERS_SOCKET_H extern "C" { struct apr_socket_t; } #include <log4cxx/helpers/inetaddress.h> #include <log4cxx/helpers/pool.h> namespace log4cxx { namespace helpers { class ByteBuffer; /** <p>This class implements client sockets (also called just "sockets"). A socket is an endpoint for communication between two machines. <p>The actual work of the socket is performed by an instance of the SocketImpl class. An application, by changing the socket factory that creates the socket implementation, can configure itself to create sockets appropriate to the local firewall. */ class LOG4CXX_EXPORT Socket : public helpers::ObjectImpl { public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(Socket) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(Socket) END_LOG4CXX_CAST_MAP() /** Creates a stream socket and connects it to the specified port number at the specified IP address. */ Socket(InetAddressPtr& address, int port); Socket(apr_socket_t* socket, apr_pool_t* pool); ~Socket(); size_t write(ByteBuffer&); /** Closes this socket. */ void close(); /** Returns the value of this socket's address field. */ InetAddressPtr getInetAddress() const; /** Returns the value of this socket's port field. */ int getPort() const; private: Socket(const Socket&); Socket& operator=(const Socket&); Pool pool; apr_socket_t* socket; /** The IP address of the remote end of this socket. */ InetAddressPtr address; /** The port number on the remote host to which this socket is connected. */ int port; }; LOG4CXX_PTR_DEF(Socket); } // namespace helpers } // namespace log4cxx #endif // _LOG4CXX_HELPERS_SOCKET_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_EXCEPTION_H #define _LOG4CXX_HELPERS_EXCEPTION_H #include <exception> #include <log4cxx/log4cxx.h> #include <log4cxx/logstring.h> namespace log4cxx { namespace helpers { /** The class Exception and its subclasses indicate conditions that a reasonable application might want to catch. */ class LOG4CXX_EXPORT Exception : public ::std::exception { public: Exception(const char* msg); Exception(const LogString& msg); Exception(const Exception& src); Exception& operator=(const Exception& src); const char* what() const throw(); private: enum { MSG_SIZE = 128 }; char msg[MSG_SIZE + 1]; }; // class Exception /** RuntimeException is the parent class of those exceptions that can be thrown during the normal operation of the process. */ class LOG4CXX_EXPORT RuntimeException : public Exception { public: RuntimeException(log4cxx_status_t stat); RuntimeException(const LogString& msg); RuntimeException(const RuntimeException& msg); RuntimeException& operator=(const RuntimeException& src); private: static LogString formatMessage(log4cxx_status_t stat); }; // class RuntimeException /** Thrown when an application attempts to use null in a case where an object is required. */ class LOG4CXX_EXPORT NullPointerException : public RuntimeException { public: NullPointerException(const LogString& msg); NullPointerException(const NullPointerException& msg); NullPointerException& operator=(const NullPointerException& src); }; // class NullPointerException /** Thrown to indicate that a method has been passed an illegal or inappropriate argument.*/ class LOG4CXX_EXPORT IllegalArgumentException : public RuntimeException { public: IllegalArgumentException(const LogString& msg); IllegalArgumentException(const IllegalArgumentException&); IllegalArgumentException& operator=(const IllegalArgumentException&); }; // class IllegalArgumentException /** Signals that an I/O exception of some sort has occurred. This class is the general class of exceptions produced by failed or interrupted I/O operations. */ class LOG4CXX_EXPORT IOException : public Exception { public: IOException(); IOException(log4cxx_status_t stat); IOException(const LogString& msg); IOException(const IOException &src); IOException& operator=(const IOException&); private: static LogString formatMessage(log4cxx_status_t stat); }; class LOG4CXX_EXPORT MissingResourceException : public Exception { public: MissingResourceException(const LogString& key); MissingResourceException(const MissingResourceException &src); MissingResourceException& operator=(const MissingResourceException&); private: static LogString formatMessage(const LogString& key); }; class LOG4CXX_EXPORT PoolException : public Exception { public: PoolException(log4cxx_status_t stat); PoolException(const PoolException &src); PoolException& operator=(const PoolException&); private: static LogString formatMessage(log4cxx_status_t stat); }; class LOG4CXX_EXPORT MutexException : public Exception { public: MutexException(log4cxx_status_t stat); MutexException(const MutexException &src); MutexException& operator=(const MutexException&); private: static LogString formatMessage(log4cxx_status_t stat); }; class LOG4CXX_EXPORT InterruptedException : public Exception { public: InterruptedException(); InterruptedException(log4cxx_status_t stat); InterruptedException(const InterruptedException &src); InterruptedException& operator=(const InterruptedException&); private: static LogString formatMessage(log4cxx_status_t stat); }; class LOG4CXX_EXPORT ThreadException : public Exception { public: ThreadException(log4cxx_status_t stat); ThreadException(const LogString& msg); ThreadException(const ThreadException &src); ThreadException& operator=(const ThreadException&); private: static LogString formatMessage(log4cxx_status_t stat); }; class LOG4CXX_EXPORT TranscoderException : public Exception { public: TranscoderException(log4cxx_status_t stat); TranscoderException(const TranscoderException &src); TranscoderException& operator=(const TranscoderException&); private: static LogString formatMessage(log4cxx_status_t stat); }; class LOG4CXX_EXPORT IllegalMonitorStateException : public Exception { public: IllegalMonitorStateException(const LogString& msg); IllegalMonitorStateException(const IllegalMonitorStateException& msg); IllegalMonitorStateException& operator=(const IllegalMonitorStateException& msg); }; /** Thrown when an application tries to create an instance of a class using the newInstance method in class Class, but the specified class object cannot be instantiated because it is an interface or is an abstract class. */ class LOG4CXX_EXPORT InstantiationException : public Exception { public: InstantiationException(const LogString& msg); InstantiationException(const InstantiationException& msg); InstantiationException& operator=(const InstantiationException& msg); }; /** Thrown when an application tries to load in a class through its string name but no definition for the class with the specified name could be found. */ class LOG4CXX_EXPORT ClassNotFoundException : public Exception { public: ClassNotFoundException(const LogString& className); ClassNotFoundException(const ClassNotFoundException& msg); ClassNotFoundException& operator=(const ClassNotFoundException& msg); private: static LogString formatMessage(const LogString& className); }; class NoSuchElementException : public Exception { public: NoSuchElementException(); NoSuchElementException(const NoSuchElementException&); NoSuchElementException& operator=(const NoSuchElementException&); }; class IllegalStateException : public Exception { public: IllegalStateException(); IllegalStateException(const IllegalStateException&); IllegalStateException& operator=(const IllegalStateException&); }; /** Thrown to indicate that there is an error in the underlying protocol, such as a TCP error. */ class LOG4CXX_EXPORT SocketException : public IOException { public: SocketException(const LogString& msg); SocketException(log4cxx_status_t status); SocketException(const SocketException&); SocketException& operator=(const SocketException&); }; /** Signals that an error occurred while attempting to connect a socket to a remote address and port. Typically, the connection was refused remotely (e.g., no process is listening on the remote address/port). */ class LOG4CXX_EXPORT ConnectException : public SocketException { public: ConnectException(log4cxx_status_t status); ConnectException(const ConnectException& src); ConnectException& operator=(const ConnectException&); }; class LOG4CXX_EXPORT ClosedChannelException : public SocketException { public: ClosedChannelException(); ClosedChannelException(const ClosedChannelException& src); ClosedChannelException& operator=(const ClosedChannelException&); }; /** Signals that an error occurred while attempting to bind a socket to a local address and port. Typically, the port is in use, or the requested local address could not be assigned. */ class LOG4CXX_EXPORT BindException : public SocketException { public: BindException(log4cxx_status_t status); BindException(const BindException&); BindException& operator=(const BindException&); }; /** Signals that an I/O operation has been interrupted. An InterruptedIOException is thrown to indicate that an input or output transfer has been terminated because the thread performing it was interrupted. The field bytesTransferred indicates how many bytes were successfully transferred before the interruption occurred. */ class LOG4CXX_EXPORT InterruptedIOException : public IOException { public: InterruptedIOException(const LogString& msg); InterruptedIOException(const InterruptedIOException&); InterruptedIOException& operator=(const InterruptedIOException&); }; /** Signals that an I/O operation has been interrupted. An InterruptedIOException is thrown to indicate that an input or output transfer has been terminated because the thread performing it was interrupted. The field bytesTransferred indicates how many bytes were successfully transferred before the interruption occurred. */ class LOG4CXX_EXPORT SocketTimeoutException : public InterruptedIOException { public: SocketTimeoutException(); SocketTimeoutException(const SocketTimeoutException&); SocketTimeoutException& operator=(const SocketTimeoutException&); }; } // namespace helpers } // namespace log4cxx #endif // _LOG4CXX_HELPERS_EXCEPTION_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_CYCLICBUFFER_H #define _LOG4CXX_HELPERS_CYCLICBUFFER_H #include <log4cxx/spi/loggingevent.h> namespace log4cxx { namespace helpers { /** CyclicBuffer is used by other appenders to hold instances of {@link log4cxx::spi::LoggingEvent LoggingEvent} for immediate or deferred display. <p>This buffer gives read access to any element in the buffer not just the first or last element. */ class LOG4CXX_EXPORT CyclicBuffer { log4cxx::spi::LoggingEventList ea; int first; int last; int numElems; int maxSize; public: /** Instantiate a new CyclicBuffer of at most <code>maxSize</code> events. The <code>maxSize</code> argument must a positive integer. @param maxSize The maximum number of elements in the buffer. @throws IllegalArgumentException if <code>maxSize</code> is negative. */ CyclicBuffer(int maxSize); ~CyclicBuffer(); /** Add an <code>event</code> as the last event in the buffer. */ void add(const spi::LoggingEventPtr& event); /** Get the <i>i</i>th oldest event currently in the buffer. If <em>i</em> is outside the range 0 to the number of elements currently in the buffer, then <code>null</code> is returned. */ spi::LoggingEventPtr get(int i); int getMaxSize() const { return maxSize; } /** Get the oldest (first) element in the buffer. The oldest element is removed from the buffer. */ spi::LoggingEventPtr get(); /** Get the number of elements in the buffer. This number is guaranteed to be in the range 0 to <code>maxSize</code> (inclusive). */ int length() const { return numElems; } /** Resize the cyclic buffer to <code>newSize</code>. @throws IllegalArgumentException if <code>newSize</code> is negative. */ void resize(int newSize); }; // class CyclicBuffer } //namespace helpers } //namespace log4cxx #endif //_LOG4CXX_HELPERS_CYCLICBUFFER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_FILEWATCHDOG_H #define _LOG4CXX_HELPERS_FILEWATCHDOG_H #include <log4cxx/logstring.h> #include <time.h> #include <log4cxx/helpers/pool.h> #include <log4cxx/helpers/thread.h> #include <log4cxx/file.h> namespace log4cxx { namespace helpers { /** Check every now and then that a certain file has not changed. If it has, then call the #doOnChange method. */ class LOG4CXX_EXPORT FileWatchdog { public: virtual ~FileWatchdog(); /** The default delay between every file modification check, set to 60 seconds. */ static long DEFAULT_DELAY /*= 60000*/; protected: /** The name of the file to observe for changes. */ File file; /** The delay to observe between every check. By default set DEFAULT_DELAY.*/ long delay; log4cxx_time_t lastModif; bool warnedAlready; volatile unsigned int interrupted; protected: FileWatchdog(const File& filename); virtual void doOnChange() = 0; void checkAndConfigure(); public: /** Set the delay to observe between each check of the file changes. */ void setDelay(long delay1) { this->delay = delay1; } void start(); private: static void* LOG4CXX_THREAD_FUNC run(apr_thread_t* thread, void* data); Pool pool; Thread thread; FileWatchdog(const FileWatchdog&); FileWatchdog& operator=(const FileWatchdog&); }; } // namespace helpers } // namespace log4cxx #endif // _LOG4CXX_HELPERS_FILEWATCHDOG_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_LOCALE_H #define _LOG4CXX_HELPERS_LOCALE_H #include <log4cxx/logstring.h> namespace log4cxx { namespace helpers { class LOG4CXX_EXPORT Locale { public: Locale(const LogString& language); Locale(const LogString& language, const LogString& country); Locale(const LogString& language, const LogString& country, const LogString& variant); const LogString& getLanguage() const; const LogString& getCountry() const; const LogString& getVariant() const; protected: Locale(const Locale&); Locale& operator=(const Locale&); const LogString language; const LogString country; const LogString variant; }; // class Locale } // namespace helpers } // namespace log4cxx #endif // _LOG4CXX_HELPERS_LOCALE_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_APRINITIALIZER_H #define _LOG4CXX_HELPERS_APRINITIALIZER_H #ifndef LOG4CXX #error "aprinitializer.h should only be included by log4cxx implementation" #endif #include <log4cxx/helpers/pool.h> #include <apr_pools.h> #include <apr_thread_proc.h> namespace log4cxx { namespace helpers { class APRInitializer { public: static log4cxx_time_t initialize(); static apr_pool_t* getRootPool(); static apr_threadkey_t* getTlsKey(); static bool isDestructed; private: APRInitializer(); APRInitializer(const APRInitializer&); APRInitializer& operator=(const APRInitializer&); apr_pool_t* p; log4cxx_time_t startTime; apr_threadkey_t* tlsKey; static APRInitializer& getInstance(); static void tlsDestruct(void*); public: ~APRInitializer(); }; } // namespace helpers } // namespace log4cxx #endif //_LOG4CXX_HELPERS_APRINITIALIZER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_STRING_HELPER_H #define _LOG4CXX_HELPERS_STRING_HELPER_H #include <log4cxx/logstring.h> #include <vector> namespace log4cxx { namespace helpers { class Pool; /** String manipulation routines */ class LOG4CXX_EXPORT StringHelper { public: static LogString trim(const LogString& s); static bool startsWith(const LogString& s, const LogString& suffix); static bool endsWith(const LogString& s, const LogString& suffix); static bool equalsIgnoreCase(const LogString& s1, const logchar* upper, const logchar* lower); static bool equalsIgnoreCase(const LogString& s1, const LogString& upper, const LogString& lower); static int toInt(const LogString& s); static log4cxx_int64_t toInt64(const LogString& s); static void toString(int i, log4cxx::helpers::Pool& pool, LogString& dst); static void toString(log4cxx_int64_t i, log4cxx::helpers::Pool& pool, LogString& dst); static void toString(size_t i, log4cxx::helpers::Pool& pool, LogString& dst); static void toString(bool val, LogString& dst); static LogString toLowerCase(const LogString& s); static LogString format(const LogString& pattern, const std::vector<LogString>& params); }; } } #endif //_LOG4CXX_HELPERS_STRING_HELPER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_RESOURCE_BUNDLE_H #define _LOG4CXX_HELPERS_RESOURCE_BUNDLE_H #include <log4cxx/helpers/objectimpl.h> #include <log4cxx/helpers/objectptr.h> namespace log4cxx { namespace helpers { class Locale; class ResourceBundle; LOG4CXX_PTR_DEF(ResourceBundle); /** Resource bundles contain locale-specific objects */ class LOG4CXX_EXPORT ResourceBundle : public ObjectImpl { public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(ResourceBundle) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(ResourceBundle) END_LOG4CXX_CAST_MAP() /** Gets a string for the given key from this resource bundle or one of its parents. Calling this method is equivalent to calling @param key the key for the desired string @return the string for the given key @throw MissingResourceException - if no object for the given key can be found */ virtual LogString getString(const LogString& key) const = 0; /** Gets a resource bundle using the specified base name and locale @param baseName the base name of the resource bundle, a fully qualified class name or property filename @param locale the locale for which a resource bundle is desired */ static ResourceBundlePtr getBundle(const LogString& baseName, const Locale& locale); protected: /* Sets the parent bundle of this bundle. The parent bundle is searched by #getString when this bundle does not contain a particular resource. Parameters: parent - this bundle's parent bundle. */ inline void setParent(const ResourceBundlePtr& parent1) { this->parent = parent1; } /** The parent bundle of this bundle. The parent bundle is searched by #getString when this bundle does not contain a particular resource. */ ResourceBundlePtr parent; }; // class ResourceBundle } // namespace helpers } // namespace log4cxx #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPER_OPTION_CONVERTER_H #define _LOG4CXX_HELPER_OPTION_CONVERTER_H #include <log4cxx/logstring.h> #include <log4cxx/helpers/objectptr.h> namespace log4cxx { class Level; class File; typedef helpers::ObjectPtrT<Level> LevelPtr; namespace spi { class LoggerRepository; typedef helpers::ObjectPtrT<LoggerRepository> LoggerRepositoryPtr; } namespace helpers { class Properties; class Object; typedef ObjectPtrT<Object> ObjectPtr; class Class; /** A convenience class to convert property values to specific types.*/ class LOG4CXX_EXPORT OptionConverter { /** OptionConverter is a static class. */ private: OptionConverter() {} public: static LogString convertSpecialChars(const LogString& s); /** If <code>value</code> is "true", then <code>true</code> is returned. If <code>value</code> is "false", then <code>true</code> is returned. Otherwise, <code>default</code> is returned. <p>Case of value is unimportant. */ static bool toBoolean(const LogString& value, bool dEfault); static int toInt(const LogString& value, int dEfault); static long toFileSize(const LogString& value, long dEfault); static LevelPtr toLevel(const LogString& value, const LevelPtr& defaultValue); /** Find the value corresponding to <code>key</code> in <code>props</code>. Then perform variable substitution on the found value. */ static LogString findAndSubst(const LogString& key, Properties& props); /** Perform variable substitution in string <code>val</code> from the values of keys found in the system propeties. <p>The variable substitution delimeters are <b>${</b> and <b>}</b>. <p>For example, if the System properties contains "key=value", then the call <pre> String s = OptionConverter.substituteVars("Value of key is ${key}."); </pre> will set the variable <code>s</code> to "Value of key is value.". <p>If no value could be found for the specified key, then the <code>props</code> parameter is searched, if the value could not be found there, then substitution defaults to the empty string. <p>For example, if system propeties contains no value for the key "inexistentKey", then the call <pre> String s = OptionConverter.subsVars("Value of inexistentKey is [${inexistentKey}]"); </pre> will set <code>s</code> to "Value of inexistentKey is []" <p>An IllegalArgumentException is thrown if <code>val</code> contains a start delimeter "${" which is not balanced by a stop delimeter "}". </p> @param val The string on which variable substitution is performed. @param props The properties from which variable substitution is performed. @throws IllegalArgumentException if <code>val</code> is malformed. */ static LogString substVars(const LogString& val, Properties& props); /** * Gets the specified system property. @param key The key to search for. @param def The default value to return. @return the string value of the system property, or the default value if there is no property with that key. */ static LogString getSystemProperty(const LogString& key, const LogString& def); /** Instantiate an object given a class name. Check that the <code>className</code> is a subclass of <code>superClass</code>. If that test fails or the object could not be instantiated, then <code>defaultValue</code> is returned. @param className The fully qualified class name of the object to instantiate. @param superClass The class to which the new object should belong. @param defaultValue The object to return in case of non-fulfillment */ static ObjectPtr instantiateByClassName(const LogString& className, const Class& superClass, const ObjectPtr& defaultValue); static ObjectPtr instantiateByKey(Properties& props, const LogString& key, const Class& superClass, const ObjectPtr& defaultValue); /** Configure log4cxx given a configFileName. <p>The configFileName must point to a file which will be interpreted by a new instance of a log4cxx configurator. <p>All configurations steps are taken on the <code>hierarchy</code> passed as a parameter. <p> @param configFileName The location of the configuration file. @param clazz The classname, of the log4cxx configurator which will parse the file <code>configFileName</code>. This must be a subclass of Configurator, or null. If this value is null then a default configurator of PropertyConfigurator is used, unless the filename pointed to by <code>configFileName</code> ends in '.xml', in which case DOMConfigurator is used. @param hierarchy The Hierarchy to act on. */ static void selectAndConfigure(const File& configFileName, const LogString& clazz, spi::LoggerRepositoryPtr& hierarchy); }; } // namespace helpers } // namespace log4cxx #endif //_LOG4CXX_HELPER_OPTION_CONVERTER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_THREAD_LOCAL_H #define _LOG4CXX_HELPERS_THREAD_LOCAL_H #include <log4cxx/log4cxx.h> #include <log4cxx/helpers/pool.h> #if !defined(LOG4CXX_THREAD_FUNC) #if defined(_WIN32) #define LOG4CXX_THREAD_FUNC __stdcall #else #define LOG4CXX_THREAD_FUNC #endif #endif extern "C" { struct apr_threadkey_t; } namespace log4cxx { namespace helpers { /** * This class provides thread-local variables. This class is similar in function * to java.lang.ThreadLocal. */ class LOG4CXX_EXPORT ThreadLocal { public: /** * Create new instance. */ ThreadLocal(); /** * Destructor. */ ~ThreadLocal(); /** * Sets the value in the current thread's copy of this thread-local variable. * @param priv new value. */ void set(void* priv); /** * Returns the value in the current thread's copy of this thread-local variable. * @return value of thread-local variable for the current thread. */ void* get(); private: /** * Prevent use of default copy constructor. */ ThreadLocal(const ThreadLocal&); /** * Prevent use of default assignment operator. */ ThreadLocal& operator=(const ThreadLocal&); static apr_threadkey_t* create(Pool& p); Pool p; apr_threadkey_t* key; }; } // namespace helpers } // namespace log4cxx #endif //_LOG4CXX_HELPERS_THREAD_LOCAL_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_DATE_LAYOUT_H #define _LOG4CXX_HELPERS_DATE_LAYOUT_H #include <log4cxx/layout.h> #include <log4cxx/helpers/dateformat.h> #include <log4cxx/helpers/timezone.h> namespace log4cxx { namespace helpers { /** This abstract layout takes care of all the date related options and formatting work. */ class LOG4CXX_EXPORT DateLayout : public Layout { private: LogString timeZoneID; LogString dateFormatOption; protected: DateFormatPtr dateFormat; public: DateLayout(const LogString& dateLayoutOption); virtual ~DateLayout(); virtual void activateOptions(log4cxx::helpers::Pool& p); virtual void setOption(const LogString& option, const LogString& value); /** The value of the <b>DateFormat</b> option should be either an argument to the constructor of helpers::DateFormat or one of the strings <b>"NULL"</b>, <b>"RELATIVE"</b>, <b>"ABSOLUTE"</b>, <b>"DATE"</b> or <b>"ISO8601</b>. */ inline void setDateFormat(const LogString& dateFormat1) { this->dateFormatOption.assign(dateFormat1); } /** Returns value of the <b>DateFormat</b> option. */ inline const LogString& getDateFormat() const { return dateFormatOption; } /** The <b>TimeZoneID</b> option is a time zone ID string in the format expected by the <code>locale</code> C++ standard class. */ inline void setTimeZone(const LogString& timeZone) { this->timeZoneID.assign(timeZone); } /** Returns value of the <b>TimeZone</b> option. */ inline const LogString& getTimeZone() const { return timeZoneID; } void formatDate(LogString &s, const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p) const; private: // // prevent copy and assignment DateLayout(const DateLayout&); DateLayout& operator=(const DateLayout&); }; } // namespace helpers } // namespace log4cxx #endif // _LOG4CXX_HELPERS_DATE_LAYOUT_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_FILEINPUTSTREAM_H #define _LOG4CXX_HELPERS_FILEINPUTSTREAM_H #include <log4cxx/helpers/inputstream.h> #include <log4cxx/file.h> #include <log4cxx/helpers/pool.h> namespace log4cxx { namespace helpers { /** * InputStream implemented on top of APR file IO. * */ class LOG4CXX_EXPORT FileInputStream : public InputStream { private: Pool pool; apr_file_t* fileptr; public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(FileInputStream) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(FileInputStream) LOG4CXX_CAST_ENTRY_CHAIN(InputStream) END_LOG4CXX_CAST_MAP() /** * Creates a FileInputStream by opening a connection to an actual * file, the file named by the path name name in the file system. * * @param filename The system-dependent file name. */ FileInputStream(const LogString& filename); FileInputStream(const logchar* filename); /** * Creates a FileInputStream by opening a connection to an actual * file, the file named by the File object file in the file system. * * @param aFile The file to be opened for reading. */ FileInputStream(const File& aFile); virtual ~FileInputStream(); /** * Closes this file input stream and releases any system * resources associated with the stream. */ virtual void close(); /** * Reads a sequence of bytes into the given buffer. * * @param buf The buffer into which bytes are to be transferred. * @return the total number of bytes read into the buffer, or -1 if there * is no more data because the end of the stream has been reached. */ virtual int read(ByteBuffer& buf); private: FileInputStream(const FileInputStream&); FileInputStream& operator=(const FileInputStream&); void open(const LogString&); }; LOG4CXX_PTR_DEF(FileInputStream); } // namespace helpers } //namespace log4cxx #endif //_LOG4CXX_HELPERS_FILEINPUTSTREAM_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_BUFFEREDOUTPUTSTREAM_H #define _LOG4CXX_HELPERS_BUFFEREDOUTPUTSTREAM_H #include <log4cxx/helpers/outputstream.h> namespace log4cxx { namespace helpers { /** * Abstract class for writing to character streams. */ class LOG4CXX_EXPORT BufferedOutputStream : public OutputStream { private: size_t count; LogString buf; public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(BufferedOutputStream) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(BufferedOutputStream) LOG4CXX_CAST_ENTRY_CHAIN(OutputStream) END_LOG4CXX_CAST_MAP() protected: BufferedOutputStream(OutputStreamPtr& out, size_t size = 4096); ~BufferedOutputStream(); public: void close(Pool& p); void flush(Pool& p); void write(ByteBuffer& buf, Pool& p); private: BufferedOutputStream(const BufferedOutputStream&); BufferedOutputStream& operator=(const BufferedOutputStream&); }; LOG4CXX_PTR_DEF(BufferedOutputStream); } // namespace helpers } //namespace log4cxx #endif //_LOG4CXX_HELPERS_BUFFEREDOUTPUTSTREAM_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_TRANSCODER_H #define _LOG4CXX_HELPERS_TRANSCODER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/logstring.h> namespace log4cxx { namespace helpers { class ByteBuffer; class Pool; /** * Simple transcoder for converting between * external char and wchar_t strings and * internal strings. * */ class LOG4CXX_EXPORT Transcoder { public: /** * Appends this specified string of UTF-8 characters to LogString. */ static void decodeUTF8(const std::string& src, LogString& dst); /** * Converts the LogString to a UTF-8 string. */ static void encodeUTF8(const LogString& src, std::string& dst); /** * Converts the LogString to a UTF-8 string. */ static char* encodeUTF8(const LogString& src, log4cxx::helpers::Pool& p); /** * Append UCS-4 code point to a byte buffer as UTF-8. */ static void encodeUTF8(unsigned int sv, ByteBuffer& dst); /** * Append UCS-4 code point to a byte buffer as UTF-16LE. */ static void encodeUTF16LE(unsigned int sv, ByteBuffer& dst); /** * Append UCS-4 code point to a byte buffer as UTF-16BE. */ static void encodeUTF16BE(unsigned int sv, ByteBuffer& dst); /** * Decodes next character from a UTF-8 string. * @param in string from which the character is extracted. * @param iter iterator addressing start of character, will be * advanced to next character if successful. * @return scalar value (UCS-4) or 0xFFFF if invalid sequence. */ static unsigned int decode(const std::string& in, std::string::const_iterator& iter); /** * Appends UCS-4 value to a UTF-8 string. * @param ch UCS-4 value. * @param dst destination. */ static void encode(unsigned int ch, std::string& dst); /** * Appends string in the current code-page * to a LogString. */ static void decode(const std::string& src, LogString& dst); /** * Appends a LogString to a string in the current * code-page. Unrepresentable characters may be * replaced with loss characters. */ static void encode(const LogString& src, std::string& dst); /** * Encodes the specified LogString to the current * character set. * @param src string to encode. * @param p pool from which to allocate return value. * @return pool allocated string. */ static char* encode(const LogString& src, log4cxx::helpers::Pool& p); #if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR_T || defined(WIN32) || defined(_WIN32) static void decode(const std::wstring& src, LogString& dst); static void encode(const LogString& src, std::wstring& dst); static wchar_t* wencode(const LogString& src, log4cxx::helpers::Pool& p); /** * Decodes next character from a wstring. * @param in string from which the character is extracted. * @param iter iterator addressing start of character, will be * advanced to next character if successful. * @return scalar value (UCS-4) or 0xFFFF if invalid sequence. */ static unsigned int decode(const std::wstring& in, std::wstring::const_iterator& iter); /** * Appends UCS-4 value to a UTF-8 string. * @param ch UCS-4 value. * @param dst destination. */ static void encode(unsigned int ch, std::wstring& dst); #endif #if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API || LOG4CXX_LOGCHAR_IS_UNICHAR static void decode(const std::basic_string<UniChar>& src, LogString& dst); static void encode(const LogString& src, std::basic_string<UniChar>& dst); /** * Decodes next character from a UniChar string. * @param in string from which the character is extracted. * @param iter iterator addressing start of character, will be * advanced to next character if successful. * @return scalar value (UCS-4) or 0xFFFF if invalid sequence. */ static unsigned int decode(const std::basic_string<UniChar>& in, std::basic_string<UniChar>::const_iterator& iter); /** * Appends UCS-4 value to a UTF-8 string. * @param ch UCS-4 value. * @param dst destination. */ static void encode(unsigned int ch, std::basic_string<UniChar>& dst); #endif #if LOG4CXX_CFSTRING_API static void decode(const CFStringRef& src, LogString& dst); static CFStringRef encode(const LogString& src); #endif enum { LOSSCHAR = 0x3F }; /** * Returns a logchar value given a character literal in the ASCII charset. * Used to implement the LOG4CXX_STR macro for EBCDIC and UNICHAR. */ static logchar decode(char v); /** * Returns a LogString given a string literal in the ASCII charset. * Used to implement the LOG4CXX_STR macro for EBCDIC and UNICHAR. */ static LogString decode(const char* v); /** * Encodes a charset name in the default encoding * without using a CharsetEncoder (which could trigger recursion). */ static std::string encodeCharsetName(const LogString& charsetName); private: private: Transcoder(); Transcoder(const Transcoder&); Transcoder& operator=(const Transcoder&); enum { BUFSIZE = 256 }; static size_t encodeUTF8(unsigned int ch, char* dst); static size_t encodeUTF16BE(unsigned int ch, char* dst); static size_t encodeUTF16LE(unsigned int ch, char* dst); }; } } #define LOG4CXX_ENCODE_CHAR(var, src) \ std::string var; \ log4cxx::helpers::Transcoder::encode(src, var) #define LOG4CXX_DECODE_CHAR(var, src) \ log4cxx::LogString var; \ log4cxx::helpers::Transcoder::decode(src, var) #define LOG4CXX_DECODE_CFSTRING(var, src) \ log4cxx::LogString var; \ log4cxx::helpers::Transcoder::decode(src, var) #define LOG4CXX_ENCODE_CFSTRING(var, src) \ CFStringRef var = log4cxx::helpers::Transcoder::encode(src) #if LOG4CXX_LOGCHAR_IS_WCHAR #define LOG4CXX_ENCODE_WCHAR(var, src) \ const std::wstring& var = src #define LOG4CXX_DECODE_WCHAR(var, src) \ const log4cxx::LogString& var = src #else #define LOG4CXX_ENCODE_WCHAR(var, src) \ std::wstring var; \ log4cxx::helpers::Transcoder::encode(src, var) #define LOG4CXX_DECODE_WCHAR(var, src) \ log4cxx::LogString var; \ log4cxx::helpers::Transcoder::decode(src, var) #endif #if LOG4CXX_LOGCHAR_IS_UNICHAR #define LOG4CXX_ENCODE_UNICHAR(var, src) \ const std::basic_string<UniChar>& var = src #define LOG4CXX_DECODE_UNICHAR(var, src) \ const log4cxx::LogString& var = src #else #define LOG4CXX_ENCODE_UNICHAR(var, src) \ std::basic_string<UniChar> var; \ log4cxx::helpers::Transcoder::encode(src, var) #define LOG4CXX_DECODE_UNICHAR(var, src) \ log4cxx::LogString var; \ log4cxx::helpers::Transcoder::decode(src, var) #endif #if defined(_MSC_VER) #pragma warning (pop) #endif #endif //_LOG4CXX_HELPERS_TRANSCODER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_STRICTMATH_H #define _LOG4CXX_HELPERS_STRICTMATH_H #include <log4cxx/log4cxx.h> namespace log4cxx { namespace helpers { /** The class StrictMath contains methods for performing basic numeric operations */ class StrictMath { public: template<typename _type> static inline const _type& minimum(const _type& a, const _type& b) { return (a < b) ? a : b; } template<typename _type> static inline const _type& maximum(const _type& a, const _type& b) { return (a > b) ? a : b; } }; // class StrictMath } // namespace helpers } // namespace log4cx #endif //_LOG4CXX_HELPERS_STRICTMATH_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_OBJECT_IMPL_H #define _LOG4CXX_HELPERS_OBJECT_IMPL_H #include <log4cxx/helpers/object.h> namespace log4cxx { namespace helpers { /** Implementation class for Object.*/ class LOG4CXX_EXPORT ObjectImpl : public virtual Object { public: ObjectImpl(); virtual ~ObjectImpl(); void addRef() const; void releaseRef() const; protected: mutable unsigned int volatile ref; private: // // prevent object copy and assignment // ObjectImpl(const ObjectImpl&); ObjectImpl& operator=(const ObjectImpl&); }; } } #endif //_LOG4CXX_HELPERS_OBJECT_IMPL_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_TIMEZONE_H #define _LOG4CXX_HELPERS_TIMEZONE_H #include <log4cxx/logstring.h> #include <log4cxx/helpers/objectimpl.h> #include <log4cxx/helpers/objectptr.h> struct apr_time_exp_t; namespace log4cxx { namespace helpers { class TimeZone; LOG4CXX_PTR_DEF(TimeZone); class LOG4CXX_EXPORT TimeZone : public helpers::ObjectImpl { public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(TimeZone) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(TimeZone) END_LOG4CXX_CAST_MAP() static const TimeZonePtr& getDefault(); static const TimeZonePtr& getGMT(); static const TimeZonePtr getTimeZone(const LogString& ID); const LogString getID() const { return id; } /** * Expand an APR time into the human readable * components for this timezone. */ virtual log4cxx_status_t explode(apr_time_exp_t* result, log4cxx_time_t input) const = 0; protected: TimeZone(const LogString& ID); virtual ~TimeZone(); const LogString id; }; } } #endif //_LOG4CXX_HELPERS_TIMEZONE_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_STRING_TOKENIZER_H #define _LOG4CXX_HELPERS_STRING_TOKENIZER_H #include <log4cxx/logstring.h> #include <log4cxx/helpers/exception.h> namespace log4cxx { namespace helpers { class LOG4CXX_EXPORT StringTokenizer { public: StringTokenizer(const LogString& str, const LogString& delim); ~StringTokenizer(); bool hasMoreTokens() const; LogString nextToken(); protected: LogString src; LogString delim; size_t pos; private: // prevent copy and assignment statements StringTokenizer(const StringTokenizer&); StringTokenizer& operator=(const StringTokenizer&); }; // class StringTokenizer } // namespace helpers; } // namespace log4cxx; #endif //_LOG4CXX_HELPERS_STRING_TOKENIZER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPERS_DATAGRAM_SOCKET_H #define _LOG4CXX_HELPERS_DATAGRAM_SOCKET_H #include <log4cxx/helpers/objectimpl.h> #include <log4cxx/helpers/objectptr.h> #include <log4cxx/helpers/inetaddress.h> #include <log4cxx/helpers/pool.h> #include <log4cxx/helpers/datagrampacket.h> extern "C" { struct apr_socket_t; } namespace log4cxx { namespace helpers { /** This class represents a socket for sending and receiving datagram packets.*/ class LOG4CXX_EXPORT DatagramSocket : public helpers::ObjectImpl { public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(DatagramSocket) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(DatagramSocket) END_LOG4CXX_CAST_MAP() /** Constructs a datagram socket and binds it to any available port on the local host machine.*/ DatagramSocket(); /** Constructs a datagram socket and binds it to the specified port on the local host machine. */ DatagramSocket(int port); /** Creates a datagram socket, bound to the specified local address. */ DatagramSocket(int port, InetAddressPtr laddr); /** ensure the socket is closed. */ ~DatagramSocket(); /** Binds a datagram socket to a local port and address.*/ void bind(int lport, InetAddressPtr laddress); /** Creates a datagram socket.*/ void create(); /** Closes this datagram socket */ void close(); /** Connects the socket to a remote address for this socket. */ void connect(InetAddressPtr address, int port); /** Returns the address to which this socket is connected. */ inline InetAddressPtr getInetAddress() const { return address; } /** Gets the local address to which the socket is bound. */ inline InetAddressPtr getLocalAddress() const { return localAddress; } /** Returns the port number on the local host to which this socket is bound. */ inline int getLocalPort() const { return localPort; } /** Returns the port for this socket */ inline int getPort() const { return port; } /** Returns the binding state of the socket. **/ inline bool isBound() const { return localPort != 0; } /** Returns wether the socket is closed or not. */ inline bool isClosed() const { return socket != 0; } /** Returns the connection state of the socket. */ inline bool isConnected() const { return port != 0; } /** Receives a datagram packet from this socket. */ void receive(DatagramPacketPtr& p); /** Sends a datagram packet from this socket. */ void send(DatagramPacketPtr& p); private: DatagramSocket(const DatagramSocket&); DatagramSocket& operator=(const DatagramSocket&); /** The APR socket */ apr_socket_t *socket; /** The memory pool for the socket */ Pool socketPool; InetAddressPtr address; InetAddressPtr localAddress; int port; /** The local port number to which this socket is connected. */ int localPort; }; LOG4CXX_PTR_DEF(DatagramSocket); } // namespace helpers } // namespace log4cxx #endif //_LOG4CXX_HELPERS_DATAGRAM_SOCKET_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PROVISION_NODE_H #define _LOG4CXX_PROVISION_NODE_H #include <vector> #include <log4cxx/helpers/objectptr.h> #include <log4cxx/logger.h> namespace log4cxx { class Logger; typedef helpers::ObjectPtrT<Logger> LoggerPtr; typedef std::vector<LoggerPtr> ProvisionNode; } // namespace log4cxx #endif //_LOG4CXX_PROVISION_NODE_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_FILE_H #define _LOG4CXX_FILE_H #include <log4cxx/logger.h> #include <log4cxx/logstring.h> extern "C" { struct apr_file_t; struct apr_finfo_t; } namespace log4cxx { namespace helpers { class Transcoder; class Pool; } /** * An abstract representation of file and directory path names. */ class LOG4CXX_EXPORT File { public: /** * Construct a new instance. */ File(); /** * Construct a new instance. Use setPath to specify path using a LogString. * @param path file path in local encoding. */ File(const char* path); /** * Construct a new instance. Use setPath to specify path using a LogString. * @param path file path in current encoding. */ File(const std::string& path); #if LOG4CXX_WCHAR_T_API /** * Construct a new instance. Use setPath to specify path using a LogString. * @param path file path. */ File(const wchar_t* path); /** * Construct a new instance. Use setPath to specify path using a LogString. * @param path file path. */ File(const std::wstring& path); #endif #if LOG4CXX_UNICHAR_API /** * Construct a new instance. Use setPath to specify path using a LogString. * @param path file path. */ File(const UniChar* path); /** * Construct a new instance. Use setPath to specify path using a LogString. * @param path file path. */ File(const std::basic_string<UniChar>& path); #endif #if LOG4CXX_CFSTRING_API /** * Construct a new instance. Use setPath to specify path using a LogString. * @param path file path. */ File(const CFStringRef& path); #endif /** * Copy constructor. */ File(const File& src); /** * Assignment operator. */ File& operator=(const File& src); /** * Destructor. */ ~File(); /** * Determines if file exists. * @param p pool. * @return true if file exists. */ bool exists(log4cxx::helpers::Pool& p) const; /** * Determines length of file. May not be accurate if file is current open. * @param p pool. * @return length of file. */ size_t length(log4cxx::helpers::Pool& p) const; /** * Determines last modification date. * @param p pool. * @return length of file. */ log4cxx_time_t lastModified(log4cxx::helpers::Pool& p) const; /** * Get final portion of file path. * @return file name. */ LogString getName() const; /** * Get file path. * @return file path. */ LogString getPath() const; /** * Set file path */ File& setPath(const LogString&); /** * Open file. See apr_file_open for details. * @param file APR file handle. * @param flags flags. * @param perm permissions. * @param p pool. * @return APR_SUCCESS if successful. */ log4cxx_status_t open(apr_file_t** file, int flags, int perm, log4cxx::helpers::Pool& p) const; /** * List files if current file is a directory. * @param p pool. * @return list of files in this directory, operation of non-directory returns empty list. */ std::vector<LogString> list(log4cxx::helpers::Pool& p) const; /** * Delete file. * @param p pool. * @return true if file successfully deleted. */ bool deleteFile(log4cxx::helpers::Pool& p) const; /** * Rename file. * @param dest new path for file. * @param p pool. * @return true if file successfully renamed. */ bool renameTo(const File& dest, log4cxx::helpers::Pool& p) const; /** * Get path of parent directory. * @param p pool. * @return path of parent directory. */ LogString getParent(log4cxx::helpers::Pool& p) const; /** * Make directories recursively. * @param p pool. * @return true if all requested directories existed or have been created. */ bool mkdirs(log4cxx::helpers::Pool& p) const; private: LogString path; static char* convertBackSlashes(char*); char* getPath(log4cxx::helpers::Pool& p) const; }; } // namespace log4cxx #define LOG4CXX_FILE(name) log4cxx::File(name) #endif // _LOG4CXX_FILE_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_FILE_APPENDER_H #define _LOG4CXX_FILE_APPENDER_H #include <log4cxx/logger.h> #include <log4cxx/logstring.h> #include <log4cxx/writerappender.h> #include <log4cxx/file.h> #include <log4cxx/helpers/pool.h> namespace log4cxx { namespace helpers { class Pool; } /** * FileAppender appends log events to a file. * * <p>Support for <code>java.io.Writer</code> and console appending * has been deprecated and then removed. See the replacement * solutions: WriterAppender and ConsoleAppender. */ class LOG4CXX_EXPORT FileAppender : public WriterAppender { protected: /** Append to or truncate the file? The default value for this variable is <code>true</code>, meaning that by default a <code>FileAppender</code> will append to an existing file and not truncate it. <p>This option is meaningful only if the FileAppender opens the file. */ bool fileAppend; /** The name of the log file. */ LogString fileName; /** Do we do bufferedIO? */ bool bufferedIO; /** How big should the IO buffer be? Default is 8K. */ int bufferSize; public: DECLARE_LOG4CXX_OBJECT(FileAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(FileAppender) LOG4CXX_CAST_ENTRY_CHAIN(WriterAppender) END_LOG4CXX_CAST_MAP() /** The default constructor does not do anything. */ FileAppender(); /** Instantiate a <code>FileAppender</code> and open the file designated by <code>filename</code>. The opened filename will become the output destination for this appender. <p>If the <code>append</code> parameter is true, the file will be appended to. Otherwise, the file designated by <code>filename</code> will be truncated before being opened. <p>If the <code>bufferedIO</code> parameter is <code>true</code>, then buffered IO will be used to write to the output file. */ FileAppender(const LayoutPtr& layout, const LogString& filename, bool append, bool bufferedIO, int bufferSize); /** Instantiate a FileAppender and open the file designated by <code>filename</code>. The opened filename will become the output destination for this appender. <p>If the <code>append</code> parameter is true, the file will be appended to. Otherwise, the file designated by <code>filename</code> will be truncated before being opened. */ FileAppender(const LayoutPtr& layout, const LogString& filename, bool append); /** Instantiate a FileAppender and open the file designated by <code>filename</code>. The opened filename will become the output destination for this appender. <p>The file will be appended to. */ FileAppender(const LayoutPtr& layout, const LogString& filename); ~FileAppender(); /** The <b>File</b> property takes a string value which should be the name of the file to append to. <p><b>Note that the special values "System.out" or "System.err" are no longer honored.</b> <p>Note: Actual opening of the file is made when #activateOptions is called, not when the options are set. */ virtual void setFile(const LogString& file); /** Sets and <i>opens</i> the file where the log output will go. The specified file must be writable. <p>If there was already an opened file, then the previous file is closed first. <p><b>Do not use this method directly. To configure a FileAppender or one of its subclasses, set its properties one by one and then call activateOptions.</b> @param file The path to the log file. @param append If true will append to fileName. Otherwise will truncate fileName. @param bufferedIO Do we do bufferedIO? @param bufferSize How big should the IO buffer be? @param p memory pool for operation. */ virtual void setFile(const LogString& file, bool append, bool bufferedIO, size_t bufferSize, log4cxx::helpers::Pool& p); /** Returns the value of the <b>Append</b> option. */ inline bool getAppend() const { return fileAppend; } /** Returns the value of the <b>File</b> option. */ inline LogString getFile() const { return fileName; } /** <p>Sets and <i>opens</i> the file where the log output will go. The specified file must be writable. <p>If there was already an opened file, then the previous file is closed first.*/ void activateOptions(log4cxx::helpers::Pool& p); void setOption(const LogString& option, const LogString& value); /** Get the value of the <b>BufferedIO</b> option. <p>BufferedIO will significatnly increase performance on heavily loaded systems. */ inline bool getBufferedIO() const { return bufferedIO; } /** Get the size of the IO buffer. */ inline int getBufferSize() const { return bufferSize; } /** The <b>Append</b> option takes a boolean value. It is set to <code>true</code> by default. If true, then <code>File</code> will be opened in append mode by #setFile (see above). Otherwise, setFile will open <code>File</code> in truncate mode. <p>Note: Actual opening of the file is made when #activateOptions is called, not when the options are set. */ void setAppend(bool fileAppend1); /** The <b>BufferedIO</b> option takes a boolean value. It is set to <code>false</code> by default. If true, then <code>File</code> will be opened in buffered mode. BufferedIO will significantly increase performance on heavily loaded systems. */ void setBufferedIO(bool bufferedIO); /** Set the size of the IO buffer. */ void setBufferSize(int bufferSize1) { this->bufferSize = bufferSize1; } /** * Replaces double backslashes with single backslashes * for compatibility with paths from earlier XML configurations files. * @param name file name * @return corrected file name */ static LogString stripDuplicateBackslashes(const LogString& name); private: FileAppender(const FileAppender&); FileAppender& operator=(const FileAppender&); }; // class FileAppender LOG4CXX_PTR_DEF(FileAppender); } // namespace log4cxx #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HTML_LAYOUT_H #define _LOG4CXX_HTML_LAYOUT_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/layout.h> #include <log4cxx/helpers/iso8601dateformat.h> namespace log4cxx { /** This layout outputs events in a HTML table. */ class LOG4CXX_EXPORT HTMLLayout : public Layout { private: // Print no location info by default bool locationInfo; //= false LogString title; helpers::ISO8601DateFormat dateFormat; public: DECLARE_LOG4CXX_OBJECT(HTMLLayout) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(HTMLLayout) LOG4CXX_CAST_ENTRY_CHAIN(Layout) END_LOG4CXX_CAST_MAP() HTMLLayout(); /** The <b>LocationInfo</b> option takes a boolean value. By default, it is set to false which means there will be no location information output by this layout. If the the option is set to true, then the file name and line number of the statement at the origin of the log statement will be output. <p>If you are embedding this layout within an {@link net::SMTPAppender SMTPAppender} then make sure to set the <b>LocationInfo</b> option of that appender as well. */ inline void setLocationInfo(bool locationInfoFlag) { this->locationInfo = locationInfoFlag; } /** Returns the current value of the <b>LocationInfo</b> option. */ inline bool getLocationInfo() const { return locationInfo; } /** The <b>Title</b> option takes a String value. This option sets the document title of the generated HTML document. <p>Defaults to 'Log4cxx Log Messages'. */ inline void setTitle(const LogString& title1) { this->title.assign(title1); } /** Returns the current value of the <b>Title</b> option. */ inline const LogString& getTitle() const { return title; } /** Returns the content type output by this layout, i.e "text/html". */ virtual LogString getContentType() const { return LOG4CXX_STR("text/html"); } /** No options to activate. */ virtual void activateOptions(log4cxx::helpers::Pool& /* p */) {} /** Set options */ virtual void setOption(const LogString& option, const LogString& value); virtual void format(LogString& output, const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool) const; /** Append appropriate HTML headers. */ virtual void appendHeader(LogString& output, log4cxx::helpers::Pool& pool); /** Append the appropriate HTML footers. */ virtual void appendFooter(LogString& output, log4cxx::helpers::Pool& pool); /** The HTML layout handles the throwable contained in logging events. Hence, this method return <code>false</code>. */ virtual bool ignoresThrowable() const { return false; } }; // class HtmlLayout LOG4CXX_PTR_DEF(HTMLLayout); } // namespace log4cxx #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif // _LOG4CXX_HTML_LAYOUT_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_VARIA_FALLBACK_ERROR_HANDLER_H #define _LOG4CXX_VARIA_FALLBACK_ERROR_HANDLER_H #include <log4cxx/spi/errorhandler.h> #include <log4cxx/helpers/objectimpl.h> #include <log4cxx/appender.h> #include <log4cxx/logger.h> #include <vector> namespace log4cxx { namespace varia { /** The <code>FallbackErrorHandler</code> implements the ErrorHandler interface such that a secondary appender may be specified. This secondary appender takes over if the primary appender fails for whatever reason. <p>The error message is printed on <code>System.err</code>, and logged in the new secondary appender. */ class LOG4CXX_EXPORT FallbackErrorHandler : public virtual spi::ErrorHandler, public virtual helpers::ObjectImpl { private: AppenderPtr backup; AppenderPtr primary; std::vector<LoggerPtr> loggers; public: DECLARE_LOG4CXX_OBJECT(FallbackErrorHandler) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(spi::OptionHandler) LOG4CXX_CAST_ENTRY(spi::ErrorHandler) END_LOG4CXX_CAST_MAP() FallbackErrorHandler(); void addRef() const; void releaseRef() const; /** <em>Adds</em> the logger passed as parameter to the list of loggers that we need to search for in case of appender failure. */ void setLogger(const LoggerPtr& logger); /** No options to activate. */ void activateOptions(log4cxx::helpers::Pool& p); void setOption(const LogString& option, const LogString& value); /** Prints the message and the stack trace of the exception on <code>System.err</code>. */ void error(const LogString& message, const std::exception& e, int errorCode) const; /** Prints the message and the stack trace of the exception on <code>System.err</code>. */ void error(const LogString& message, const std::exception& e, int errorCode, const spi::LoggingEventPtr& event) const; /** Print a the error message passed as parameter on <code>System.err</code>. */ void error(const LogString& /* message */) const {} /** Return the backup appender. */ const AppenderPtr& getBackupAppender() const { return backup; } /** The appender to which this error handler is attached. */ void setAppender(const AppenderPtr& primary); /** Set the backup appender. */ void setBackupAppender(const AppenderPtr& backup); }; } // namespace varia } // namespace log4cxx #endif //_LOG4CXX_VARIA_FALLBACK_ERROR_HANDLER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_ROLLING_FILE_APPENDER_H #define _LOG4CXX_ROLLING_FILE_APPENDER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/rolling/rollingfileappenderskeleton.h> namespace log4cxx { /** RollingFileAppender extends FileAppender to backup the log files when they reach a certain size. */ class LOG4CXX_EXPORT RollingFileAppender : public log4cxx::rolling::RollingFileAppenderSkeleton { private: /** The default maximum file size is 10MB. */ long maxFileSize; /** There is one backup file by default. */ int maxBackupIndex; public: // // Use custom class to use non-default name to avoid // conflict with log4cxx::rolling::RollingFileAppender DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS( RollingFileAppender, ClassRollingFileAppender ) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY( RollingFileAppender ) LOG4CXX_CAST_ENTRY_CHAIN( FileAppender ) END_LOG4CXX_CAST_MAP() /** The default constructor simply calls its {@link FileAppender#FileAppender parents constructor}. */ RollingFileAppender(); /** Instantiate a RollingFileAppender and open the file designated by <code>filename</code>. The opened filename will become the ouput destination for this appender. <p>If the <code>append</code> parameter is true, the file will be appended to. Otherwise, the file desginated by <code>filename</code> will be truncated before being opened. */ RollingFileAppender( const LayoutPtr & layout, const LogString & fileName, bool append ); /** Instantiate a FileAppender and open the file designated by <code>filename</code>. The opened filename will become the output destination for this appender. <p>The file will be appended to. */ RollingFileAppender( const LayoutPtr & layout, const LogString & fileName ); virtual ~RollingFileAppender(); /** Returns the value of the <b>MaxBackupIndex</b> option. */ int getMaxBackupIndex() const; /** Get the maximum size that the output file is allowed to reach before being rolled over to backup files. */ long getMaximumFileSize() const; /** Set the maximum number of backup files to keep around. <p>The <b>MaxBackupIndex</b> option determines how many backup files are kept before the oldest is erased. This option takes a positive integer value. If set to zero, then there will be no backup files and the log file will be truncated when it reaches <code>MaxFileSize</code>. */ void setMaxBackupIndex( int maxBackupIndex ); /** Set the maximum size that the output file is allowed to reach before being rolled over to backup files. <p>In configuration files, the <b>MaxFileSize</b> option takes an long integer in the range 0 - 2^63. You can specify the value with the suffixes "KB", "MB" or "GB" so that the integer is interpreted being expressed respectively in kilobytes, megabytes or gigabytes. For example, the value "10KB" will be interpreted as 10240. */ void setMaxFileSize( const LogString & value ); void setMaximumFileSize( int value ); virtual void setOption( const LogString & option, const LogString & value ); /** Prepares RollingFileAppender for use. */ void activateOptions( log4cxx::helpers::Pool & pool ); }; // class RollingFileAppender LOG4CXX_PTR_DEF(RollingFileAppender); } // namespace log4cxx #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif //_LOG4CXX_ROLLING_FILE_APPENDER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_APPENDER_SKELETON_H #define _LOG4CXX_APPENDER_SKELETON_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/appender.h> #include <log4cxx/layout.h> #include <log4cxx/spi/errorhandler.h> #include <log4cxx/spi/filter.h> #include <log4cxx/helpers/objectimpl.h> #include <log4cxx/helpers/mutex.h> #include <log4cxx/helpers/pool.h> #include <log4cxx/level.h> namespace log4cxx { /** * Implementation base class for all appenders. * * This class provides the code for common functionality, such as * support for threshold filtering and support for general filters. * */ class LOG4CXX_EXPORT AppenderSkeleton : public virtual Appender, public virtual helpers::ObjectImpl { protected: /** The layout variable does not need to be set if the appender implementation has its own layout. */ LayoutPtr layout; /** Appenders are named. */ LogString name; /** There is no level threshold filtering by default. */ LevelPtr threshold; /** It is assumed and enforced that errorHandler is never null. */ spi::ErrorHandlerPtr errorHandler; /** The first filter in the filter chain. Set to <code>null</code> initially. */ spi::FilterPtr headFilter; /** The last filter in the filter chain. */ spi::FilterPtr tailFilter; /** Is this appender closed? */ bool closed; log4cxx::helpers::Pool pool; log4cxx::helpers::Mutex mutex; public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(AppenderSkeleton) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(Appender) LOG4CXX_CAST_ENTRY(spi::OptionHandler) END_LOG4CXX_CAST_MAP() AppenderSkeleton(); AppenderSkeleton(const LayoutPtr& layout); void addRef() const; void releaseRef() const; /** Finalize this appender by calling the derived class' <code>close</code> method. */ void finalize(); /** Derived appenders should override this method if option structure requires it. */ virtual void activateOptions(log4cxx::helpers::Pool& /* pool */) {} virtual void setOption(const LogString& option, const LogString& value); /** Add a filter to end of the filter list. */ void addFilter(const spi::FilterPtr& newFilter) ; /** Subclasses of <code>AppenderSkeleton</code> should implement this method to perform actual logging. See also AppenderSkeleton::doAppend method. */ protected: virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p) = 0; /** Clear the filters chain. */ public: void clearFilters(); /** Return the currently set spi::ErrorHandler for this Appender. */ const spi::ErrorHandlerPtr& getErrorHandler() const { return errorHandler; } /** Returns the head Filter. */ spi::FilterPtr getFilter() const { return headFilter; } /** Return the first filter in the filter chain for this Appender. The return value may be <code>0</code> if no is filter is set. */ const spi::FilterPtr& getFirstFilter() const { return headFilter; } /** Returns the layout of this appender. The value may be 0. */ LayoutPtr getLayout() const { return layout; } /** Returns the name of this Appender. */ LogString getName() const { return name; } /** Returns this appenders threshold level. See the #setThreshold method for the meaning of this option. */ const LevelPtr& getThreshold() { return threshold; } /** Check whether the message level is below the appender's threshold. If there is no threshold set, then the return value is always <code>true</code>. */ bool isAsSevereAsThreshold(const LevelPtr& level) const; /** * This method performs threshold checks and invokes filters before * delegating actual logging to the subclasses specific * AppenderSkeleton#append method. * */ void doAppend(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool); /** Set the {@link spi::ErrorHandler ErrorHandler} for this Appender. */ void setErrorHandler(const spi::ErrorHandlerPtr& eh); /** Set the layout for this appender. Note that some appenders have their own (fixed) layouts or do not use one. For example, the {@link net::SocketAppender SocketAppender} ignores the layout set here. */ void setLayout(const LayoutPtr& layout1) { this->layout = layout1; } /** Set the name of this Appender. */ void setName(const LogString& name1) { this->name.assign(name1); } /** Set the threshold level. All log events with lower level than the threshold level are ignored by the appender. <p>In configuration files this option is specified by setting the value of the <b>Threshold</b> option to a level string, such as "DEBUG", "INFO" and so on. */ void setThreshold(const LevelPtr& threshold); }; // class AppenderSkeleton } // namespace log4cxx #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif //_LOG4CXX_APPENDER_SKELETON_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_MDC_H #define _LOG4CXX_MDC_H #if defined(_MSC_VER) #pragma warning (push) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/log4cxx.h> #include <log4cxx/logstring.h> #include <map> namespace log4cxx { /** The MDC class is similar to the {@link log4cxx::NDC NDC} class except that it is based on a map instead of a stack. It provides <em>mapped diagnostic contexts</em>. A <em>Mapped Diagnostic Context</em>, or MDC in short, is an instrument for distinguishing interleaved log output from different sources. Log output is typically interleaved when a server handles multiple clients near-simultaneously. <p><b><em>The MDC is managed on a per thread basis</em></b>. A child thread automatically inherits a <em>copy</em> of the mapped diagnostic context of its parent. */ class LOG4CXX_EXPORT MDC { public: /** String to string stl map. */ typedef std::map<LogString, LogString> Map; /** * Places a key/value pair in the MDC for the current thread * which will be removed during the corresponding destructor. Both * construction and destruction are expected to be on the same thread. * @param key key * @param value value. */ MDC(const std::string& key, const std::string& value); ~MDC(); /** * Put a context value (the <code>o</code> parameter) as identified * with the <code>key</code> parameter into the current thread's * context map. * * <p>If the current thread does not have a context map it is * created as a side effect. * @param key key * @param value value. */ static void put(const std::string& key, const std::string& value); /** * Put a context value (the <code>o</code> parameter) as identified * with the <code>key</code> parameter into the current thread's * context map. * * <p>If the current thread does not have a context map it is * created as a side effect. * */ static void putLS(const LogString& key, const LogString& value); /** * Get the context identified by the <code>key</code> parameter. * * <p>This method has no side effects. * @param key key. * @return value for key, empty if not set. * */ static std::string get(const std::string& key); /** * Gets the context identified by the <code>key</code> parameter. * @param key context key. * @param dest destination to which value is appended. * @return true if key has associated value. */ static bool get(const LogString& key, LogString& dest); /** * Remove the the context identified by the <code>key</code> * parameter. * @param key key. * @return value if key had been set, empty if not. */ static std::string remove(const std::string& key); #if LOG4CXX_WCHAR_T_API /** * Places a key/value pair in the MDC for the current thread * which will be removed during the corresponding destructor. Both * construction and destruction are expected to be on the same thread. * @param key key * @param value value. */ MDC(const std::wstring& key, const std::wstring& value); /** * Put a context value (the <code>o</code> parameter) as identified * with the <code>key</code> parameter into the current thread's * context map. * * <p>If the current thread does not have a context map it is * created as a side effect. * @param key key * @param value value. */ static void put(const std::wstring& key, const std::wstring& value); /** * Get the context identified by the <code>key</code> parameter. * * <p>This method has no side effects. * @param key key. * @return value for key, empty if not set. * */ static std::wstring get(const std::wstring& key); /** * Remove the the context identified by the <code>key</code> * parameter. * @param key key. * @return value if key had been set, empty if not. */ static std::wstring remove(const std::wstring& key); #endif #if LOG4CXX_UNICHAR_API /** * Places a key/value pair in the MDC for the current thread * which will be removed during the corresponding destructor. Both * construction and destruction are expected to be on the same thread. * @param key key * @param value value. */ MDC(const std::basic_string<UniChar>& key, const std::basic_string<UniChar>& value); /** * Put a context value (the <code>o</code> parameter) as identified * with the <code>key</code> parameter into the current thread's * context map. * * <p>If the current thread does not have a context map it is * created as a side effect. * @param key key * @param value value. */ static void put(const std::basic_string<UniChar>& key, const std::basic_string<UniChar>& value); /** * Get the context identified by the <code>key</code> parameter. * * <p>This method has no side effects. * @param key key. * @return value for key, empty if not set. * */ static std::basic_string<UniChar> get(const std::basic_string<UniChar>& key); /** * Remove the the context identified by the <code>key</code> * parameter. * @param key key. * @return value if key had been set, empty if not. */ static std::basic_string<UniChar> remove(const std::basic_string<UniChar>& key); #endif #if LOG4CXX_CFSTRING_API /** * Places a key/value pair in the MDC for the current thread * which will be removed during the corresponding destructor. Both * construction and destruction are expected to be on the same thread. * @param key key * @param value value. */ MDC(const CFStringRef& key, const CFStringRef& value); /** * Put a context value (the <code>o</code> parameter) as identified * with the <code>key</code> parameter into the current thread's * context map. * * <p>If the current thread does not have a context map it is * created as a side effect. * @param key key * @param value value. */ static void put(const CFStringRef& key, const CFStringRef& value); /** * Get the context identified by the <code>key</code> parameter. * * <p>This method has no side effects. * @param key key. * @return value for key, empty if not set. * */ static CFStringRef get(const CFStringRef& key); /** * Remove the the context identified by the <code>key</code> * parameter. * @param key key. * @return value if key had been set, empty if not. */ static CFStringRef remove(const CFStringRef& key); #endif /** * Remove the the context identified by the <code>key</code> * parameter. * @param key key. * @param prevValue buffer to which previous value is appended. * @return true if key existed in MDC. */ static bool remove(const LogString& key, LogString& prevValue); /** * Clear all entries in the MDC. */ static void clear(); private: MDC(const MDC&); MDC& operator=(const MDC&); LogString key; }; // class MDC; } // namespace log4cxx #if defined(_MSC_VER) #pragma warning (pop) #endif #endif // _LOG4CXX_MDC_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_CONSOLE_APPENDER_H #define _LOG4CXX_CONSOLE_APPENDER_H #include <log4cxx/writerappender.h> namespace log4cxx { /** * ConsoleAppender appends log events to <code>stdout</code> or * <code>stderr</code> using a layout specified by the user. The * default target is <code>stdout</code>. */ class LOG4CXX_EXPORT ConsoleAppender : public WriterAppender { private: LogString target; public: DECLARE_LOG4CXX_OBJECT(ConsoleAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(ConsoleAppender) LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) END_LOG4CXX_CAST_MAP() ConsoleAppender(); ConsoleAppender(const LayoutPtr& layout); ConsoleAppender(const LayoutPtr& layout, const LogString& target); ~ConsoleAppender(); /** * Sets the value of the <b>target</b> property. Recognized values * are "System.out" and "System.err". Any other value will be * ignored. * */ void setTarget(const LogString& value); /** * Returns the current value of the <b>target</b> property. The * default value of the option is "System.out". * * See also #setTarget. * */ LogString getTarget() const; void activateOptions(log4cxx::helpers::Pool& p); void setOption(const LogString& option, const LogString& value); static const LogString& getSystemOut(); static const LogString& getSystemErr(); private: void targetWarn(const LogString& val); static log4cxx::helpers::WriterPtr createWriter(const LogString& target); }; LOG4CXX_PTR_DEF(ConsoleAppender); } //namespace log4cxx #endif //_LOG4CXX_CONSOLE_APPENDER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_DB_ODBC_APPENDER_H #define _LOG4CXX_DB_ODBC_APPENDER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/log4cxx.h> #include <log4cxx/helpers/exception.h> #include <log4cxx/appenderskeleton.h> #include <log4cxx/spi/loggingevent.h> #include <list> namespace log4cxx { namespace db { class LOG4CXX_EXPORT SQLException : public log4cxx::helpers::Exception { public: SQLException(short fHandleType, void* hInput, const char* prolog, log4cxx::helpers::Pool& p); SQLException(const char* msg); SQLException(const SQLException& src); private: const char* formatMessage(short fHandleType, void* hInput, const char* prolog, log4cxx::helpers::Pool& p); }; /** <p><b>WARNING: This version of ODBCAppender is very likely to be completely replaced in the future. Moreoever, it does not log exceptions.</b> </p> The ODBCAppender provides for sending log events to a database. <p>Each append call adds to an <code>ArrayList</code> buffer. When the buffer is filled each log event is placed in a sql statement (configurable) and executed. <b>BufferSize</b>, <b>db URL</b>, <b>User</b>, & <b>Password</b> are configurable options in the standard log4j ways. <p>The <code>setSql(String sql)</code> sets the SQL statement to be used for logging -- this statement is sent to a <code>PatternLayout</code> (either created automaticly by the appender or added by the user). Therefore by default all the conversion patterns in <code>PatternLayout</code> can be used inside of the statement. (see the test cases for examples) <p>Overriding the {@link #getLogStatement} method allows more explicit control of the statement used for logging. <p>For use as a base class: <ul> <li>Override getConnection() to pass any connection you want. Typically this is used to enable application wide connection pooling. <li>Override closeConnection -- if you override getConnection make sure to implement <code>closeConnection</code> to handle the connection you generated. Typically this would return the connection to the pool it came from. <li>Override getLogStatement to produce specialized or dynamic statements. The default uses the sql option value. </ul> */ class LOG4CXX_EXPORT ODBCAppender : public AppenderSkeleton { protected: /** * URL of the DB for default connection handling */ LogString databaseURL; /** * User to connect as for default connection handling */ LogString databaseUser; /** * User to use for default connection handling */ LogString databasePassword; typedef void* SQLHDBC; typedef void* SQLHENV; typedef void* SQLHANDLE; typedef short SQLSMALLINT; /** * Connection used by default. The connection is opened the first time it * is needed and then held open until the appender is closed (usually at * garbage collection). This behavior is best modified by creating a * sub-class and overriding the <code>getConnection</code> and * <code>closeConnection</code> methods. */ SQLHDBC connection; SQLHENV env; /** * Stores the string given to the pattern layout for conversion into a SQL * statement, eg: insert into LogTable (Thread, File, Message) values * ("%t", "%F", "%m") * * Be careful of quotes in your messages! * * Also see PatternLayout. */ LogString sqlStatement; /** * size of LoggingEvent buffer before writing to the database. * Default is 1. */ size_t bufferSize; /** * ArrayList holding the buffer of Logging Events. */ std::list<spi::LoggingEventPtr> buffer; public: DECLARE_LOG4CXX_OBJECT(ODBCAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(ODBCAppender) LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) END_LOG4CXX_CAST_MAP() ODBCAppender(); virtual ~ODBCAppender(); /** Set options */ virtual void setOption(const LogString& option, const LogString& value); /** Activate the specified options. */ virtual void activateOptions(log4cxx::helpers::Pool& p); /** * Adds the event to the buffer. When full the buffer is flushed. */ void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool&); /** * By default getLogStatement sends the event to the required Layout object. * The layout will format the given pattern into a workable SQL string. * * Overriding this provides direct access to the LoggingEvent * when constructing the logging statement. * */ protected: LogString getLogStatement(const spi::LoggingEventPtr& event, helpers::Pool& p) const; /** * * Override this to provide an alertnate method of getting * connections (such as caching). One method to fix this is to open * connections at the start of flushBuffer() and close them at the * end. I use a connection pool outside of ODBCAppender which is * accessed in an override of this method. * */ virtual void execute(const LogString& sql, log4cxx::helpers::Pool& p) /*throw(SQLException)*/; /** * Override this to return the connection to a pool, or to clean up the * resource. * * The default behavior holds a single connection open until the appender * is closed (typically when garbage collected). */ virtual void closeConnection(SQLHDBC con); /** * Override this to link with your connection pooling system. * * By default this creates a single connection which is held open * until the object is garbage collected. */ virtual SQLHDBC getConnection(log4cxx::helpers::Pool& p) /*throw(SQLException)*/; /** * Closes the appender, flushing the buffer first then closing the default * connection if it is open. */ public: virtual void close(); /** * loops through the buffer of LoggingEvents, gets a * sql string from getLogStatement() and sends it to execute(). * Errors are sent to the errorHandler. * * If a statement fails the LoggingEvent stays in the buffer! */ virtual void flushBuffer(log4cxx::helpers::Pool& p); /** * ODBCAppender requires a layout. * */ virtual bool requiresLayout() const { return true; } /** * Set pre-formated statement eg: insert into LogTable (msg) values ("%m") */ void setSql(const LogString& s); /** * Returns pre-formated statement eg: insert into LogTable (msg) values ("%m") */ inline const LogString& getSql() const { return sqlStatement; } inline void setUser(const LogString& user) { databaseUser = user; } inline void setURL(const LogString& url) { databaseURL = url; } inline void setPassword(const LogString& password) { databasePassword = password; } inline void setBufferSize(size_t newBufferSize) { bufferSize = newBufferSize; } inline const LogString& getUser() const { return databaseUser; } inline const LogString& getURL() const { return databaseURL; } inline const LogString& getPassword() const { return databasePassword; } inline size_t getBufferSize() const { return bufferSize; } private: ODBCAppender(const ODBCAppender&); ODBCAppender& operator=(const ODBCAppender&); }; // class ODBCAppender LOG4CXX_PTR_DEF(ODBCAppender); } // namespace db } // namespace log4cxx #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif // _LOG4CXX_DB_ODBC_APPENDER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_STREAM_H #define _LOG4CXX_STREAM_H #include <log4cxx/logger.h> #include <sstream> #include <log4cxx/spi/location/locationinfo.h> namespace log4cxx { /** * Base class for the basic_logstream template which attempts * to emulate std::basic_ostream but attempts to short-circuit * unnecessary operations. * * The logstream has a logger and level that are used for logging * requests. The level of the stream is compared against the * current level of the logger to determine if the request should be processed. */ class LOG4CXX_EXPORT logstream_base { public: /** * Create new instance. * @param logger logger logger used in log requests. * @param level indicates level that will be used in log requests. Can * be modified later by inserting a level or calling setLevel. */ logstream_base(const log4cxx::LoggerPtr& logger, const log4cxx::LevelPtr& level); /** * Destructor. */ virtual ~logstream_base(); /** * Insertion operator for std::fixed and similar manipulators. */ void insert(std::ios_base& (*manip)(std::ios_base&)); /** * get precision. */ int precision(); /** * get width. */ int width(); /** * set precision. This should be used in preference to inserting an std::setprecision(n) * since the other requires construction of an STL stream which may be expensive. */ int precision(int newval); /** * set width. This should be used in preference to inserting an std::setw(n) * since the other requires construction of an STL stream which may be expensive. */ int width(int newval); /** * Get fill character. */ int fill(); /** * Set fill character. */ int fill(int newval); /** * Set flags. see std::ios_base. */ std::ios_base::fmtflags flags(std::ios_base::fmtflags newflags); /** * Set flags. see std::ios_base. */ std::ios_base::fmtflags setf(std::ios_base::fmtflags newflags, std::ios_base::fmtflags mask); /** * Set flags. see std::ios_base. */ std::ios_base::fmtflags setf(std::ios_base::fmtflags newflags); /** * end of message manipulator, triggers logging. */ static logstream_base& endmsg(logstream_base&); /** * no-operation manipulator, Used to avoid ambiguity with VC6. */ static logstream_base& nop(logstream_base&); /** * end of message action. */ void end_message(); /** * Set the level. * @param level level */ void setLevel(const LevelPtr& level); /** * Returns true if the current level is the same or high as the * level of logger at time of construction or last setLevel. */ inline bool isEnabled() const { return enabled; } /** * Returns if logger is currently enabled for the specified level. */ bool isEnabledFor(const LevelPtr& level) const; /** * Sets the location for subsequent log requests. */ void setLocation(const log4cxx::spi::LocationInfo& location); /** * Sets the state of the embedded stream (if any) * to the state of the formatting info. * @param os stream to receive formatting info. * @param fillchar receives fill charater. * @return true if fill character was specified. */ bool set_stream_state(std::ios_base& os, int& fillchar); protected: /** * Dispatches the pending log request. */ virtual void log(LoggerPtr& logger, const LevelPtr& level, const log4cxx::spi::LocationInfo& location) = 0; /** * Erase any content in the message construction buffer. */ virtual void erase() = 0; /** * Copy state of embedded stream (if any) * to value and mask instances of std::ios_base * and return fill character value. */ virtual void get_stream_state(std::ios_base& base, std::ios_base& mask, int& fill, bool& fillSet) const = 0; virtual void refresh_stream_state() = 0; private: /** * prevent copy constructor. */ logstream_base(logstream_base&); /** * prevent copy operatpr. */ logstream_base& operator=(logstream_base&); /** * Minimal extension of std::ios_base to allow creation * of embedded IO states. */ class LOG4CXX_EXPORT logstream_ios_base : public std::ios_base { public: logstream_ios_base(std::ios_base::fmtflags initval, int initsize); } initset, initclear; /** * fill character. */ int fillchar; /** * true if fill character is set. */ bool fillset; /** * true if assigned level was same or higher than level of associated logger. */ bool enabled; /** * associated logger. */ log4cxx::LoggerPtr logger; /** * associated level. */ log4cxx::LevelPtr level; /** * associated level. */ log4cxx::spi::LocationInfo location; }; typedef logstream_base& (*logstream_manipulator)(logstream_base&); /** * An STL-like stream API for log4cxx using char as the character type. *. Instances of log4cxx::logstream * are not designedfor use by multiple threads and in general should be short-lived * function scoped objects. Using log4cxx::basic_logstream as a class member or * static instance should be avoided in the same manner as you would avoid placing a std::ostringstream * in those locations. Insertion operations are generally short-circuited if the * level for the stream is not the same of higher that the level of the associated logger. */ class LOG4CXX_EXPORT logstream : public logstream_base { typedef char Ch; public: /** * Constructor. */ logstream(const log4cxx::LoggerPtr& logger, const log4cxx::LevelPtr& level); /** * Constructor. */ logstream(const Ch* loggerName, const log4cxx::LevelPtr& level); /** * Constructor. */ logstream(const std::basic_string<Ch>& loggerName, const log4cxx::LevelPtr& level); ~logstream(); /** * Insertion operator for std::fixed and similar manipulators. */ logstream& operator<<(std::ios_base& (*manip)(std::ios_base&)); /** * Insertion operator for logstream_base::endmsg. */ logstream& operator<<(logstream_manipulator manip); /** * Insertion operator for level. */ logstream& operator<<(const log4cxx::LevelPtr& level); /** * Insertion operator for location. */ logstream& operator<<(const log4cxx::spi::LocationInfo& location); /** * Alias for insertion operator for location. Kludge to avoid * inappropriate compiler ambiguity. */ logstream& operator>>(const log4cxx::spi::LocationInfo& location); /** * Cast operator to provide access to embedded std::basic_ostream. */ operator std::basic_ostream<Ch>&(); #if !(LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE) /** * Template to allow any class with an std::basic_ostream inserter * to be applied to this class. */ template <class V> inline log4cxx::logstream& operator<<(const V& val) { if (LOG4CXX_UNLIKELY(isEnabled())) { ((std::basic_ostream<char>&) *this) << val; } return *this; } #endif protected: virtual void log(LoggerPtr& logger, const LevelPtr& level, const log4cxx::spi::LocationInfo& location); virtual void erase(); virtual void get_stream_state(std::ios_base& base, std::ios_base& mask, int& fill, bool& fillSet) const; virtual void refresh_stream_state(); private: logstream(const logstream&); logstream& operator=(const logstream&); std::basic_stringstream<Ch>* stream; }; #if LOG4CXX_WCHAR_T_API /** * An STL-like stream API for log4cxx using wchar_t as the character type. *. Instances of log4cxx::logstream * are not designedfor use by multiple threads and in general should be short-lived * function scoped objects. Using log4cxx::basic_logstream as a class member or * static instance should be avoided in the same manner as you would avoid placing a std::ostringstream * in those locations. Insertion operations are generally short-circuited if the * level for the stream is not the same of higher that the level of the associated logger. */ class LOG4CXX_EXPORT wlogstream : public logstream_base { typedef wchar_t Ch; public: /** * Constructor. */ wlogstream(const log4cxx::LoggerPtr& logger, const log4cxx::LevelPtr& level); /** * Constructor. */ wlogstream(const Ch* loggerName, const log4cxx::LevelPtr& level); /** * Constructor. */ wlogstream(const std::basic_string<Ch>& loggerName, const log4cxx::LevelPtr& level); ~wlogstream(); /** * Insertion operator for std::fixed and similar manipulators. */ wlogstream& operator<<(std::ios_base& (*manip)(std::ios_base&)); /** * Insertion operator for logstream_base::endmsg. */ wlogstream& operator<<(logstream_manipulator manip); /** * Insertion operator for level. */ wlogstream& operator<<(const log4cxx::LevelPtr& level); /** * Insertion operator for location. */ wlogstream& operator<<(const log4cxx::spi::LocationInfo& location); /** * Alias for insertion operator for location. Kludge to avoid * inappropriate compiler ambiguity. */ wlogstream& operator>>(const log4cxx::spi::LocationInfo& location); /** * Cast operator to provide access to embedded std::basic_ostream. */ operator std::basic_ostream<Ch>&(); #if !(LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE) /** * Template to allow any class with an std::basic_ostream inserter * to be applied to this class. */ template <class V> inline log4cxx::wlogstream& operator<<(const V& val) { if (LOG4CXX_UNLIKELY(isEnabled())) { ((std::basic_ostream<wchar_t>&) *this) << val; } return *this; } #endif protected: virtual void log(LoggerPtr& logger, const LevelPtr& level, const log4cxx::spi::LocationInfo& location); virtual void erase(); virtual void get_stream_state(std::ios_base& base, std::ios_base& mask, int& fill, bool& fillSet) const; virtual void refresh_stream_state(); private: wlogstream(const wlogstream&); wlogstream& operator=(const wlogstream&); std::basic_stringstream<Ch>* stream; }; #endif #if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API /** * An STL-like stream API for log4cxx using UniChar as the character type. *. Instances of log4cxx::logstream * are not designedfor use by multiple threads and in general should be short-lived * function scoped objects. Using log4cxx::basic_logstream as a class member or * static instance should be avoided in the same manner as you would avoid placing a std::ostringstream * in those locations. Insertion operations are generally short-circuited if the * level for the stream is not the same of higher that the level of the associated logger. */ class LOG4CXX_EXPORT ulogstream : public logstream_base { typedef UniChar Ch; public: /** * Constructor. */ ulogstream(const log4cxx::LoggerPtr& logger, const log4cxx::LevelPtr& level); #if LOG4CXX_UNICHAR_API /** * Constructor. */ ulogstream(const Ch* loggerName, const log4cxx::LevelPtr& level); /** * Constructor. */ ulogstream(const std::basic_string<Ch>& loggerName, const log4cxx::LevelPtr& level); #endif #if LOG4CXX_CFSTRING_API ulogstream(const CFStringRef& loggerName, const log4cxx::LevelPtr& level); #endif ~ulogstream(); /** * Insertion operator for std::fixed and similar manipulators. */ ulogstream& operator<<(std::ios_base& (*manip)(std::ios_base&)); /** * Insertion operator for logstream_base::endmsg. */ ulogstream& operator<<(logstream_manipulator manip); /** * Insertion operator for level. */ ulogstream& operator<<(const log4cxx::LevelPtr& level); /** * Insertion operator for location. */ ulogstream& operator<<(const log4cxx::spi::LocationInfo& location); /** * Alias for insertion operator for location. Kludge to avoid * inappropriate compiler ambiguity. */ ulogstream& operator>>(const log4cxx::spi::LocationInfo& location); /** * Cast operator to provide access to embedded std::basic_ostream. */ operator std::basic_ostream<Ch>&(); #if !(LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE) /** * Template to allow any class with an std::basic_ostream inserter * to be applied to this class. */ template <class V> inline ulogstream& operator<<(const V& val) { if (LOG4CXX_UNLIKELY(isEnabled())) { ((std::basic_ostream<Ch>&) *this) << val; } return *this; } #endif protected: virtual void log(LoggerPtr& logger, const LevelPtr& level, const log4cxx::spi::LocationInfo& location); virtual void erase(); virtual void get_stream_state(std::ios_base& base, std::ios_base& mask, int& fill, bool& fillSet) const; virtual void refresh_stream_state(); private: ulogstream(const ulogstream&); ulogstream& operator=(const ulogstream&); std::basic_stringstream<Ch>* stream; }; #endif } // namespace log4cxx #if LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE // // VC6 will fail to compile if class-scope templates // are used to handle arbitrary insertion operations. // However, using global namespace insertion operations // run into LOGCXX-150. /** * Template to allow any class with an std::basic_ostream inserter * to be applied to this class. */ template <class V> inline log4cxx::logstream& operator<<(log4cxx::logstream& os, const V& val) { if (LOG4CXX_UNLIKELY(os.isEnabled())) { ((std::basic_ostream<char>&) os) << val; } return os; } #if LOG4CXX_WCHAR_T_API /** * Template to allow any class with an std::basic_ostream inserter * to be applied to this class. */ template <class V> inline log4cxx::wlogstream& operator<<(log4cxx::wlogstream& os, const V& val) { if (LOG4CXX_UNLIKELY(os.isEnabled())) { ((std::basic_ostream<wchar_t>&) os) << val; } return os; } #endif #endif #if !defined(LOG4CXX_ENDMSG) #if LOG4CXX_LOGSTREAM_ADD_NOP #define LOG4CXX_ENDMSG (log4cxx::logstream_manipulator) log4cxx::logstream_base::nop >> LOG4CXX_LOCATION << (log4cxx::logstream_manipulator) log4cxx::logstream_base::endmsg #else #define LOG4CXX_ENDMSG LOG4CXX_LOCATION << (log4cxx::logstream_manipulator) log4cxx::logstream_base::endmsg #endif #endif #endif //_LOG4CXX_STREAM_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_SIMPLE_LAYOUT_H #define _LOG4CXX_SIMPLE_LAYOUT_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/layout.h> namespace log4cxx { /** SimpleLayout consists of the level of the log statement, followed by " - " and then the log message itself. For example, <pre> DEBUG - Hello world </pre> <p> <p>PatternLayout offers a much more powerful alternative. */ class LOG4CXX_EXPORT SimpleLayout : public Layout { public: DECLARE_LOG4CXX_OBJECT(SimpleLayout) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(SimpleLayout) LOG4CXX_CAST_ENTRY_CHAIN(Layout) END_LOG4CXX_CAST_MAP() /** Returns the log statement in a format consisting of the <code>level</code>, followed by " - " and then the <code>message</code>. For example, <pre> INFO - "A message" </pre> @return A byte array in SimpleLayout format. */ virtual void format(LogString& output, const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool) const; /** The SimpleLayout does not handle the throwable contained within {@link spi::LoggingEvent LoggingEvents}. Thus, it returns <code>true</code>. */ bool ignoresThrowable() const { return true; } virtual void activateOptions(log4cxx::helpers::Pool& /* p */) {} virtual void setOption(const LogString& /* option */, const LogString& /* value */) {} }; LOG4CXX_PTR_DEF(SimpleLayout); } // namespace log4cxx #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif //_LOG4CXX_SIMPLE_LAYOUT_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_NDC_H #define _LOG4CXX_NDC_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/log4cxx.h> #include <log4cxx/logstring.h> #include <stack> namespace log4cxx { /** 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. <p>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. <p>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. <p><em><b>note that ndcs are managed on a per thread basis</b></em>. ndc operations such as #push, #pop, #clear and #getDepth affect the ndc of the <em>current</em> thread only. ndcs of other threads remain unaffected. <p>for example, a servlet 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 #push operation. simply put, <p><ul> <li>contexts can be nested. <p><li>when entering a context, call <code>ndc.push</code>. as a side effect, if there is no nested diagnostic context for the current thread, this method will create it. <p><li>when leaving a context, call <code>ndc.pop</code>. <p><li><b>when exiting a thread make sure to call #remove </b>. </ul> <p>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. <p>if configured to do so, PatternLayout and TTCCLayout instances automatically retrieve the nested diagnostic context for the current thread without any user intervention. hence, even if a servlet 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. <p>heavy duty systems should call the #remove method when leaving the run method of a thread. this ensures that the memory used by the thread can be freed by the java garbage collector. there is a mechanism to lazily remove references to dead threads. in practice, this means that you can be a little sloppy and sometimes forget to call #remove before exiting a thread. */ class LOG4CXX_EXPORT NDC { public: /** * Pair of Message and FullMessage. */ typedef std::pair<LogString, LogString> DiagnosticContext; typedef std::stack<DiagnosticContext> Stack; /** Creates a nested diagnostic context. Since java performs no automatic cleanup of objects when a scope is left, in log4j push() and pop() must be used to manage the NDC. For convenience, log4cxx provides an NDC constructor and destructor which simply call the push() and pop() methods, allowing for automatic cleanup when the current scope ends. @param message The new diagnostic context information. @see The #push method. */ NDC(const std::string& message); /** Removes the topmost element from the NDC stack. @see The #pop method. */ ~NDC(); /** 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. */ static void clear(); /** Clone the diagnostic context for the current thread. <p>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. <p>The child thread uses the #inherit method to inherit the parent's diagnostic context. <p>If not passed to #inherit, returned stack should be deleted by caller. @return Stack A clone of the current thread's diagnostic context, will not be null. */ static Stack * cloneStack(); /** Inherit the diagnostic context of another thread. <p>The parent thread can obtain a reference to its diagnostic context using the #cloneStack method. It should communicate this information to its child so that it may inherit the parent's diagnostic context. <p>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, will be deleted during call. If NULL, NDC will not be modified. */ static void inherit(Stack * stack); /** * Get the current value of the NDC of the * currrent thread. * @param dest destination to which to append content of NDC. * @return true if NDC is set. */ static bool get(LogString& dest); /** Get the current nesting depth of this diagnostic context. */ static int getDepth(); /** * Tests if the NDC is empty. */ static bool empty(); /** Pop top value off stack. @return top value. */ static LogString pop(); /** Pop top value off stack. @param buf to which top value is appended. @return true if NDC contained at least one value. */ static bool pop(std::string& buf); /** Looks at the last diagnostic context at the top of this NDC without removing it. <p>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. */ static LogString peek(); /** Get top value without removing value. @param buf to which top value is appended. @return true if NDC contained at least one value. */ static bool peek(std::string& buf); /** Push new diagnostic context information for the current thread. <p>The contents of the <code>message</code> parameter is determined solely by the client. @param message The new diagnostic context information. */ static void push(const std::string& message); /** Push new diagnostic context information for the current thread. <p>The contents of the <code>message</code> parameter is determined solely by the client. @param message The new diagnostic context information. */ static void pushLS(const LogString& message); /** Remove the diagnostic context for this thread. <p>Each thread that created a diagnostic context by calling #push should call this method before exiting. Otherwise, the memory used by the <b>thread</b> cannot be reclaimed by the VM. <p>As this is such an important problem in heavy duty systems and because it is difficult to always guarantee that the remove method is called before exiting a thread, this method has been augmented to lazily remove references to dead threads. In practice, this means that you can be a little sloppy and occasionally forget to call #remove before exiting a thread. However, you must call <code>remove</code> sometime. If you never call it, then your application is sure to run out of memory. */ static void remove(); #if LOG4CXX_WCHAR_T_API /** Creates a nested diagnostic context. Since java performs no automatic cleanup of objects when a scope is left, in log4j push() and pop() must be used to manage the NDC. For convenience, log4cxx provides an NDC constructor and destructor which simply call the push() and pop() methods, allowing for automatic cleanup when the current scope ends. @param message The new diagnostic context information. @see The #push method. */ NDC(const std::wstring& message); /** Push new diagnostic context information for the current thread. <p>The contents of the <code>message</code> parameter is determined solely by the client. @param message The new diagnostic context information. */ static void push(const std::wstring& message); /** * Appends the current NDC content to the provided string. * @param dst destination. * @return true if NDC value set. */ static bool peek(std::wstring& dst); /** * Appends the current NDC content to the provided string and removes the value from the NDC. * @param dst destination. * @return true if NDC value set. */ static bool pop(std::wstring& dst); #endif #if LOG4CXX_UNICHAR_API /** Creates a nested diagnostic context. Since java performs no automatic cleanup of objects when a scope is left, in log4j push() and pop() must be used to manage the NDC. For convenience, log4cxx provides an NDC constructor and destructor which simply call the push() and pop() methods, allowing for automatic cleanup when the current scope ends. @param message The new diagnostic context information. @see The #push method. */ NDC(const std::basic_string<UniChar>& message); /** Push new diagnostic context information for the current thread. <p>The contents of the <code>message</code> parameter is determined solely by the client. @param message The new diagnostic context information. */ static void push(const std::basic_string<UniChar>& message); /** * Appends the current NDC content to the provided string. * @param dst destination. * @return true if NDC value set. */ static bool peek(std::basic_string<UniChar>& dst); /** * Appends the current NDC content to the provided string and removes the value from the NDC. * @param dst destination. * @return true if NDC value set. */ static bool pop(std::basic_string<UniChar>& dst); #endif #if LOG4CXX_CFSTRING_API /** Creates a nested diagnostic context. Since java performs no automatic cleanup of objects when a scope is left, in log4j push() and pop() must be used to manage the NDC. For convenience, log4cxx provides an NDC constructor and destructor which simply call the push() and pop() methods, allowing for automatic cleanup when the current scope ends. @param message The new diagnostic context information. @see The #push method. */ NDC(const CFStringRef& message); /** Push new diagnostic context information for the current thread. <p>The contents of the <code>message</code> parameter is determined solely by the client. @param message The new diagnostic context information. */ static void push(const CFStringRef& message); /** * Gets the current NDC value. * @param dst destination. * @return true if NDC value set. */ static bool peek(CFStringRef& dst); /** * Gets and removes the current NDC value. * @param dst destination. * @return true if NDC value set. */ static bool pop(CFStringRef& dst); #endif private: NDC(const NDC&); NDC& operator=(const NDC&); static LogString& getMessage(DiagnosticContext& ctx); static LogString& getFullMessage(DiagnosticContext& ctx); }; // class NDC; } // namespace log4cxx #if defined(_MSC_VER) #pragma warning (pop) #endif #endif // _LOG4CXX_NDC_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_WRITER_APPENDER_H #define _LOG4CXX_WRITER_APPENDER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/appenderskeleton.h> #include <log4cxx/helpers/outputstreamwriter.h> namespace log4cxx { namespace helpers { class Transcoder; } /** WriterAppender appends log events to a standard output stream */ class LOG4CXX_EXPORT WriterAppender : public AppenderSkeleton { private: /** 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. <p>The <code>immediateFlush</code> variable is set to <code>true</code> by default. */ bool immediateFlush; /** The encoding to use when opening an input stream. <p>The <code>encoding</code> variable is set to <code>""</code> by default which results in the utilization of the system's default encoding. */ LogString encoding; /** * This is the {@link Writer Writer} where we will write to. */ log4cxx::helpers::WriterPtr writer; public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(WriterAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(WriterAppender) LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) END_LOG4CXX_CAST_MAP() /** This default constructor does nothing.*/ WriterAppender(); protected: WriterAppender(const LayoutPtr& layout, log4cxx::helpers::WriterPtr& writer); WriterAppender(const LayoutPtr& layout); public: ~WriterAppender(); /** Derived appenders should override this method if option structure requires it. */ virtual void activateOptions(log4cxx::helpers::Pool& pool); /** If the <b>ImmediateFlush</b> option is set to <code>true</code>, the appender will flush at the end of each write. This is the default behavior. If the option is set to <code>false</code>, then the underlying stream can defer writing to physical medium to a later time. <p>Avoiding the flush operation at the end of each append results in a performance gain of 10 to 20 percent. However, there is safety tradeoff involved in skipping flushing. Indeed, when flushing is skipped, then it is likely that the last few log events will not be recorded on disk when the application exits. This is a high price to pay even for a 20% performance gain. */ void setImmediateFlush(bool value); /** Returns value of the <b>ImmediateFlush</b> option. */ bool getImmediateFlush() const { return immediateFlush; } /** This method is called by the AppenderSkeleton#doAppend method. <p>If the output stream exists and is writable then write a log statement to the output stream. Otherwise, write a single warning message to <code>stderr</code>. <p>The format of the output will depend on this appender's layout. */ virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p); protected: /** This method determines if there is a sense in attempting to append. <p>It checks whether there is a set output target and also if there is a set layout. If these checks fail, then the boolean value <code>false</code> is returned. */ virtual bool checkEntryConditions() const; public: /** Close this appender instance. The underlying stream or writer is also closed. <p>Closed appenders cannot be reused. */ virtual void close(); protected: /** * Close the underlying {@link log4cxx::helpers::Writer}. * */ void closeWriter(); /** Returns an OutputStreamWriter when passed an OutputStream. The encoding used will depend on the value of the <code>encoding</code> property. If the encoding value is specified incorrectly the writer will be opened using the default system encoding (an error message will be printed to the loglog. */ virtual log4cxx::helpers::WriterPtr createWriter( log4cxx::helpers::OutputStreamPtr& os); public: LogString getEncoding() const; void setEncoding(const LogString& value); void setOption(const LogString& option, const LogString& value); /** <p>Sets the Writer where the log output will go. The specified Writer must be opened by the user and be writable. <p>The <code>java.io.Writer</code> will be closed when the appender instance is closed. <p><b>WARNING:</b> Logging to an unopened Writer will fail. <p> @param writer An already opened Writer. */ void setWriter(const log4cxx::helpers::WriterPtr& writer); virtual bool requiresLayout() const; protected: /** Actual writing occurs here. */ virtual void subAppend(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p); /** Write a footer as produced by the embedded layout's Layout#appendFooter method. */ virtual void writeFooter(log4cxx::helpers::Pool& p); /** Write a header as produced by the embedded layout's Layout#appendHeader method. */ virtual void writeHeader(log4cxx::helpers::Pool& p); private: // // prevent copy and assignment WriterAppender(const WriterAppender&); WriterAppender& operator=(const WriterAppender&); }; LOG4CXX_PTR_DEF(WriterAppender); } //namespace log4cxx #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif //_LOG4CXX_WRITER_APPENDER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_LEVEL_H #define _LOG4CXX_LEVEL_H #include <log4cxx/logstring.h> #include <limits.h> #include <log4cxx/helpers/objectimpl.h> #include <log4cxx/helpers/objectptr.h> namespace log4cxx { class Level; /** smart pointer to a Level instance */ LOG4CXX_PTR_DEF(Level); /** Defines the minimum set of levels recognized by the system, that is <code>OFF</code>, <code>FATAL</code>, <code>ERROR</code>, <code>WARN</code>, <code>INFO</code>, <code>DEBUG</code> and <code>ALL</code>. <p>The <code>Level</code> class may be subclassed to define a larger level set. */ class LOG4CXX_EXPORT Level : public helpers::ObjectImpl { public: class LOG4CXX_EXPORT LevelClass : public helpers::Class { public: LevelClass() : helpers::Class() {} virtual LogString getName() const { return LOG4CXX_STR("Level"); } virtual LevelPtr toLevel(const LogString& sArg) const { return Level::toLevelLS(sArg); } virtual LevelPtr toLevel(int val) const { return Level::toLevel(val); } }; DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(Level, LevelClass) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(Level) END_LOG4CXX_CAST_MAP() /** Instantiate a Level object. */ Level(int level, const LogString& name, int syslogEquivalent); /** Convert the string passed as argument to a level. If the conversion fails, then this method returns DEBUG. * @param sArg level name. */ static LevelPtr toLevel(const std::string& sArg); /** Convert the string passed as argument to a level. If the conversion fails, then this method returns the value of <code>defaultLevel</code>. * @param sArg level name. * @param defaultLevel level to return if no match. * @return */ static LevelPtr toLevel(const std::string& sArg, const LevelPtr& defaultLevel); /** * Get the name of the level in the current encoding. * @param name buffer to which name is appended. */ void toString(std::string& name) const; #if LOG4CXX_WCHAR_T_API /** Convert the string passed as argument to a level. If the conversion fails, then this method returns DEBUG. * @param sArg level name. */ static LevelPtr toLevel(const std::wstring& sArg); /** Convert the string passed as argument to a level. If the conversion fails, then this method returns the value of <code>defaultLevel</code>. * @param sArg level name. * @param defaultLevel level to return if no match. * @return */ static LevelPtr toLevel(const std::wstring& sArg, const LevelPtr& defaultLevel); /** * Get the name of the level. * @param name buffer to which name is appended. */ void toString(std::wstring& name) const; #endif #if LOG4CXX_UNICHAR_API /** Convert the string passed as argument to a level. If the conversion fails, then this method returns DEBUG. * @param sArg level name. */ static LevelPtr toLevel(const std::basic_string<UniChar>& sArg); /** Convert the string passed as argument to a level. If the conversion fails, then this method returns the value of <code>defaultLevel</code>. * @param sArg level name. * @param defaultLevel level to return if no match. * @return */ static LevelPtr toLevel(const std::basic_string<UniChar>& sArg, const LevelPtr& defaultLevel); /** * Get the name of the level. * @param name buffer to which name is appended. */ void toString(std::basic_string<UniChar>& name) const; #endif #if LOG4CXX_CFSTRING_API /** Convert the string passed as argument to a level. If the conversion fails, then this method returns DEBUG. * @param sArg level name. */ static LevelPtr toLevel(const CFStringRef& sArg); /** Convert the string passed as argument to a level. If the conversion fails, then this method returns the value of <code>defaultLevel</code>. * @param sArg level name. * @param defaultLevel level to return if no match. * @return */ static LevelPtr toLevel(const CFStringRef& sArg, const LevelPtr& defaultLevel); /** * Get the name of the level. * @param name buffer to which name is appended. */ void toString(CFStringRef& name) const; #endif /** Convert the string passed as argument to a level. If the conversion fails, then this method returns DEBUG. * @param sArg level name. */ static LevelPtr toLevelLS(const LogString& sArg); /** Convert the string passed as argument to a level. If the conversion fails, then this method returns the value of <code>defaultLevel</code>. * @param sArg level name. * @param defaultLevel level to return if no match. * @return */ static LevelPtr toLevelLS(const LogString& sArg, const LevelPtr& defaultLevel); /** Returns the string representation of this level. * @return level name. */ LogString toString() const; /** Convert an integer passed as argument to a level. If the conversion fails, then this method returns DEBUG. */ static LevelPtr toLevel(int val); /** Convert an integer passed as argument to a level. If the conversion fails, then this method returns the specified default. */ static LevelPtr toLevel(int val, const LevelPtr& defaultLevel); enum { OFF_INT = INT_MAX, FATAL_INT = 50000, ERROR_INT = 40000, WARN_INT = 30000, INFO_INT = 20000, DEBUG_INT = 10000, TRACE_INT = 5000, ALL_INT = INT_MIN }; static LevelPtr getAll(); static LevelPtr getFatal(); static LevelPtr getError(); static LevelPtr getWarn(); static LevelPtr getInfo(); static LevelPtr getDebug(); static LevelPtr getTrace(); static LevelPtr getOff(); /** Two levels are equal if their level fields are equal. */ virtual bool equals(const LevelPtr& level) const; inline bool operator==(const Level& level1) const { return (this->level == level1.level); } inline bool operator!=(const Level& level1) const { return (this->level != level1.level); } /** Return the syslog equivalent of this level as an integer. */ inline int getSyslogEquivalent() const { return syslogEquivalent; } /** Returns <code>true</code> if this level has a higher or equal level than the level passed as argument, <code>false</code> otherwise. <p>You should think twice before overriding the default implementation of <code>isGreaterOrEqual</code> method. */ virtual bool isGreaterOrEqual(const LevelPtr& level) const; /** Returns the integer representation of this level. */ inline int toInt() const { return level; } private: int level; LogString name; int syslogEquivalent; Level(const Level&); Level& operator=(const Level&); }; } #define DECLARE_LOG4CXX_LEVEL(level)\ public:\ class Class##level : public Level::LevelClass\ {\ public:\ Class##level() : Level::LevelClass() {}\ virtual LogString getName() const { return LOG4CXX_STR(#level); } \ virtual LevelPtr toLevel(const LogString& sArg) const\ { return level::toLevelLS(sArg); }\ virtual LevelPtr toLevel(int val) const\ { return level::toLevel(val); }\ };\ DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(level, Class##level) #define IMPLEMENT_LOG4CXX_LEVEL(level) \ IMPLEMENT_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(level, Class##level) #endif //_LOG4CXX_LEVEL_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_ROLLING_POLICY_H) #define _LOG4CXX_ROLLING_ROLLING_POLICY_H #include <log4cxx/portability.h> #include <log4cxx/spi/optionhandler.h> #include <log4cxx/rolling/rolloverdescription.h> #include <log4cxx/file.h> namespace log4cxx { namespace rolling { /** * A <code>RollingPolicy</code> is responsible for performing the * rolling over of the active log file. The <code>RollingPolicy</code> * is also responsible for providing the <em>active log file</em>, * that is the live file where logging output will be directed. * * * * */ class LOG4CXX_EXPORT RollingPolicy : public virtual spi::OptionHandler { DECLARE_ABSTRACT_LOG4CXX_OBJECT(RollingPolicy) public: virtual ~RollingPolicy() {} /** * Initialize the policy and return any initial actions for rolling file appender. * * @param file current value of RollingFileAppender.getFile(). * @param append current value of RollingFileAppender.getAppend(). * @param p pool for memory allocations during call. * @return Description of the initialization, may be null to indicate * no initialization needed. * @throws SecurityException if denied access to log files. */ virtual RolloverDescriptionPtr initialize( const LogString& file, const bool append, log4cxx::helpers::Pool& p) = 0; /** * Prepare for a rollover. This method is called prior to * closing the active log file, performs any necessary * preliminary actions and describes actions needed * after close of current log file. * * @param activeFile file name for current active log file. * @param p pool for memory allocations during call. * @return Description of pending rollover, may be null to indicate no rollover * at this time. * @throws SecurityException if denied access to log files. */ virtual RolloverDescriptionPtr rollover(const LogString& activeFile, log4cxx::helpers::Pool& p) = 0; }; LOG4CXX_PTR_DEF(RollingPolicy); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_ROLLING_POLICY_BASE_H) #define _LOG4CXX_ROLLING_ROLLING_POLICY_BASE_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/helpers/object.h> #include <log4cxx/logger.h> #include <log4cxx/logmanager.h> #include <log4cxx/rolling/rollingpolicy.h> #include <log4cxx/pattern/patternconverter.h> #include <log4cxx/pattern/formattinginfo.h> #include <log4cxx/pattern/patternparser.h> namespace log4cxx { namespace rolling { /** * Implements methods common to most, it not all, rolling * policies. * * * */ class LOG4CXX_EXPORT RollingPolicyBase : public virtual RollingPolicy, public virtual helpers::ObjectImpl { protected: DECLARE_ABSTRACT_LOG4CXX_OBJECT(RollingPolicyBase) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(RollingPolicy) LOG4CXX_CAST_ENTRY(spi::OptionHandler) END_LOG4CXX_CAST_MAP() private: /** * File name pattern converters. */ LOG4CXX_LIST_DEF(PatternConverterList, log4cxx::pattern::PatternConverterPtr); PatternConverterList patternConverters; /** * File name field specifiers. */ LOG4CXX_LIST_DEF(FormattingInfoList, log4cxx::pattern::FormattingInfoPtr); FormattingInfoList patternFields; /** * File name pattern. */ LogString fileNamePatternStr; public: RollingPolicyBase(); virtual ~RollingPolicyBase(); void addRef() const; void releaseRef() const; virtual void activateOptions(log4cxx::helpers::Pool& p) = 0; virtual log4cxx::pattern::PatternMap getFormatSpecifiers() const = 0; virtual void setOption(const LogString& option, const LogString& value); /** * Set file name pattern. * @param fnp file name pattern. */ void setFileNamePattern(const LogString& fnp); /** * Get file name pattern. * @return file name pattern. */ LogString getFileNamePattern() const; protected: /** * Parse file name pattern. */ void parseFileNamePattern(); /** * Format file name. * * @param obj object to be evaluted in formatting, may not be null. * @param buf string buffer to which formatted file name is appended, may not be null. * @param p memory pool. */ void formatFileName(log4cxx::helpers::ObjectPtr& obj, LogString& buf, log4cxx::helpers::Pool& p) const; log4cxx::pattern::PatternConverterPtr getIntegerPatternConverter() const; log4cxx::pattern::PatternConverterPtr getDatePatternConverter() const; }; } } #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_FILE_RENAME_ACTION_H) #define _LOG4CXX_ROLLING_FILE_RENAME_ACTION_H #include <log4cxx/rolling/action.h> #include <log4cxx/file.h> namespace log4cxx { namespace rolling { class FileRenameAction : public Action { const File source; const File destination; bool renameEmptyFile; public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(FileRenameAction) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(FileRenameAction) LOG4CXX_CAST_ENTRY_CHAIN(Action) END_LOG4CXX_CAST_MAP() /** * Constructor. */ FileRenameAction(const File& toRename, const File& renameTo, bool renameEmptyFile); /** * Perform action. * * @return true if successful. */ virtual bool execute(log4cxx::helpers::Pool& pool) const; }; LOG4CXX_PTR_DEF(FileRenameAction); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_ACTION_H) #define _LOG4CXX_ROLLING_ACTION_H #include <log4cxx/portability.h> #include <log4cxx/helpers/objectimpl.h> #include <log4cxx/helpers/mutex.h> #include <log4cxx/helpers/pool.h> namespace log4cxx { namespace rolling { /** * A file system action performed as part of a rollover event. */ class Action : public virtual log4cxx::helpers::ObjectImpl { DECLARE_ABSTRACT_LOG4CXX_OBJECT(Action) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(Action) END_LOG4CXX_CAST_MAP() /** * Is action complete. */ bool complete; /** * Is action interrupted. */ bool interrupted; log4cxx::helpers::Pool pool; log4cxx::helpers::Mutex mutex; protected: /** * Constructor. */ Action(); virtual ~Action(); public: /** * Perform action. * * @return true if successful. */ virtual bool execute(log4cxx::helpers::Pool& pool) const = 0; void run(log4cxx::helpers::Pool& pool); void close(); /** * Tests if the action is complete. * @return true if action is complete. */ bool isComplete() const; void reportException(const std::exception&); }; LOG4CXX_PTR_DEF(Action); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_MANUAL_TRIGGERING_POLICY_H) #define _LOG4CXX_ROLLING_MANUAL_TRIGGERING_POLICY_H #include <log4cxx/rolling/triggeringpolicy.h> namespace log4cxx { class File; namespace helpers { class Pool; } namespace rolling { /** * ManualTriggeringPolicy only rolls over on explicit calls to * RollingFileAppender.rollover(). * * * */ class LOG4CXX_EXPORT ManualTriggeringPolicy : public TriggeringPolicy { DECLARE_LOG4CXX_OBJECT(ManualTriggeringPolicy) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(ManualTriggeringPolicy) LOG4CXX_CAST_ENTRY_CHAIN(TriggeringPolicy) END_LOG4CXX_CAST_MAP() public: ManualTriggeringPolicy(); /** * Determines if a rollover may be appropriate at this time. If * true is returned, RolloverPolicy.rollover will be called but it * can determine that a rollover is not warranted. * * @param appender A reference to the appender. * @param event A reference to the currently event. * @param filename The filename for the currently active log file. * @param fileLength Length of the file in bytes. * @return true if a rollover should occur. */ virtual bool isTriggeringEvent( Appender* appender, const log4cxx::spi::LoggingEventPtr& event, const LogString& filename, size_t fileLength); void activateOptions(log4cxx::helpers::Pool&); void setOption(const LogString& option, const LogString& value); }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_ROLLING_FILE_APPENDER_H) #define _LOG4CXX_ROLLING_ROLLING_FILE_APPENDER_H #include <log4cxx/rolling/rollingfileappenderskeleton.h> namespace log4cxx { namespace rolling { /** * <code>RollingFileAppender</code> extends {@link log4cxx::FileAppender} to backup the log files * depending on {@link log4cxx::rolling::RollingPolicy RollingPolicy} and {@link log4cxx::rolling::TriggeringPolicy TriggeringPolicy}. * <p> * To be of any use, a <code>RollingFileAppender</code> instance must have both * a <code>RollingPolicy</code> and a <code>TriggeringPolicy</code> set up. * However, if its <code>RollingPolicy</code> also implements the * <code>TriggeringPolicy</code> interface, then only the former needs to be * set up. For example, {@link log4cxx::rolling::TimeBasedRollingPolicy TimeBasedRollingPolicy} acts both as a * <code>RollingPolicy</code> and a <code>TriggeringPolicy</code>. * * <p><code>RollingFileAppender</code> can be configured programattically or * using {@link log4cxx::xml::DOMConfigurator}. Here is a sample * configration file: <pre>&lt;?xml version="1.0" encoding="UTF-8" ?> &lt;!DOCTYPE log4j:configuration> &lt;log4j:configuration debug="true"> &lt;appender name="ROLL" class="org.apache.log4j.rolling.RollingFileAppender"> <b>&lt;rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy"> &lt;param name="FileNamePattern" value="/wombat/foo.%d{yyyy-MM}.gz"/> &lt;/rollingPolicy></b> &lt;layout class="org.apache.log4j.PatternLayout"> &lt;param name="ConversionPattern" value="%c{1} - %m%n"/> &lt;/layout> &lt;/appender> &lt;root"> &lt;appender-ref ref="ROLL"/> &lt;/root> &lt;/log4j:configuration> </pre> *<p>This configuration file specifies a monthly rollover schedule including * automatic compression of the archived files. See * {@link TimeBasedRollingPolicy} for more details. * * * * * */ class LOG4CXX_EXPORT RollingFileAppender : public RollingFileAppenderSkeleton { DECLARE_LOG4CXX_OBJECT(RollingFileAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(RollingFileAppender) LOG4CXX_CAST_ENTRY_CHAIN(RollingFileAppenderSkeleton) END_LOG4CXX_CAST_MAP() public: RollingFileAppender(); using RollingFileAppenderSkeleton::getRollingPolicy; using RollingFileAppenderSkeleton::getTriggeringPolicy; /** * Sets the rolling policy. In case the 'policy' argument also implements * {@link TriggeringPolicy}, then the triggering policy for this appender * is automatically set to be the policy argument. * @param policy */ using RollingFileAppenderSkeleton::setRollingPolicy; using RollingFileAppenderSkeleton::setTriggeringPolicy; }; LOG4CXX_PTR_DEF(RollingFileAppender); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_ROLLING_FILE_APPENDER_SKELETON_H) #define _LOG4CXX_ROLLING_ROLLING_FILE_APPENDER_SKELETON_H #include <log4cxx/portability.h> #include <log4cxx/spi/optionhandler.h> #include <log4cxx/fileappender.h> #include <log4cxx/rolling/triggeringpolicy.h> #include <log4cxx/rolling/rollingpolicy.h> #include <log4cxx/rolling/action.h> namespace log4cxx { namespace rolling { /** * Base class for log4cxx::rolling::RollingFileAppender and log4cxx::RollingFileAppender * (analogues of org.apache.log4j.rolling.RFA from extras companion and * org.apache.log4j.RFA from log4j 1.2, respectively). * * */ class LOG4CXX_EXPORT RollingFileAppenderSkeleton : public FileAppender { DECLARE_LOG4CXX_OBJECT(RollingFileAppenderSkeleton) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(RollingFileAppenderSkeleton) LOG4CXX_CAST_ENTRY_CHAIN(FileAppender) END_LOG4CXX_CAST_MAP() /** * Triggering policy. */ TriggeringPolicyPtr triggeringPolicy; /** * Rolling policy. */ RollingPolicyPtr rollingPolicy; /** * Length of current active log file. */ size_t fileLength; public: /** * The default constructor simply calls its {@link * FileAppender#FileAppender parents constructor}. * */ RollingFileAppenderSkeleton(); void activateOptions(log4cxx::helpers::Pool&); /** Implements the usual roll over behaviour. <p>If <code>MaxBackupIndex</code> is positive, then files {<code>File.1</code>, ..., <code>File.MaxBackupIndex -1</code>} are renamed to {<code>File.2</code>, ..., <code>File.MaxBackupIndex</code>}. Moreover, <code>File</code> is renamed <code>File.1</code> and closed. A new <code>File</code> is created to receive further log output. <p>If <code>MaxBackupIndex</code> is equal to zero, then the <code>File</code> is truncated with no backup files created. */ bool rollover(log4cxx::helpers::Pool& p); protected: /** Actual writing occurs here. */ virtual void subAppend(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p); protected: RollingPolicyPtr getRollingPolicy() const; TriggeringPolicyPtr getTriggeringPolicy() const; /** * Sets the rolling policy. In case the 'policy' argument also implements * {@link TriggeringPolicy}, then the triggering policy for this appender * is automatically set to be the policy argument. * @param policy */ void setRollingPolicy(const RollingPolicyPtr& policy); void setTriggeringPolicy(const TriggeringPolicyPtr& policy); public: /** * Close appender. Waits for any asynchronous file compression actions to be completed. */ void close(); protected: /** Returns an OutputStreamWriter when passed an OutputStream. The encoding used will depend on the value of the <code>encoding</code> property. If the encoding value is specified incorrectly the writer will be opened using the default system encoding (an error message will be printed to the loglog. @param os output stream, may not be null. @return new writer. */ log4cxx::helpers::WriterPtr createWriter(log4cxx::helpers::OutputStreamPtr& os); public: /** * Get byte length of current active log file. * @return byte length of current active log file. */ size_t getFileLength() const; /** * Increments estimated byte length of current active log file. * @param increment additional bytes written to log file. */ void incrementFileLength(size_t increment); }; LOG4CXX_PTR_DEF(RollingFileAppenderSkeleton); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_FIXED_WINDOW_ROLLING_POLICY_H) #define _LOG4CXX_ROLLING_FIXED_WINDOW_ROLLING_POLICY_H #include <log4cxx/rolling/rollingpolicybase.h> namespace log4cxx { namespace helpers { class Pool; } namespace rolling { /** * When rolling over, <code>FixedWindowRollingPolicy</code> renames files * according to a fixed window algorithm as described below. * * <p>The <b>ActiveFileName</b> property, which is required, represents the name * of the file where current logging output will be written. * The <b>FileNamePattern</b> option represents the file name pattern for the * archived (rolled over) log files. If present, the <b>FileNamePattern</b> * option must include an integer token, that is the string "%i" somwhere * within the pattern. * * <p>Let <em>max</em> and <em>min</em> represent the values of respectively * the <b>MaxIndex</b> and <b>MinIndex</b> options. Let "foo.log" be the value * of the <b>ActiveFile</b> option and "foo.%i.log" the value of * <b>FileNamePattern</b>. Then, when rolling over, the file * <code>foo.<em>max</em>.log</code> will be deleted, the file * <code>foo.<em>max-1</em>.log</code> will be renamed as * <code>foo.<em>max</em>.log</code>, the file <code>foo.<em>max-2</em>.log</code> * renamed as <code>foo.<em>max-1</em>.log</code>, and so on, * the file <code>foo.<em>min+1</em>.log</code> renamed as * <code>foo.<em>min+2</em>.log</code>. Lastly, the active file <code>foo.log</code> * will be renamed as <code>foo.<em>min</em>.log</code> and a new active file name * <code>foo.log</code> will be created. * * <p>Given that this rollover algorithm requires as many file renaming * operations as the window size, large window sizes are discouraged. The * current implementation will automatically reduce the window size to 12 when * larger values are specified by the user. * * * * * */ class LOG4CXX_EXPORT FixedWindowRollingPolicy : public RollingPolicyBase { DECLARE_LOG4CXX_OBJECT(FixedWindowRollingPolicy) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(FixedWindowRollingPolicy) LOG4CXX_CAST_ENTRY_CHAIN(RollingPolicyBase) END_LOG4CXX_CAST_MAP() int minIndex; int maxIndex; bool explicitActiveFile; /** * It's almost always a bad idea to have a large window size, say over 12. */ enum { MAX_WINDOW_SIZE = 12 }; bool purge(int purgeStart, int maxIndex, log4cxx::helpers::Pool& p) const; public: FixedWindowRollingPolicy(); void activateOptions(log4cxx::helpers::Pool& p); void setOption(const LogString& option, const LogString& value); void rollover(); int getMaxIndex() const; int getMinIndex() const; void setMaxIndex(int newVal); void setMinIndex(int newVal); /** * Initialize the policy and return any initial actions for rolling file appender. * * @param file current value of RollingFileAppender::getFile(). * @param append current value of RollingFileAppender::getAppend(). * @param p pool used for any required memory allocations. * @return Description of the initialization, may be null to indicate * no initialization needed. * @throws SecurityException if denied access to log files. */ virtual RolloverDescriptionPtr initialize( const LogString& file, const bool append, log4cxx::helpers::Pool& p); /** * Prepare for a rollover. This method is called prior to * closing the active log file, performs any necessary * preliminary actions and describes actions needed * after close of current log file. * * @param activeFile file name for current active log file. * @param p pool used for any required memory allocations. * @return Description of pending rollover, may be null to indicate no rollover * at this time. * @throws SecurityException if denied access to log files. */ virtual RolloverDescriptionPtr rollover(const LogString& activeFile, log4cxx::helpers::Pool& p); protected: log4cxx::pattern::PatternMap getFormatSpecifiers() const; }; LOG4CXX_PTR_DEF(FixedWindowRollingPolicy); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_ZIP_COMPRESS_ACTION_H) #define _LOG4CXX_ROLLING_ZIP_COMPRESS_ACTION_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/rolling/action.h> #include <log4cxx/file.h> namespace log4cxx { namespace rolling { class ZipCompressAction : public Action { const File source; const File destination; bool deleteSource; public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(ZipCompressAction) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(ZipCompressAction) LOG4CXX_CAST_ENTRY_CHAIN(Action) END_LOG4CXX_CAST_MAP() /** * Constructor. */ ZipCompressAction(const File& source, const File& destination, bool deleteSource); /** * Perform action. * * @return true if successful. */ virtual bool execute(log4cxx::helpers::Pool& pool) const; private: ZipCompressAction(const ZipCompressAction&); ZipCompressAction& operator=(const ZipCompressAction&); }; LOG4CXX_PTR_DEF(ZipCompressAction); } #if defined(_MSC_VER) #pragma warning ( pop ) #endif } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_FILTER_BASED_TRIGGERING_POLICY_H) #define _LOG4CXX_ROLLING_FILTER_BASED_TRIGGERING_POLICY_H #include <log4cxx/rolling/triggeringpolicy.h> #include <log4cxx/spi/filter.h> namespace log4cxx { class File; namespace helpers { class Pool; } namespace rolling { /** * FilterBasedTriggeringPolicy determines if rolling should be triggered * by evaluating the current message against a set of filters. Unless a * filter rejects a message, a rolling event will be triggered. * * * * */ class LOG4CXX_EXPORT FilterBasedTriggeringPolicy : public TriggeringPolicy { DECLARE_LOG4CXX_OBJECT(FilterBasedTriggeringPolicy) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(FilterBasedTriggeringPolicy) LOG4CXX_CAST_ENTRY_CHAIN(TriggeringPolicy) END_LOG4CXX_CAST_MAP() /** * The first filter in the filter chain. Set to <code>null</code> initially. */ log4cxx::spi::FilterPtr headFilter; /** * The last filter in the filter chain. */ log4cxx::spi::FilterPtr tailFilter; public: /** * Creates a new FilterBasedTriggeringPolicy. */ FilterBasedTriggeringPolicy(); virtual ~FilterBasedTriggeringPolicy(); /** * Determines if a rollover may be appropriate at this time. If * true is returned, RolloverPolicy.rollover will be called but it * can determine that a rollover is not warranted. * * @param appender A reference to the appender. * @param event A reference to the currently event. * @param filename The filename for the currently active log file. * @param fileLength Length of the file in bytes. * @return true if a rollover should occur. */ virtual bool isTriggeringEvent( Appender* appender, const log4cxx::spi::LoggingEventPtr& event, const LogString& filename, size_t fileLength); /** * Add a filter to end of the filter list. * @param newFilter filter to add to end of list. */ void addFilter(const log4cxx::spi::FilterPtr& newFilter); /** * Clear the filters chain. * */ void clearFilters(); /** * Returns the head Filter. * */ log4cxx::spi::FilterPtr& getFilter(); /** * Prepares the instance for use. */ void activateOptions(log4cxx::helpers::Pool&); void setOption(const LogString& option, const LogString& value); }; LOG4CXX_PTR_DEF(FilterBasedTriggeringPolicy); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_GZ_COMPRESS_ACTION_H) #define _LOG4CXX_ROLLING_GZ_COMPRESS_ACTION_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/rolling/action.h> #include <log4cxx/file.h> namespace log4cxx { namespace rolling { class GZCompressAction : public Action { const File source; const File destination; bool deleteSource; public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(GZCompressAction) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(GZCompressAction) LOG4CXX_CAST_ENTRY_CHAIN(Action) END_LOG4CXX_CAST_MAP() /** * Constructor. */ GZCompressAction(const File& source, const File& destination, bool deleteSource); /** * Perform action. * * @return true if successful. */ virtual bool execute(log4cxx::helpers::Pool& pool) const; private: GZCompressAction(const GZCompressAction&); GZCompressAction& operator=(const GZCompressAction&); }; LOG4CXX_PTR_DEF(GZCompressAction); } } #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_TIME_BASED_ROLLING_POLICY_H) #define _LOG4CXX_ROLLING_TIME_BASED_ROLLING_POLICY_H #include <log4cxx/portability.h> #include <log4cxx/rolling/rollingpolicybase.h> #include <log4cxx/rolling/triggeringpolicy.h> namespace log4cxx { namespace rolling { /** * <code>TimeBasedRollingPolicy</code> is both easy to configure and quite * powerful. * * <p>In order to use <code>TimeBasedRollingPolicy</code>, the * <b>FileNamePattern</b> option must be set. It basically specifies the name of the * rolled log files. The value <code>FileNamePattern</code> should consist of * the name of the file, plus a suitably placed <code>%d</code> conversion * specifier. The <code>%d</code> conversion specifier may contain a date and * time pattern as specified by the {@link log4cxx::helpers::SimpleDateFormat} class. If * the date and time pattern is ommitted, then the default pattern of * "yyyy-MM-dd" is assumed. The following examples should clarify the point. * * <p> * <table cellspacing="5px" border="1"> * <tr> * <th><code>FileNamePattern</code> value</th> * <th>Rollover schedule</th> * <th>Example</th> * </tr> * <tr> * <td nowrap="true"><code>/wombat/folder/foo.%d</code></td> * <td>Daily rollover (at midnight). Due to the omission of the optional * time and date pattern for the %d token specifier, the default pattern * of "yyyy-MM-dd" is assumed, which corresponds to daily rollover. * </td> * <td>During November 23rd, 2004, logging output will go to * the file <code>/wombat/foo.2004-11-23</code>. At midnight and for * the rest of the 24th, logging output will be directed to * <code>/wombat/foo.2004-11-24</code>. * </td> * </tr> * <tr> * <td nowrap="true"><code>/wombat/foo.%d{yyyy-MM}.log</code></td> * <td>Rollover at the beginning of each month.</td> * <td>During the month of October 2004, logging output will go to * <code>/wombat/foo.2004-10.log</code>. After midnight of October 31st * and for the rest of November, logging output will be directed to * <code>/wombat/foo.2004-11.log</code>. * </td> * </tr> * </table> * <h2>Automatic file compression</h2> * <code>TimeBasedRollingPolicy</code> supports automatic file compression. * This feature is enabled if the value of the <b>FileNamePattern</b> option * ends with <code>.gz</code> or <code>.zip</code>. * <p> * <table cellspacing="5px" border="1"> * <tr> * <th><code>FileNamePattern</code> value</th> * <th>Rollover schedule</th> * <th>Example</th> * </tr> * <tr> * <td nowrap="true"><code>/wombat/foo.%d.gz</code></td> * <td>Daily rollover (at midnight) with automatic GZIP compression of the * arcived files.</td> * <td>During November 23rd, 2004, logging output will go to * the file <code>/wombat/foo.2004-11-23</code>. However, at midnight that * file will be compressed to become <code>/wombat/foo.2004-11-23.gz</code>. * For the 24th of November, logging output will be directed to * <code>/wombat/folder/foo.2004-11-24</code> until its rolled over at the * beginning of the next day. * </td> * </tr> * </table> * * <h2>Decoupling the location of the active log file and the archived log files</h2> * <p>The <em>active file</em> is defined as the log file for the current period * whereas <em>archived files</em> are thos files which have been rolled over * in previous periods. * * <p>By setting the <b>ActiveFileName</b> option you can decouple the location * of the active log file and the location of the archived log files. * <p> * <table cellspacing="5px" border="1"> * <tr> * <th><code>FileNamePattern</code> value</th> * <th>ActiveFileName</th> * <th>Rollover schedule</th> * <th>Example</th> * </tr> * <tr> * <td nowrap="true"><code>/wombat/foo.log.%d</code></td> * <td nowrap="true"><code>/wombat/foo.log</code></td> * <td>Daily rollover.</td> * * <td>During November 23rd, 2004, logging output will go to * the file <code>/wombat/foo.log</code>. However, at midnight that file * will archived as <code>/wombat/foo.log.2004-11-23</code>. For the 24th * of November, logging output will be directed to * <code>/wombat/folder/foo.log</code> until its archived as * <code>/wombat/foo.log.2004-11-24</code> at the beginning of the next * day. * </td> * </tr> * </table> * <p> * If configuring programatically, do not forget to call {@link #activateOptions} * method before using this policy. Moreover, {@link #activateOptions} of * <code> TimeBasedRollingPolicy</code> must be called <em>before</em> calling * the {@link #activateOptions} method of the owning * <code>RollingFileAppender</code>. * * * */ class LOG4CXX_EXPORT TimeBasedRollingPolicy : public RollingPolicyBase, public TriggeringPolicy { DECLARE_LOG4CXX_OBJECT(TimeBasedRollingPolicy) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(TimeBasedRollingPolicy) LOG4CXX_CAST_ENTRY_CHAIN(RollingPolicyBase) LOG4CXX_CAST_ENTRY_CHAIN(TriggeringPolicy) END_LOG4CXX_CAST_MAP() private: /** * Time for next determination if time for rollover. */ log4cxx_time_t nextCheck; /** * File name at last rollover. */ LogString lastFileName; /** * Length of any file type suffix (.gz, .zip). */ int suffixLength; public: TimeBasedRollingPolicy(); void addRef() const; void releaseRef() const; void activateOptions(log4cxx::helpers::Pool& ); /** * Initialize the policy and return any initial actions for rolling file appender. * * @param file current value of RollingFileAppender.getFile(). * @param append current value of RollingFileAppender.getAppend(). * @param pool pool for any required allocations. * @return Description of the initialization, may be null to indicate * no initialization needed. * @throws SecurityException if denied access to log files. */ RolloverDescriptionPtr initialize( const LogString& file, const bool append, log4cxx::helpers::Pool& pool); /** * Prepare for a rollover. This method is called prior to * closing the active log file, performs any necessary * preliminary actions and describes actions needed * after close of current log file. * * @param activeFile file name for current active log file. * @param pool pool for any required allocations. * @return Description of pending rollover, may be null to indicate no rollover * at this time. * @throws SecurityException if denied access to log files. */ RolloverDescriptionPtr rollover(const LogString& activeFile, log4cxx::helpers::Pool& pool); /** * Determines if a rollover may be appropriate at this time. If * true is returned, RolloverPolicy.rollover will be called but it * can determine that a rollover is not warranted. * * @param appender A reference to the appender. * @param event A reference to the currently event. * @param filename The filename for the currently active log file. * @param fileLength Length of the file in bytes. * @return true if a rollover should occur. */ virtual bool isTriggeringEvent( Appender* appender, const log4cxx::spi::LoggingEventPtr& event, const LogString& filename, size_t fileLength); protected: log4cxx::pattern::PatternMap getFormatSpecifiers() const; }; LOG4CXX_PTR_DEF(TimeBasedRollingPolicy); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_ROLLOVER_DESCRIPTION_H) #define _LOG4CXX_ROLLING_ROLLOVER_DESCRIPTION_H #include <log4cxx/portability.h> #include <log4cxx/rolling/action.h> namespace log4cxx { namespace rolling { class RolloverDescription : public log4cxx::helpers::ObjectImpl { DECLARE_LOG4CXX_OBJECT(RolloverDescription) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(RolloverDescription) END_LOG4CXX_CAST_MAP() /** * Active log file name after rollover. */ LogString activeFileName; /** * Should active file be opened for appending. */ bool append; /** * Action to be completed after close of current active log file * before returning control to caller. */ ActionPtr synchronous; /** * Action to be completed after close of current active log file * and before next rollover attempt, may be executed asynchronously. */ ActionPtr asynchronous; public: RolloverDescription(); /** * Create new instance. * @param activeFileName active log file name after rollover, may not be null. * @param append true if active log file after rollover should be opened for appending. * @param synchronous action to be completed after close of current active log file, may be null. * @param asynchronous action to be completed after close of current active log file and * before next rollover attempt. */ RolloverDescription( const LogString& activeFileName, const bool append, const ActionPtr& synchronous, const ActionPtr& asynchronous); /** * Active log file name after rollover. * @return active log file name after rollover. */ LogString getActiveFileName() const; bool getAppend() const; /** * Action to be completed after close of current active log file * before returning control to caller. * * @return action, may be null. */ ActionPtr getSynchronous() const; /** * Action to be completed after close of current active log file * and before next rollover attempt, may be executed asynchronously. * * @return action, may be null. */ ActionPtr getAsynchronous() const; }; LOG4CXX_PTR_DEF(RolloverDescription); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_SIZE_BASED_TRIGGERING_POLICY_H) #define _LOG4CXX_ROLLING_SIZE_BASED_TRIGGERING_POLICY_H #include <log4cxx/rolling/triggeringpolicy.h> namespace log4cxx { class File; namespace helpers { class Pool; } namespace rolling { /** * SizeBasedTriggeringPolicy looks at size of the file being * currently written to. * * * */ class LOG4CXX_EXPORT SizeBasedTriggeringPolicy : public TriggeringPolicy { DECLARE_LOG4CXX_OBJECT(SizeBasedTriggeringPolicy) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(SizeBasedTriggeringPolicy) LOG4CXX_CAST_ENTRY_CHAIN(TriggeringPolicy) END_LOG4CXX_CAST_MAP() protected: size_t maxFileSize; public: SizeBasedTriggeringPolicy(); /** * Determines if a rollover may be appropriate at this time. If * true is returned, RolloverPolicy.rollover will be called but it * can determine that a rollover is not warranted. * * @param appender A reference to the appender. * @param event A reference to the currently event. * @param filename The filename for the currently active log file. * @param fileLength Length of the file in bytes. * @return true if a rollover should occur. */ virtual bool isTriggeringEvent( Appender* appender, const log4cxx::spi::LoggingEventPtr& event, const LogString& filename, size_t fileLength); size_t getMaxFileSize(); void setMaxFileSize(size_t l); void activateOptions(log4cxx::helpers::Pool&); void setOption(const LogString& option, const LogString& value); }; LOG4CXX_PTR_DEF(SizeBasedTriggeringPolicy); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if !defined(_LOG4CXX_ROLLING_TRIGGER_POLICY_H) #define _LOG4CXX_ROLLING_TRIGGER_POLICY_H #include <log4cxx/spi/optionhandler.h> #include <log4cxx/helpers/objectimpl.h> #include <log4cxx/spi/loggingevent.h> #include <log4cxx/appender.h> namespace log4cxx { class File; namespace rolling { /** * A <code>TriggeringPolicy</code> controls the conditions under which rollover * occurs. Such conditions include time of day, file size, an * external event or a combination thereof. * * * * */ class LOG4CXX_EXPORT TriggeringPolicy : public virtual spi::OptionHandler, public virtual helpers::ObjectImpl { DECLARE_ABSTRACT_LOG4CXX_OBJECT(TriggeringPolicy) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(TriggeringPolicy) LOG4CXX_CAST_ENTRY(spi::OptionHandler) END_LOG4CXX_CAST_MAP() public: virtual ~TriggeringPolicy(); void addRef() const; void releaseRef() const; /** * Determines if a rollover may be appropriate at this time. If * true is returned, RolloverPolicy.rollover will be called but it * can determine that a rollover is not warranted. * * @param appender A reference to the appender. * @param event A reference to the currently event. * @param filename The filename for the currently active log file. * @param fileLength Length of the file in bytes. * @return true if a rollover should occur. */ virtual bool isTriggeringEvent( Appender* appender, const log4cxx::spi::LoggingEventPtr& event, const LogString& filename, size_t fileLength) = 0; }; LOG4CXX_PTR_DEF(TriggeringPolicy); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_LAYOUT_H #define _LOG4CXX_PATTERN_LAYOUT_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/layout.h> #include <log4cxx/pattern/loggingeventpatternconverter.h> #include <log4cxx/pattern/formattinginfo.h> #include <log4cxx/pattern/patternparser.h> namespace log4cxx { /** A flexible layout configurable with pattern string. <p>The goal of this class is to #format a {@link spi::LoggingEvent LoggingEvent} and return the results as a string. The results depend on the <em>conversion pattern</em>. <p>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>. <p><i>You are free to insert any literal text within the conversion pattern.</i> <p>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, level, date, thread name. The format modifiers control such things as field width, padding, left and right justification. The following is a simple example. <p>Let the conversion pattern be <b>"\%-5p [\%t]: \%m\%n"</b> and assume that the log4cxx environment was set to use a PatternLayout. Then the statements <pre> LoggerPtr root = Logger::getRoot(); root->debug("Message 1"); root->warn("Message 2"); </pre> would yield the output <pre> DEBUG [main]: Message 1 WARN [main]: Message 2 </pre> <p>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 level of the logging event should be left justified to a width of five characters. The recognized conversion characters are <p> <table border="1" CELLPADDING="8"> <tr> <td align=center><b>Conversion Character</b></td> <td align=center><b>Effect</b></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. <p>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. <p>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. The date conversion specifier may be followed by a set of braces containing a date and time pattern string compatible with java.text.SimpleDateFormat, <em>ABSOLUTE</em>, <em>DATE</em> or <em>ISO8601</em>. For example, <b>%d{HH:mm:ss,SSS}</b>, <b>%d{dd&nbsp;MMM&nbsp;yyyy&nbsp;HH:mm:ss,SSS}</b> or <b>%d{DATE}</b>. If no date format specifier is given then ISO8601 format is assumed. </td> </tr> <tr> <td align=center><b>F</b></td> <td>Used to output the file name where the logging request was issued. </tr> <tr> <td align=center><b>l</b></td> <td>Used to output location information of the caller which generated the logging event. </td> </tr> <tr> <td align=center><b>L</b></td> <td>Used to output the line number from where the logging request was issued. </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. <p>This conversion character offers practically the same performance as using non-portable line separator strings such as "\n", or "\r\n". Thus, it is the preferred way of specifying a line separator. </tr> <tr> <td align=center><b>p</b></td> <td>Used to output the level of the logging event.</td> </tr> <tr> <td align=center><b>r</b></td> <td>Used to output the number of milliseconds elapsed since the start of the application until the creation 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>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>X</b></td> <td> <p>Used to output the MDC (mapped diagnostic context) associated with the thread that generated the logging event. The <b>X</b> conversion character <em>must</em> be followed by the key for the map placed between braces, as in <b>\%X{clientNumber}</b> where <code>clientNumber</code> is the key. The value in the MDC corresponding to the key will be output.</p> <p>See MDC class for more details. </p> </td> </tr> <tr> <td align=center><b>\%</b></td> <td>The sequence \%\% outputs a single percent sign. </td> </tr> </table> <p>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. <p>The optional format modifier is placed between the percent sign and the conversion character. <p>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. <p>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. <p>Below are various format modifier examples for the logger conversion specifier. <p> <TABLE BORDER=1 CELLPADDING=8> <tr> <td align=center><b>Format modifier</b></td> <td align=center><b>left justify</b></td> <td align=center><b>minimum width</b></td> <td align=center><b>maximum width</b></td> <td align=center><b>comment</b></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> <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> <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> <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> <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. </table> <p>Below are some examples of conversion patterns. <p><b>\%r [\%t] \%-5p \%c \%x - \%m\n</b> <p>This is essentially the TTCC layout. <p><b>\%-6r [\%15.15t] \%-5p \%30.30c \%x - \%m\n</b> <p>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. <p>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 LOG4CXX_EXPORT PatternLayout : public Layout { /** * Conversion pattern. */ LogString conversionPattern; /** * Pattern converters. */ LOG4CXX_LIST_DEF(LoggingEventPatternConverterList, log4cxx::pattern::LoggingEventPatternConverterPtr); LoggingEventPatternConverterList patternConverters; /** * Field widths and alignment corresponding to pattern converters. */ LOG4CXX_LIST_DEF(FormattingInfoList, log4cxx::pattern::FormattingInfoPtr); FormattingInfoList patternFields; public: DECLARE_LOG4CXX_OBJECT(PatternLayout) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(PatternLayout) LOG4CXX_CAST_ENTRY_CHAIN(Layout) END_LOG4CXX_CAST_MAP() /** Does nothing */ PatternLayout(); /** Constructs a PatternLayout using the supplied conversion pattern. */ PatternLayout(const LogString& pattern); /** Set the <b>ConversionPattern</b> option. This is the string which controls formatting and consists of a mix of literal content and conversion specifiers. */ void setConversionPattern(const LogString& conversionPattern); /** Returns the value of the <b>ConversionPattern</b> option. */ inline LogString getConversionPattern() const { return conversionPattern; } /** Call createPatternParser */ virtual void activateOptions(log4cxx::helpers::Pool& p); virtual void setOption(const LogString& option, const LogString& value); /** The PatternLayout does not handle the throwable contained within {@link spi::LoggingEvent LoggingEvents}. Thus, it returns <code>true</code>. */ virtual bool ignoresThrowable() const { return true; } /** Produces a formatted string as specified by the conversion pattern. */ virtual void format(LogString& output, const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool) const; protected: virtual log4cxx::pattern::PatternMap getFormatSpecifiers(); }; LOG4CXX_PTR_DEF(PatternLayout); } // namespace log4cxx #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif //_LOG4CXX_PATTERN_LAYOUT_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_ASYNC_APPENDER_H #define _LOG4CXX_ASYNC_APPENDER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/appenderskeleton.h> #include <log4cxx/helpers/appenderattachableimpl.h> #include <deque> #include <log4cxx/spi/loggingevent.h> #include <log4cxx/helpers/thread.h> #include <log4cxx/helpers/mutex.h> #include <log4cxx/helpers/condition.h> namespace log4cxx { /** The AsyncAppender lets users log events asynchronously. It uses a bounded buffer to store logging events. <p>The AsyncAppender will collect the events sent to it and then dispatch them to all the appenders that are attached to it. You can attach multiple appenders to an AsyncAppender. <p>The AsyncAppender uses a separate thread to serve the events in its bounded buffer. <p><b>Important note:</b> The <code>AsyncAppender</code> can only be script configured using the {@link xml::DOMConfigurator DOMConfigurator}. */ class LOG4CXX_EXPORT AsyncAppender : public virtual spi::AppenderAttachable, public virtual AppenderSkeleton { public: DECLARE_LOG4CXX_OBJECT(AsyncAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(AsyncAppender) LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) LOG4CXX_CAST_ENTRY(spi::AppenderAttachable) END_LOG4CXX_CAST_MAP() /** * Create new instance. */ AsyncAppender(); /** * Destructor. */ virtual ~AsyncAppender(); void addRef() const; void releaseRef() const; /** * Add appender. * * @param newAppender appender to add, may not be null. */ void addAppender(const AppenderPtr& newAppender); void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p); /** Close this <code>AsyncAppender</code> by interrupting the dispatcher thread which will process all pending events before exiting. */ void close(); /** * Get iterator over attached appenders. * @return list of all attached appenders. */ AppenderList getAllAppenders() const; /** * Get appender by name. * * @param name name, may not be null. * @return matching appender or null. */ AppenderPtr getAppender(const LogString& name) const; /** * Gets whether the location of the logging request call * should be captured. * * @return the current value of the <b>LocationInfo</b> option. */ bool getLocationInfo() const; /** * Determines if specified appender is attached. * @param appender appender. * @return true if attached. */ bool isAttached(const AppenderPtr& appender) const; virtual bool requiresLayout() const; /** * Removes and closes all attached appenders. */ void removeAllAppenders(); /** * Removes an appender. * @param appender appender to remove. */ void removeAppender(const AppenderPtr& appender); /** * Remove appender by name. * @param name name. */ void removeAppender(const LogString& name); /** * The <b>LocationInfo</b> attribute is provided for compatibility * with log4j and has no effect on the log output. * @param flag new value. */ void setLocationInfo(bool flag); /** * The <b>BufferSize</b> option takes a non-negative integer value. * This integer value determines the maximum size of the bounded * buffer. * */ void setBufferSize(int size); /** * Gets the current buffer size. * @return the current value of the <b>BufferSize</b> option. */ int getBufferSize() const; /** * Sets whether appender should wait if there is no * space available in the event buffer or immediately return. * * @param value true if appender should wait until available space in buffer. */ void setBlocking(bool value); /** * Gets whether appender should block calling thread when buffer is full. * If false, messages will be counted by logger and a summary * message appended after the contents of the buffer have been appended. * * @return true if calling thread will be blocked when buffer is full. */ bool getBlocking() const; /** * Set appender properties by name. * @param option property name. * @param value property value. */ void setOption(const LogString& option, const LogString& value); private: AsyncAppender(const AsyncAppender&); AsyncAppender& operator=(const AsyncAppender&); /** * The default buffer size is set to 128 events. */ enum { DEFAULT_BUFFER_SIZE = 128 }; /** * Event buffer. */ LOG4CXX_LIST_DEF(LoggingEventList, log4cxx::spi::LoggingEventPtr); LoggingEventList buffer; /** * Mutex used to guard access to buffer and discardMap. */ ::log4cxx::helpers::Mutex bufferMutex; ::log4cxx::helpers::Condition bufferNotFull; ::log4cxx::helpers::Condition bufferNotEmpty; class DiscardSummary { private: /** * First event of the highest severity. */ ::log4cxx::spi::LoggingEventPtr maxEvent; /** * Total count of messages discarded. */ int count; public: /** * Create new instance. * * @param event event, may not be null. */ DiscardSummary(const ::log4cxx::spi::LoggingEventPtr& event); /** Copy constructor. */ DiscardSummary(const DiscardSummary& src); /** Assignment operator. */ DiscardSummary& operator=(const DiscardSummary& src); /** * Add discarded event to summary. * * @param event event, may not be null. */ void add(const ::log4cxx::spi::LoggingEventPtr& event); /** * Create event with summary information. * * @return new event. */ ::log4cxx::spi::LoggingEventPtr createEvent(::log4cxx::helpers::Pool& p); }; /** * Map of DiscardSummary objects keyed by logger name. */ typedef std::map<LogString, DiscardSummary> DiscardMap; DiscardMap* discardMap; /** * Buffer size. */ int bufferSize; /** * Nested appenders. */ helpers::AppenderAttachableImplPtr appenders; /** * Dispatcher. */ helpers::Thread dispatcher; /** * Should location info be included in dispatched messages. */ bool locationInfo; /** * Does appender block when buffer is full. */ bool blocking; /** * Dispatch routine. */ static void* LOG4CXX_THREAD_FUNC dispatch(apr_thread_t* thread, void* data); }; // class AsyncAppender LOG4CXX_PTR_DEF(AsyncAppender); } // namespace log4cxx #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif// _LOG4CXX_ASYNC_APPENDER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_NT_EVENT_LOG_APPENDER_HEADER_ #define _LOG4CXX_NT_EVENT_LOG_APPENDER_HEADER_ #include <log4cxx/appenderskeleton.h> namespace log4cxx { namespace nt { /** * Appends log events to NT EventLog. */ class LOG4CXX_EXPORT NTEventLogAppender : public AppenderSkeleton { public: DECLARE_LOG4CXX_OBJECT(NTEventLogAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(NTEventLogAppender) LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) END_LOG4CXX_CAST_MAP() NTEventLogAppender(); NTEventLogAppender(const LogString& server, const LogString& log, const LogString& source, const LayoutPtr& layout); virtual ~NTEventLogAppender(); virtual void activateOptions(log4cxx::helpers::Pool& p); virtual void close(); virtual void setOption(const LogString& option, const LogString& value); /** * The SocketAppender does not use a layout. Hence, this method * returns <code>false</code>. * */ bool requiresLayout() const { return true; } void setSource(const LogString& source) { this->source.assign(source); } const LogString& getSource() const { return source; } void setLog(const LogString& log) { this->log.assign(log); } const LogString& getLog() const { return log; } void setServer(const LogString& server) { this->server.assign(server); } const LogString& getServer() const { return server; } protected: // // these typedef are proxies for the real Win32 definitions // and need to be cast to the global definitions before // use with a Win32 API call typedef void SID; typedef void* HANDLE; virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p); static unsigned short getEventType(const spi::LoggingEventPtr& event); static unsigned short getEventCategory(const spi::LoggingEventPtr& event); /* * Add this source with appropriate configuration keys to the registry. */ void addRegistryInfo(); // Data LogString server; LogString log; LogString source; HANDLE hEventLog; SID * pCurrentUserSID; static LogString getErrorString(const LogString& function); private: NTEventLogAppender(const NTEventLogAppender&); NTEventLogAppender& operator=(const NTEventLogAppender&); }; // class NTEventLogAppender LOG4CXX_PTR_DEF(NTEventLogAppender); } // namespace nt } // namespace log4cxx #endif //_LOG4CXX_NT_EVENT_LOG_APPENDER_HEADER_
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_NT_OUTPUTDEBUGSTRING_APPENDER_HEADER_ #define _LOG4CXX_NT_OUTPUTDEBUGSTRING_APPENDER_HEADER_ #include <log4cxx/appenderskeleton.h> namespace log4cxx { namespace nt { class LOG4CXX_EXPORT OutputDebugStringAppender : public AppenderSkeleton { public: DECLARE_LOG4CXX_OBJECT(OutputDebugStringAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(OutputDebugStringAppender) LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) END_LOG4CXX_CAST_MAP() OutputDebugStringAppender(); bool requiresLayout() const { return true; } virtual void close() {} virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p); }; } } #endif //_LOG4CXX_NT_OUTPUTDEBUGSTRING_APPENDER_HEADER_
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_XML_LAYOUT_H #define _LOG4CXX_XML_LAYOUT_H #include <log4cxx/layout.h> namespace log4cxx { namespace xml { /** The output of the XMLLayout consists of a series of log4j:event elements. It does not output a complete well-formed XML file. The output is designed to be included as an <em>external entity</em> in a separate file to form a correct XML file. <p>For example, if <code>abc</code> is the name of the file where the XMLLayout ouput goes, then a well-formed XML file would be: <code> <?xml version="1.0" ?> <!DOCTYPE log4j:eventSet [<!ENTITY data SYSTEM "abc">]> <log4j:eventSet version="1.2" xmlns:log4j="http://jakarta.apache.org/log4j/"> @&data; </log4j:eventSet> </code> <p>This approach enforces the independence of the XMLLayout and the appender where it is embedded. */ class LOG4CXX_EXPORT XMLLayout : public Layout { private: // Print no location info by default bool locationInfo; //= false bool properties; // = false public: DECLARE_LOG4CXX_OBJECT(XMLLayout) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(XMLLayout) LOG4CXX_CAST_ENTRY_CHAIN(Layout) END_LOG4CXX_CAST_MAP() XMLLayout(); /** The <b>LocationInfo</b> option takes a boolean value. By default, it is set to false which means there will be no location information output by this layout. If the the option is set to true, then the file name and line number of the statement at the origin of the log statement will be output. <p>If you are embedding this layout within a SMTPAppender then make sure to set the <b>LocationInfo</b> option of that appender as well. */ inline void setLocationInfo(bool locationInfo1) { this->locationInfo = locationInfo1; } /** Returns the current value of the <b>LocationInfo</b> option. */ inline bool getLocationInfo() const { return locationInfo; } /** * Sets whether MDC key-value pairs should be output, default false. * @param flag new value. * */ inline void setProperties(bool flag) { properties = flag; } /** * Gets whether MDC key-value pairs should be output. * @return true if MDC key-value pairs are output. * */ inline bool getProperties() { return properties; } /** No options to activate. */ void activateOptions(log4cxx::helpers::Pool& /* p */) { } /** Set options */ virtual void setOption(const LogString& option, const LogString& value); /** * Formats a {@link spi::LoggingEvent LoggingEvent} * in conformance with the log4cxx.dtd. **/ virtual void format(LogString& output, const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p) const; /** The XMLLayout prints and does not ignore exceptions. Hence the return value <code>false</code>. */ virtual bool ignoresThrowable() const { return false; } }; // class XMLLayout LOG4CXX_PTR_DEF(XMLLayout); } // namespace xml } // namespace log4cxx #endif // _LOG4CXX_XML_LAYOUT_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_XML_DOM_CONFIGURATOR_H #define _LOG4CXX_XML_DOM_CONFIGURATOR_H #if defined(_MSC_VER) #pragma warning (push) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/logstring.h> #include <map> #include <log4cxx/appender.h> #include <log4cxx/layout.h> #include <log4cxx/logger.h> #include <log4cxx/helpers/properties.h> #include <log4cxx/spi/configurator.h> #include <log4cxx/helpers/charsetdecoder.h> #include <log4cxx/spi/filter.h> #include <log4cxx/rolling/triggeringpolicy.h> #include <log4cxx/rolling/rollingpolicy.h> #include <log4cxx/file.h> #include <log4cxx/config/propertysetter.h> extern "C" { struct apr_xml_doc; struct apr_xml_elem; } namespace log4cxx { namespace xml { /** Use this class to initialize the log4cxx environment using a DOM tree. <p>Sometimes it is useful to see how log4cxx is reading configuration files. You can enable log4cxx internal logging by setting the <code>debug</code> attribute in the <code>log4cxx</code> element. As in <pre> &lt;log4j:configuration <b>debug="true"</b> xmlns:log4j="http://jakarta.apache.org/log4j/"> ... &lt;/log4j:configuration> </pre> <p>There are sample XML files included in the package. */ class LOG4CXX_EXPORT DOMConfigurator : virtual public spi::Configurator, virtual public helpers::ObjectImpl { protected: typedef std::map<LogString, AppenderPtr> AppenderMap; /** Used internally to parse appenders by IDREF name. */ AppenderPtr findAppenderByName( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* elem, apr_xml_doc* doc, const LogString& appenderName, AppenderMap& appenders); /** Used internally to parse appenders by IDREF element. */ AppenderPtr findAppenderByReference( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* appenderRef, apr_xml_doc* doc, AppenderMap& appenders); /** Used internally to parse an appender element. */ AppenderPtr parseAppender( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* appenderElement, apr_xml_doc* doc, AppenderMap& appenders); /** Used internally to parse an {@link spi::ErrorHandler ErrorHandler } element. */ void parseErrorHandler( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* element, AppenderPtr& appender, apr_xml_doc* doc, AppenderMap& appenders); /** Used internally to parse a filter element. */ void parseFilters( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* element, std::vector<log4cxx::spi::FilterPtr>& filters); /** Used internally to parse a logger element. */ void parseLogger( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* loggerElement, apr_xml_doc* doc, AppenderMap& appenders); /** Used internally to parse the logger factory element. */ void parseLoggerFactory( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* factoryElement); /** Used internally to parse the logger factory element. */ log4cxx::helpers::ObjectPtr parseTriggeringPolicy( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* factoryElement); /** Used internally to parse the logger factory element. */ log4cxx::rolling::RollingPolicyPtr parseRollingPolicy( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* factoryElement); /** Used internally to parse the root logger element. */ void parseRoot(log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* rootElement, apr_xml_doc* doc, AppenderMap& appenders); /** Used internally to parse the children of a logger element. */ void parseChildrenOfLoggerElement( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* catElement, LoggerPtr logger, bool isRoot, apr_xml_doc* doc, AppenderMap& appenders); /** Used internally to parse a layout element. */ LayoutPtr parseLayout( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* layout_element); /** Used internally to parse a level element. */ void parseLevel( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* element, LoggerPtr logger, bool isRoot); void setParameter( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* elem, log4cxx::config::PropertySetter& propSetter); /** Used internally to configure the log4cxx framework from an in-memory representation of an XML document. */ void parse( log4cxx::helpers::Pool& p, log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem* element, apr_xml_doc* doc, AppenderMap& appenders); public: DOMConfigurator(); DECLARE_LOG4CXX_OBJECT(DOMConfigurator) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(spi::Configurator) END_LOG4CXX_CAST_MAP() DOMConfigurator(log4cxx::helpers::Pool& p); void addRef() const; void releaseRef() const; /** A static version of #doConfigure. */ static void configure(const std::string& filename); #if LOG4CXX_WCHAR_T_API static void configure(const std::wstring& filename); #endif #if LOG4CXX_UNICHAR_API static void configure(const std::basic_string<UniChar>& filename); #endif #if LOG4CXX_CFSTRING_API static void configure(const CFStringRef& filename); #endif /** Like #configureAndWatch(const std::string& configFilename, long delay) except that the default delay as defined by log4cxx::helpers::FileWatchdog#DEFAULT_DELAY is used. @param configFilename A log4j configuration file in XML format. */ static void configureAndWatch(const std::string& configFilename); #if LOG4CXX_WCHAR_T_API static void configureAndWatch(const std::wstring& configFilename); #endif #if LOG4CXX_UNICHAR_API static void configureAndWatch(const std::basic_string<UniChar>& configFilename); #endif #if LOG4CXX_CFSTRING_API static void configureAndWatch(const CFStringRef& configFilename); #endif /** Read the configuration file <code>configFilename</code> if it exists. Moreover, a thread will be created that will periodically check if <code>configFilename</code> has been created or modified. The period is determined by the <code>delay</code> argument. If a change or file creation is detected, then <code>configFilename</code> is read to configure log4cxx. @param configFilename A log4j configuration file in XML format. @param delay The delay in milliseconds to wait between each check. */ static void configureAndWatch(const std::string& configFilename, long delay); #if LOG4CXX_WCHAR_T_API static void configureAndWatch(const std::wstring& configFilename, long delay); #endif #if LOG4CXX_UNICHAR_API static void configureAndWatch(const std::basic_string<UniChar>& configFilename, long delay); #endif #if LOG4CXX_CFSTRING_API static void configureAndWatch(const CFStringRef& configFilename, long delay); #endif /** Interpret the XML file pointed by <code>filename</code> and set up log4cxx accordingly. <p>The configuration is done relative to the hierarchy parameter. @param filename The file to parse. @param repository The hierarchy to operation upon. */ void doConfigure(const File& filename, spi::LoggerRepositoryPtr& repository); protected: static LogString getAttribute( log4cxx::helpers::CharsetDecoderPtr& utf8Decoder, apr_xml_elem*, const std::string& attrName); LogString subst(const LogString& value); protected: helpers::Properties props; spi::LoggerRepositoryPtr repository; spi::LoggerFactoryPtr loggerFactory; private: // prevent assignment or copy statements DOMConfigurator(const DOMConfigurator&); DOMConfigurator& operator=(const DOMConfigurator&); }; LOG4CXX_PTR_DEF(DOMConfigurator); } // namespace xml } // namespace log4cxx #if defined(_MSC_VER) #pragma warning (pop) #endif #endif // _LOG4CXX_XML_DOM_CONFIGURATOR_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_LOG_MANAGER_H #define _LOG4CXX_LOG_MANAGER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/logstring.h> #include <vector> #include <log4cxx/spi/repositoryselector.h> namespace log4cxx { class Logger; typedef helpers::ObjectPtrT<Logger> LoggerPtr; typedef std::vector<LoggerPtr> LoggerList; namespace spi { class LoggerFactory; typedef helpers::ObjectPtrT<LoggerFactory> LoggerFactoryPtr; } /** * Use the <code>LogManager</code> class to retreive Logger * instances or to operate on the current * {@link log4cxx::spi::LoggerRepository LoggerRepository}. * When the <code>LogManager</code> class is loaded * into memory the default initialization procedure is inititated. */ class LOG4CXX_EXPORT LogManager { private: static void * guard; static spi::RepositorySelectorPtr& getRepositorySelector(); public: /** Sets <code>LoggerFactory</code> but only if the correct <em>guard</em> is passed as parameter. <p>Initally the guard is null. If the guard is <code>null</code>, then invoking this method sets the logger factory and the guard. Following invocations will throw a {@link helpers::IllegalArgumentException IllegalArgumentException}, unless the previously set <code>guard</code> is passed as the second parameter. <p>This allows a high-level component to set the {@link spi::RepositorySelector RepositorySelector} used by the <code>LogManager</code>. */ static void setRepositorySelector(spi::RepositorySelectorPtr selector, void * guard); static spi::LoggerRepositoryPtr& getLoggerRepository(); /** Retrieve the appropriate root logger. */ static LoggerPtr getRootLogger(); /** Retrieve the appropriate Logger instance. * @param name logger name in current encoding. * @return logger. */ static LoggerPtr getLogger(const std::string& name); /** Retrieve the appropriate Logger instance. * @param name logger name in current encoding. * @param factory logger factory. * @return logger. */ static LoggerPtr getLogger(const std::string& name, const spi::LoggerFactoryPtr& factory); /** * Determines if logger name exists in the hierarchy. * @param name logger name. * @return true if logger exists. */ static LoggerPtr exists(const std::string& name); #if LOG4CXX_WCHAR_T_API /** Retrieve the appropriate Logger instance. * @param name logger name. * @return logger. */ static LoggerPtr getLogger(const std::wstring& name); /** Retrieve the appropriate Logger instance. * @param name logger name. * @param factory logger factory. * @return logger. */ static LoggerPtr getLogger(const std::wstring& name, const spi::LoggerFactoryPtr& factory); /** * Determines if logger name exists in the hierarchy. * @param name logger name. * @return true if logger exists. */ static LoggerPtr exists(const std::wstring& name); #endif #if LOG4CXX_UNICHAR_API /** Retrieve the appropriate Logger instance. * @param name logger name. * @return logger. */ static LoggerPtr getLogger(const std::basic_string<UniChar>& name); /** Retrieve the appropriate Logger instance. * @param name logger name. * @param factory logger factory. * @return logger. */ static LoggerPtr getLogger(const std::basic_string<UniChar>& name, const spi::LoggerFactoryPtr& factory); /** * Determines if logger name exists in the hierarchy. * @param name logger name. * @return true if logger exists. */ static LoggerPtr exists(const std::basic_string<UniChar>& name); #endif #if LOG4CXX_CFSTRING_API /** Retrieve the appropriate Logger instance. * @param name logger name. * @return logger. */ static LoggerPtr getLogger(const CFStringRef& name); /** Retrieve the appropriate Logger instance. * @param name logger name. * @param factory logger factory. * @return logger. */ static LoggerPtr getLogger(const CFStringRef& name, const spi::LoggerFactoryPtr& factory); /** * Determines if logger name exists in the hierarchy. * @param name logger name. * @return true if logger exists. */ static LoggerPtr exists(const CFStringRef& name); #endif /** Retrieve the appropriate Logger instance. * @param name logger name. * @return logger. */ static LoggerPtr getLoggerLS(const LogString& name); /** Retrieve the appropriate Logger instance. * @param name logger name. * @param factory logger factory. * @return logger. */ static LoggerPtr getLoggerLS(const LogString& name, const spi::LoggerFactoryPtr& factory); /** * Determines if logger name exists in the hierarchy. * @param name logger name. * @return true if logger exists. */ static LoggerPtr existsLS(const LogString& name); static LoggerList getCurrentLoggers(); /** Safely close and remove all appenders in all loggers including the root logger. */ static void shutdown(); /** Reset all values contained in this current {@link spi::LoggerRepository LoggerRepository} to their default. */ static void resetConfiguration(); }; // class LogManager } // namespace log4cxx #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif //_LOG4CXX_LOG_MANAGER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_STRING_H #define _LOG4CXX_STRING_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <string> #include <log4cxx/log4cxx.h> #if LOG4CXX_LOGCHAR_IS_WCHAR && LOG4CXX_LOGCHAR_IS_UTF8 && LOG4CXX_LOGCHAR_IS_UNICHAR #error only one of LOG4CXX_LOGCHAR_IS_WCHAR, LOG4CXX_LOGCHAR_IS_UTF8 or LOG4CXX_LOGCHAR_IS_UNICHAR may be true #endif #if LOG4CXX_CFSTRING_API extern "C" { typedef const struct __CFString* CFStringRef; } #endif namespace log4cxx { #if LOG4CXX_LOGCHAR_IS_UNICHAR || LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API typedef unsigned short UniChar; #endif #if LOG4CXX_LOGCHAR_IS_WCHAR typedef wchar_t logchar; #define LOG4CXX_STR(str) L ## str #endif #if LOG4CXX_LOGCHAR_IS_UTF8 typedef char logchar; #if LOG4CXX_CHARSET_EBCDIC #define LOG4CXX_STR(str) log4cxx::helpers::Transcoder::decode(str) #else #define LOG4CXX_STR(str) str #endif #endif #if LOG4CXX_LOGCHAR_IS_UNICHAR typedef UniChar logchar; #define LOG4CXX_STR(str) log4cxx::helpers::Transcoder::decode(str) #endif typedef std::basic_string<logchar> LogString; } #if !defined(LOG4CXX_EOL) #if defined(_WIN32) #define LOG4CXX_EOL LOG4CXX_STR("\x0D\x0A") #else #define LOG4CXX_EOL LOG4CXX_STR("\x0A") #endif #endif #if LOG4CXX_LOGCHAR_IS_UNICHAR || (LOG4CXX_LOGCHAR_IS_UTF8 || LOG4CXX_CHARSET_EBCDIC) #include <log4cxx/helpers/transcoder.h> #endif #if defined(_MSC_VER) #pragma warning (pop) #endif #endif //_LOG4CXX_STRING_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_DEFAULT_LOGGER_FACTORY_H #define _LOG4CXX_DEFAULT_LOGGER_FACTORY_H #include <log4cxx/spi/loggerfactory.h> #include <log4cxx/helpers/objectimpl.h> namespace log4cxx { class Logger; typedef helpers::ObjectPtrT<Logger> LoggerPtr; class LOG4CXX_EXPORT DefaultLoggerFactory : public virtual spi::LoggerFactory, public virtual helpers::ObjectImpl { public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(DefaultLoggerFactory) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(spi::LoggerFactory) END_LOG4CXX_CAST_MAP() virtual LoggerPtr makeNewLoggerInstance( log4cxx::helpers::Pool& pool, const LogString& name) const; }; } // namespace log4cxx #endif //_LOG4CXX_DEFAULT_LOGGER_FACTORY_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_LOGGER_H #define _LOG4CXX_LOGGER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/helpers/appenderattachableimpl.h> #include <log4cxx/level.h> #include <log4cxx/helpers/pool.h> #include <log4cxx/helpers/mutex.h> #include <log4cxx/spi/location/locationinfo.h> #include <log4cxx/helpers/resourcebundle.h> #include <log4cxx/helpers/messagebuffer.h> namespace log4cxx { namespace helpers { class synchronized; } namespace spi { class LoggerRepository; LOG4CXX_PTR_DEF(LoggerRepository); class LoggerFactory; LOG4CXX_PTR_DEF(LoggerFactory); } class Logger; /** smart pointer to a Logger class */ LOG4CXX_PTR_DEF(Logger); LOG4CXX_LIST_DEF(LoggerList, LoggerPtr); /** This is the central class in the log4cxx package. Most logging operations, except configuration, are done through this class. */ class LOG4CXX_EXPORT Logger : public virtual log4cxx::spi::AppenderAttachable, public virtual helpers::ObjectImpl { public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(Logger) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(Logger) LOG4CXX_CAST_ENTRY(spi::AppenderAttachable) END_LOG4CXX_CAST_MAP() private: /** * Reference to memory pool. */ helpers::Pool* pool; protected: /** The name of this logger. */ LogString name; /** The assigned level of this logger. The <code>level</code> variable need not be assigned a value in which case it is inherited form the hierarchy. */ LevelPtr level; /** The parent of this logger. All loggers have at least one ancestor which is the root logger. */ LoggerPtr parent; /** The resourceBundle for localized messages. @see setResourceBundle, getResourceBundle */ helpers::ResourceBundlePtr resourceBundle; // Loggers need to know what Hierarchy they are in log4cxx::spi::LoggerRepository * repository; helpers::AppenderAttachableImplPtr aai; /** 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; protected: friend class DefaultLoggerFactory; /** This constructor created a new <code>logger</code> instance and sets its name. <p>It is intended to be used by sub-classes only. You should not create categories directly. @param pool lifetime of pool must be longer than logger. @param name The name of the logger. */ Logger(log4cxx::helpers::Pool& pool, const LogString& name); public: ~Logger(); void addRef() const; void releaseRef() const; /** Add <code>newAppender</code> to the list of appenders of this Logger instance. <p>If <code>newAppender</code> is already in the list of appenders, then it won't be added again. */ virtual void addAppender(const AppenderPtr& newAppender); /** Call the appenders in the hierrachy starting at <code>this</code>. If no appenders could be found, emit a warning. <p>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. @param p memory pool for any allocations needed to process request. */ void callAppenders(const log4cxx::spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p) const; /** Close all attached appenders implementing the AppenderAttachable interface. */ void closeNestedAppenders(); /** Log a message string with the DEBUG level. <p>This method first checks if this logger is <code>DEBUG</code> enabled by comparing the level of this logger with the DEBUG level. If this logger is <code>DEBUG</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void debug(const std::string& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the DEBUG level. <p>This method first checks if this logger is <code>DEBUG</code> enabled by comparing the level of this logger with the DEBUG level. If this logger is <code>DEBUG</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void debug(const std::string& msg) const; #if LOG4CXX_WCHAR_T_API /** Log a message string with the DEBUG level. <p>This method first checks if this logger is <code>DEBUG</code> enabled by comparing the level of this logger with the DEBUG level. If this logger is <code>DEBUG</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void debug(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the DEBUG level. <p>This method first checks if this logger is <code>DEBUG</code> enabled by comparing the level of this logger with the DEBUG level. If this logger is <code>DEBUG</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void debug(const std::wstring& msg) const; #endif #if LOG4CXX_UNICHAR_API /** Log a message string with the DEBUG level. <p>This method first checks if this logger is <code>DEBUG</code> enabled by comparing the level of this logger with the DEBUG level. If this logger is <code>DEBUG</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void debug(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the DEBUG level. <p>This method first checks if this logger is <code>DEBUG</code> enabled by comparing the level of this logger with the DEBUG level. If this logger is <code>DEBUG</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void debug(const std::basic_string<UniChar>& msg) const; #endif #if LOG4CXX_CFSTRING_API /** Log a message string with the DEBUG level. <p>This method first checks if this logger is <code>DEBUG</code> enabled by comparing the level of this logger with the DEBUG level. If this logger is <code>DEBUG</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void debug(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the DEBUG level. <p>This method first checks if this logger is <code>DEBUG</code> enabled by comparing the level of this logger with the DEBUG level. If this logger is <code>DEBUG</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void debug(const CFStringRef& msg) const; #endif /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void error(const std::string& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void error(const std::string& msg) const; #if LOG4CXX_WCHAR_T_API /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void error(const std::wstring& msg) const; /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void error(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const; #endif #if LOG4CXX_UNICHAR_API /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void error(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void error(const std::basic_string<UniChar>& msg) const; #endif #if LOG4CXX_CFSTRING_API /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void error(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void error(const CFStringRef& msg) const; #endif /** Log a message string with the FATAL level. <p>This method first checks if this logger is <code>FATAL</code> enabled by comparing the level of this logger with the FATAL level. If this logger is <code>FATAL</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void fatal(const std::string& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void fatal(const std::string& msg) const; #if LOG4CXX_WCHAR_T_API /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void fatal(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void fatal(const std::wstring& msg) const; #endif #if LOG4CXX_UNICHAR_API /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void fatal(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void fatal(const std::basic_string<UniChar>& msg) const; #endif #if LOG4CXX_CFSTRING_API /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void fatal(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the ERROR level. <p>This method first checks if this logger is <code>ERROR</code> enabled by comparing the level of this logger with the ERROR level. If this logger is <code>ERROR</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void fatal(const CFStringRef& msg) const; #endif /** This method creates a new logging event and logs the event without further checks. @param level the level to log. @param message message. @param location location of source of logging request. */ void forcedLog(const LevelPtr& level, const std::string& message, const log4cxx::spi::LocationInfo& location) const; /** This method creates a new logging event and logs the event without further checks. @param level the level to log. @param message message. */ void forcedLog(const LevelPtr& level, const std::string& message) const; #if LOG4CXX_WCHAR_T_API /** This method creates a new logging event and logs the event without further checks. @param level the level to log. @param message message. @param location location of source of logging request. */ void forcedLog(const LevelPtr& level, const std::wstring& message, const log4cxx::spi::LocationInfo& location) const; /** This method creates a new logging event and logs the event without further checks. @param level the level to log. @param message message. */ void forcedLog(const LevelPtr& level, const std::wstring& message) const; #endif #if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API /** This method creates a new logging event and logs the event without further checks. @param level the level to log. @param message message. @param location location of source of logging request. */ void forcedLog(const LevelPtr& level, const std::basic_string<UniChar>& message, const log4cxx::spi::LocationInfo& location) const; /** This method creates a new logging event and logs the event without further checks. @param level the level to log. @param message message. */ void forcedLog(const LevelPtr& level, const std::basic_string<UniChar>& message) const; #endif #if LOG4CXX_CFSTRING_API /** This method creates a new logging event and logs the event without further checks. @param level the level to log. @param message message. @param location location of source of logging request. */ void forcedLog(const LevelPtr& level, const CFStringRef& message, const log4cxx::spi::LocationInfo& location) const; /** This method creates a new logging event and logs the event without further checks. @param level the level to log. @param message message. */ void forcedLog(const LevelPtr& level, const CFStringRef& message) const; #endif /** This method creates a new logging event and logs the event without further checks. @param level the level to log. @param message the message string to log. @param location location of the logging statement. */ void forcedLogLS(const LevelPtr& level, const LogString& message, const log4cxx::spi::LocationInfo& location) const; /** Get the additivity flag for this Logger instance. */ bool getAdditivity() const; /** Get the appenders contained in this logger as an AppenderList. If no appenders can be found, then an empty AppenderList is returned. @return AppenderList An collection of the appenders in this logger.*/ AppenderList getAllAppenders() const; /** Look for the appender named as <code>name</code>. <p>Return the appender with that name if in the list. Return <code>NULL</code> otherwise. */ AppenderPtr getAppender(const LogString& name) const; /** Starting from this logger, search the logger hierarchy for a non-null level and return it. <p>The Logger class is designed so that this method executes as quickly as possible. @throws RuntimeException if all levels are null in the hierarchy */ virtual const LevelPtr& getEffectiveLevel() const; /** Return the the LoggerRepository where this <code>Logger</code> is attached. */ log4cxx::spi::LoggerRepositoryPtr getLoggerRepository() const; /** * Get the logger name. * @return logger name as LogString. */ const LogString getName() const { return name; } /** * Get logger name in current encoding. * @param name buffer to which name is appended. */ void getName(std::string& name) const; #if LOG4CXX_WCHAR_T_API /** * Get logger name. * @param name buffer to which name is appended. */ void getName(std::wstring& name) const; #endif #if LOG4CXX_UNICHAR_API /** * Get logger name. * @param name buffer to which name is appended. */ void getName(std::basic_string<UniChar>& name) const; #endif #if LOG4CXX_CFSTRING_API /** * Get logger name. * @param name buffer to which name is appended. */ void getName(CFStringRef& name) const; #endif /** Returns the parent of this logger. Note that the parent of a given logger may change during the lifetime of the logger. <p>The root logger will return <code>0</code>. */ LoggerPtr getParent() const; /** Returns the assigned Level, if any, for this Logger. @return Level - the assigned Level, can be null. */ LevelPtr getLevel() const; /** * Retrieve a logger by name in current encoding. * @param name logger name. */ static LoggerPtr getLogger(const std::string& name); /** * Retrieve a logger by name in current encoding. * @param name logger name. */ static LoggerPtr getLogger(const char* const name); #if LOG4CXX_WCHAR_T_API /** * Retrieve a logger by name. * @param name logger name. */ static LoggerPtr getLogger(const std::wstring& name); /** * Retrieve a logger by name. * @param name logger name. */ static LoggerPtr getLogger(const wchar_t* const name); #endif #if LOG4CXX_UNICHAR_API /** * Retrieve a logger by name. * @param name logger name. */ static LoggerPtr getLogger(const std::basic_string<UniChar>& name); #endif #if LOG4CXX_CFSTRING_API /** * Retrieve a logger by name. * @param name logger name. */ static LoggerPtr getLogger(const CFStringRef& name); #endif /** * Retrieve a logger by name in Unicode. * @param name logger name. */ static LoggerPtr getLoggerLS(const LogString& name); /** Retrieve the root logger. */ static LoggerPtr getRootLogger(); /** Like #getLogger except that the type of logger instantiated depends on the type returned by the LoggerFactory#makeNewLoggerInstance method of the <code>factory</code> parameter. <p>This method is intended to be used by sub-classes. @param name The name of the logger to retrieve. @param factory A LoggerFactory implementation that will actually create a new Instance. */ static LoggerPtr getLoggerLS(const LogString& name, const log4cxx::spi::LoggerFactoryPtr& factory); /** Like #getLogger except that the type of logger instantiated depends on the type returned by the LoggerFactory#makeNewLoggerInstance method of the <code>factory</code> parameter. <p>This method is intended to be used by sub-classes. @param name The name of the logger to retrieve. @param factory A LoggerFactory implementation that will actually create a new Instance. */ static LoggerPtr getLogger(const std::string& name, const log4cxx::spi::LoggerFactoryPtr& factory); #if LOG4CXX_WCHAR_T_API /** Like #getLogger except that the type of logger instantiated depends on the type returned by the LoggerFactory#makeNewLoggerInstance method of the <code>factory</code> parameter. <p>This method is intended to be used by sub-classes. @param name The name of the logger to retrieve. @param factory A LoggerFactory implementation that will actually create a new Instance. */ static LoggerPtr getLogger(const std::wstring& name, const log4cxx::spi::LoggerFactoryPtr& factory); #endif #if LOG4CXX_UNICHAR_API /** Like #getLogger except that the type of logger instantiated depends on the type returned by the LoggerFactory#makeNewLoggerInstance method of the <code>factory</code> parameter. <p>This method is intended to be used by sub-classes. @param name The name of the logger to retrieve. @param factory A LoggerFactory implementation that will actually create a new Instance. */ static LoggerPtr getLogger(const std::basic_string<UniChar>& name, const log4cxx::spi::LoggerFactoryPtr& factory); #endif #if LOG4CXX_CFSTRING_API /** Like #getLogger except that the type of logger instantiated depends on the type returned by the LoggerFactory#makeNewLoggerInstance method of the <code>factory</code> parameter. <p>This method is intended to be used by sub-classes. @param name The name of the logger to retrieve. @param factory A LoggerFactory implementation that will actually create a new Instance. */ static LoggerPtr getLogger(const CFStringRef& name, const log4cxx::spi::LoggerFactoryPtr& factory); #endif /** Return the <em>inherited</em> ResourceBundle for this logger. This method walks the hierarchy to find the appropriate resource bundle. It will return the resource bundle attached to the closest ancestor of this logger, much like the way priorities are searched. In case there is no bundle in the hierarchy then <code>NULL</code> is returned. */ helpers::ResourceBundlePtr getResourceBundle() const; protected: /** Returns the string resource coresponding to <code>key</code> in this logger's inherited resource bundle. If the resource cannot be found, then an {@link #error error} message will be logged complaining about the missing resource. @see #getResourceBundle. */ LogString getResourceBundleString(const LogString& key) const; public: /** Log a message string with the INFO level. <p>This method first checks if this logger is <code>INFO</code> enabled by comparing the level of this logger with the INFO level. If this logger is <code>INFO</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void info(const std::string& msg, const log4cxx::spi::LocationInfo& location) const; void info(const std::string& msg) const; #if LOG4CXX_WCHAR_T_API /** Log a message string with the INFO level. <p>This method first checks if this logger is <code>INFO</code> enabled by comparing the level of this logger with the INFO level. If this logger is <code>INFO</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void info(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the INFO level. <p>This method first checks if this logger is <code>INFO</code> enabled by comparing the level of this logger with the INFO level. If this logger is <code>INFO</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void info(const std::wstring& msg) const; #endif #if LOG4CXX_UNICHAR_API /** Log a message string with the INFO level. <p>This method first checks if this logger is <code>INFO</code> enabled by comparing the level of this logger with the INFO level. If this logger is <code>INFO</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void info(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the INFO level. <p>This method first checks if this logger is <code>INFO</code> enabled by comparing the level of this logger with the INFO level. If this logger is <code>INFO</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void info(const std::basic_string<UniChar>& msg) const; #endif #if LOG4CXX_CFSTRING_API /** Log a message string with the INFO level. <p>This method first checks if this logger is <code>INFO</code> enabled by comparing the level of this logger with the INFO level. If this logger is <code>INFO</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void info(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the INFO level. <p>This method first checks if this logger is <code>INFO</code> enabled by comparing the level of this logger with the INFO level. If this logger is <code>INFO</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void info(const CFStringRef& msg) const; #endif /** Is the appender passed as parameter attached to this logger? */ bool isAttached(const AppenderPtr& appender) const; /** * Check whether this logger is enabled for the <code>DEBUG</code> * Level. * * <p> This function is intended to lessen the computational cost of * disabled log debug statements. * * <p> For some <code>logger</code> Logger object, when you write, * <pre> * logger->debug("debug message"); * </pre> * * <p>You incur the cost constructing the message, concatenation in * this case, regardless of whether the message is logged or not. * * <p>If you are worried about speed, then you should write * <pre> * if(logger->isDebugEnabled()) { * logger->debug("debug message"); * } * </pre> * * <p>This way you will not incur the cost of parameter * construction if debugging is disabled for <code>logger</code>. On * the other hand, if the <code>logger</code> is debug enabled, you * will incur the cost of evaluating whether the logger is debug * enabled twice. Once in <code>isDebugEnabled</code> and once in * the <code>debug</code>. This is an insignificant overhead * since evaluating a logger takes about 1%% of the time it * takes to actually log. * * @return bool - <code>true</code> if this logger is debug * enabled, <code>false</code> otherwise. * */ bool isDebugEnabled() const; /** Check whether this logger is enabled for a given Level passed as parameter. See also #isDebugEnabled. @return bool True if this logger is enabled for <code>level</code>. */ bool isEnabledFor(const LevelPtr& level) const; /** Check whether this logger is enabled for the info Level. See also #isDebugEnabled. @return bool - <code>true</code> if this logger is enabled for level info, <code>false</code> otherwise. */ bool isInfoEnabled() const; /** Check whether this logger is enabled for the warn Level. See also #isDebugEnabled. @return bool - <code>true</code> if this logger is enabled for level warn, <code>false</code> otherwise. */ bool isWarnEnabled() const; /** Check whether this logger is enabled for the error Level. See also #isDebugEnabled. @return bool - <code>true</code> if this logger is enabled for level error, <code>false</code> otherwise. */ bool isErrorEnabled() const; /** Check whether this logger is enabled for the fatal Level. See also #isDebugEnabled. @return bool - <code>true</code> if this logger is enabled for level fatal, <code>false</code> otherwise. */ bool isFatalEnabled() const; /** Check whether this logger is enabled for the trace level. See also #isDebugEnabled. @return bool - <code>true</code> if this logger is enabled for level trace, <code>false</code> otherwise. */ bool isTraceEnabled() const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @param values The values for the placeholders <code>{0}</code>, <code>{1}</code> etc. within the pattern. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const LogString& key, const log4cxx::spi::LocationInfo& locationInfo, const std::vector<LogString>& values) const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const std::string& key, const log4cxx::spi::LocationInfo& locationInfo) const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @param val1 The first value for the placeholders within the pattern. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const std::string& key, const log4cxx::spi::LocationInfo& locationInfo, const std::string& val1) const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @param val1 The first value for the placeholders within the pattern. @param val2 The second value for the placeholders within the pattern. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const std::string& key, const log4cxx::spi::LocationInfo& locationInfo, const std::string& val1, const std::string& val2) const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @param val1 The value for the first placeholder within the pattern. @param val2 The value for the second placeholder within the pattern. @param val3 The value for the third placeholder within the pattern. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const std::string& key, const log4cxx::spi::LocationInfo& locationInfo, const std::string& val1, const std::string& val2, const std::string& val3) const; #if LOG4CXX_WCHAR_T_API /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const std::wstring& key, const log4cxx::spi::LocationInfo& locationInfo) const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @param val1 The value for the first placeholder within the pattern. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const std::wstring& key, const log4cxx::spi::LocationInfo& locationInfo, const std::wstring& val1) const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @param val1 The value for the first placeholder within the pattern. @param val2 The value for the second placeholder within the pattern. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const std::wstring& key, const log4cxx::spi::LocationInfo& locationInfo, const std::wstring& val1, const std::wstring& val2) const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @param val1 The value for the first placeholder within the pattern. @param val2 The value for the second placeholder within the pattern. @param val3 The value for the third placeholder within the pattern. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const std::wstring& key, const log4cxx::spi::LocationInfo& locationInfo, const std::wstring& val1, const std::wstring& val2, const std::wstring& val3) const; #endif #if LOG4CXX_UNICHAR_API /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const std::basic_string<UniChar>& key, const log4cxx::spi::LocationInfo& locationInfo) const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @param val1 The value for the first placeholder within the pattern. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const std::basic_string<UniChar>& key, const log4cxx::spi::LocationInfo& locationInfo, const std::basic_string<UniChar>& val1) const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @param val1 The value for the first placeholder within the pattern. @param val2 The value for the second placeholder within the pattern. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const std::basic_string<UniChar>& key, const log4cxx::spi::LocationInfo& locationInfo, const std::basic_string<UniChar>& val1, const std::basic_string<UniChar>& val2) const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @param val1 The value for the first placeholder within the pattern. @param val2 The value for the second placeholder within the pattern. @param val3 The value for the third placeholder within the pattern. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const std::basic_string<UniChar>& key, const log4cxx::spi::LocationInfo& locationInfo, const std::basic_string<UniChar>& val1, const std::basic_string<UniChar>& val2, const std::basic_string<UniChar>& val3) const; #endif #if LOG4CXX_CFSTRING_API /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const CFStringRef& key, const log4cxx::spi::LocationInfo& locationInfo) const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @param val1 The value for the first placeholder within the pattern. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const CFStringRef& key, const log4cxx::spi::LocationInfo& locationInfo, const CFStringRef& val1) const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @param val1 The value for the first placeholder within the pattern. @param val2 The value for the second placeholder within the pattern. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const CFStringRef& key, const log4cxx::spi::LocationInfo& locationInfo, const CFStringRef& val1, const CFStringRef& val2) const; /** Log a localized and parameterized message. First, the user supplied <code>key</code> is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied string array <code>params</code>. @param level The level of the logging request. @param key The key to be searched in the ResourceBundle. @param locationInfo The location info of the logging request. @param val1 The value for the first placeholder within the pattern. @param val2 The value for the second placeholder within the pattern. @param val3 The value for the third placeholder within the pattern. @see #setResourceBundle */ void l7dlog(const LevelPtr& level, const CFStringRef& key, const log4cxx::spi::LocationInfo& locationInfo, const CFStringRef& val1, const CFStringRef& val2, const CFStringRef& val3) const; #endif /** This is the most generic printing method. It is intended to be invoked by <b>wrapper</b> classes. @param level The level of the logging request. @param message The message of the logging request. @param location The source file of the logging request, may be null. */ void log(const LevelPtr& level, const std::string& message, const log4cxx::spi::LocationInfo& location) const; /** This is the most generic printing method. It is intended to be invoked by <b>wrapper</b> classes. @param level The level of the logging request. @param message The message of the logging request. */ void log(const LevelPtr& level, const std::string& message) const; #if LOG4CXX_WCHAR_T_API /** This is the most generic printing method. It is intended to be invoked by <b>wrapper</b> classes. @param level The level of the logging request. @param message The message of the logging request. @param location The source file of the logging request, may be null. */ void log(const LevelPtr& level, const std::wstring& message, const log4cxx::spi::LocationInfo& location) const; /** This is the most generic printing method. It is intended to be invoked by <b>wrapper</b> classes. @param level The level of the logging request. @param message The message of the logging request. */ void log(const LevelPtr& level, const std::wstring& message) const; #endif #if LOG4CXX_UNICHAR_API /** This is the most generic printing method. It is intended to be invoked by <b>wrapper</b> classes. @param level The level of the logging request. @param message The message of the logging request. @param location The source file of the logging request, may be null. */ void log(const LevelPtr& level, const std::basic_string<UniChar>& message, const log4cxx::spi::LocationInfo& location) const; /** This is the most generic printing method. It is intended to be invoked by <b>wrapper</b> classes. @param level The level of the logging request. @param message The message of the logging request. */ void log(const LevelPtr& level, const std::basic_string<UniChar>& message) const; #endif #if LOG4CXX_CFSTRING_API /** This is the most generic printing method. It is intended to be invoked by <b>wrapper</b> classes. @param level The level of the logging request. @param message The message of the logging request. @param location The source file of the logging request, may be null. */ void log(const LevelPtr& level, const CFStringRef& message, const log4cxx::spi::LocationInfo& location) const; /** This is the most generic printing method. It is intended to be invoked by <b>wrapper</b> classes. @param level The level of the logging request. @param message The message of the logging request. */ void log(const LevelPtr& level, const CFStringRef& message) const; #endif /** This is the most generic printing method. It is intended to be invoked by <b>wrapper</b> classes. @param level The level of the logging request. @param message The message of the logging request. @param location The source file of the logging request, may be null. */ void logLS(const LevelPtr& level, const LogString& message, const log4cxx::spi::LocationInfo& location) const; /** Remove all previously added appenders from this logger instance. <p>This is useful when re-reading configuration information. */ void removeAllAppenders(); /** Remove the appender passed as parameter form the list of appenders. */ void removeAppender(const AppenderPtr& appender); /** Remove the appender with the name passed as parameter form the list of appenders. */ void removeAppender(const LogString& name); /** Set the additivity flag for this Logger instance. */ void setAdditivity(bool additive); protected: friend class Hierarchy; /** Only the Hierarchy class can set the hierarchy of a logger.*/ void setHierarchy(spi::LoggerRepository * repository); public: /** Set the level of this Logger. <p>As in <pre> &nbsp;&nbsp;&nbsp;logger->setLevel(Level::getDebug()); </pre> <p>Null values are admitted. */ virtual void setLevel(const LevelPtr& level); /** Set the resource bundle to be used with localized logging methods. */ inline void setResourceBundle(const helpers::ResourceBundlePtr& bundle) { resourceBundle = bundle; } #if LOG4CXX_WCHAR_T_API /** Log a message string with the WARN level. <p>This method first checks if this logger is <code>WARN</code> enabled by comparing the level of this logger with the WARN level. If this logger is <code>WARN</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void warn(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the WARN level. <p>This method first checks if this logger is <code>WARN</code> enabled by comparing the level of this logger with the WARN level. If this logger is <code>WARN</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void warn(const std::wstring& msg) const; #endif #if LOG4CXX_UNICHAR_API /** Log a message string with the WARN level. <p>This method first checks if this logger is <code>WARN</code> enabled by comparing the level of this logger with the WARN level. If this logger is <code>WARN</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void warn(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the WARN level. <p>This method first checks if this logger is <code>WARN</code> enabled by comparing the level of this logger with the WARN level. If this logger is <code>WARN</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void warn(const std::basic_string<UniChar>& msg) const; #endif #if LOG4CXX_CFSTRING_API /** Log a message string with the WARN level. <p>This method first checks if this logger is <code>WARN</code> enabled by comparing the level of this logger with the WARN level. If this logger is <code>WARN</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void warn(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the WARN level. <p>This method first checks if this logger is <code>WARN</code> enabled by comparing the level of this logger with the WARN level. If this logger is <code>WARN</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void warn(const CFStringRef& msg) const; #endif /** Log a message string with the WARN level. <p>This method first checks if this logger is <code>WARN</code> enabled by comparing the level of this logger with the WARN level. If this logger is <code>WARN</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void warn(const std::string& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the WARN level. <p>This method first checks if this logger is <code>WARN</code> enabled by comparing the level of this logger with the WARN level. If this logger is <code>WARN</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void warn(const std::string& msg) const; #if LOG4CXX_WCHAR_T_API /** Log a message string with the TRACE level. <p>This method first checks if this logger is <code>TRACE</code> enabled by comparing the level of this logger with the TRACE level. If this logger is <code>TRACE</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void trace(const std::wstring& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the TRACE level. <p>This method first checks if this logger is <code>TRACE</code> enabled by comparing the level of this logger with the TRACE level. If this logger is <code>TRACE</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void trace(const std::wstring& msg) const; #endif #if LOG4CXX_UNICHAR_API /** Log a message string with the TRACE level. <p>This method first checks if this logger is <code>TRACE</code> enabled by comparing the level of this logger with the TRACE level. If this logger is <code>TRACE</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void trace(const std::basic_string<UniChar>& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the TRACE level. <p>This method first checks if this logger is <code>TRACE</code> enabled by comparing the level of this logger with the TRACE level. If this logger is <code>TRACE</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void trace(const std::basic_string<UniChar>& msg) const; #endif #if LOG4CXX_CFSTRING_API /** Log a message string with the TRACE level. <p>This method first checks if this logger is <code>TRACE</code> enabled by comparing the level of this logger with the TRACE level. If this logger is <code>TRACE</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void trace(const CFStringRef& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the TRACE level. <p>This method first checks if this logger is <code>TRACE</code> enabled by comparing the level of this logger with the TRACE level. If this logger is <code>TRACE</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void trace(const CFStringRef& msg) const; #endif /** Log a message string with the TRACE level. <p>This method first checks if this logger is <code>TRACE</code> enabled by comparing the level of this logger with the TRACE level. If this logger is <code>TRACE</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. @param location location of source of logging request. */ void trace(const std::string& msg, const log4cxx::spi::LocationInfo& location) const; /** Log a message string with the TRACE level. <p>This method first checks if this logger is <code>TRACE</code> enabled by comparing the level of this logger with the TRACE level. If this logger is <code>TRACE</code> enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag. @param msg the message string to log. */ void trace(const std::string& msg) const; inline const log4cxx::helpers::Mutex& getMutex() const { return mutex; } private: // // prevent copy and assignment Logger(const Logger&); Logger& operator=(const Logger&); log4cxx::helpers::Mutex mutex; friend class log4cxx::helpers::synchronized; }; LOG4CXX_LIST_DEF(LoggerList, LoggerPtr); } /** @addtogroup LoggingMacros Logging macros @{ */ #if !defined(LOG4CXX_UNLIKELY) #if __GNUC__ >= 3 /** Provides optimization hint to the compiler to optimize for the expression being false. @param expr boolean expression. @returns value of expression. */ #define LOG4CXX_UNLIKELY(expr) __builtin_expect(expr, 0) #else /** Provides optimization hint to the compiler to optimize for the expression being false. @param expr boolean expression. @returns value of expression. **/ #define LOG4CXX_UNLIKELY(expr) expr #endif #endif /** Logs a message to a specified logger with a specified level. @param logger the logger to be used. @param level the level to log. @param message the message string to log. */ #define LOG4CXX_LOG(logger, level, message) { \ if (logger->isEnabledFor(level)) {\ ::log4cxx::helpers::MessageBuffer oss_; \ logger->forcedLog(level, oss_.str(oss_ << message), LOG4CXX_LOCATION); } } /** Logs a message to a specified logger with a specified level. @param logger the logger to be used. @param level the level to log. @param message the message string to log in the internal encoding. */ #define LOG4CXX_LOGLS(logger, level, message) { \ if (logger->isEnabledFor(level)) {\ ::log4cxx::helpers::LogCharMessageBuffer oss_; \ logger->forcedLog(level, oss_.str(oss_ << message), LOG4CXX_LOCATION); } } /** Logs a message to a specified logger with the DEBUG level. @param logger the logger to be used. @param message the message string to log. */ #define LOG4CXX_DEBUG(logger, message) { \ if (LOG4CXX_UNLIKELY(logger->isDebugEnabled())) {\ ::log4cxx::helpers::MessageBuffer oss_; \ logger->forcedLog(::log4cxx::Level::getDebug(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} /** Logs a message to a specified logger with the TRACE level. @param logger the logger to be used. @param message the message string to log. */ #define LOG4CXX_TRACE(logger, message) { \ if (LOG4CXX_UNLIKELY(logger->isTraceEnabled())) {\ ::log4cxx::helpers::MessageBuffer oss_; \ logger->forcedLog(::log4cxx::Level::getTrace(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} /** Logs a message to a specified logger with the INFO level. @param logger the logger to be used. @param message the message string to log. */ #define LOG4CXX_INFO(logger, message) { \ if (logger->isInfoEnabled()) {\ ::log4cxx::helpers::MessageBuffer oss_; \ logger->forcedLog(::log4cxx::Level::getInfo(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} /** Logs a message to a specified logger with the WARN level. @param logger the logger to be used. @param message the message string to log. */ #define LOG4CXX_WARN(logger, message) { \ if (logger->isWarnEnabled()) {\ ::log4cxx::helpers::MessageBuffer oss_; \ logger->forcedLog(::log4cxx::Level::getWarn(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} /** Logs a message to a specified logger with the ERROR level. @param logger the logger to be used. @param message the message string to log. */ #define LOG4CXX_ERROR(logger, message) { \ if (logger->isErrorEnabled()) {\ ::log4cxx::helpers::MessageBuffer oss_; \ logger->forcedLog(::log4cxx::Level::getError(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} /** Logs a error if the condition is not true. @param logger the logger to be used. @param condition condition @param message the message string to log. */ #define LOG4CXX_ASSERT(logger, condition, message) { \ if (!(condition) && logger->isErrorEnabled()) {\ ::log4cxx::helpers::MessageBuffer oss_; \ logger->forcedLog(::log4cxx::Level::getError(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} /** Logs a message to a specified logger with the FATAL level. @param logger the logger to be used. @param message the message string to log. */ #define LOG4CXX_FATAL(logger, message) { \ if (logger->isFatalEnabled()) {\ ::log4cxx::helpers::MessageBuffer oss_; \ logger->forcedLog(::log4cxx::Level::getFatal(), oss_.str(oss_ << message), LOG4CXX_LOCATION); }} /** Logs a localized message with no parameter. @param logger the logger to be used. @param level the level to log. @param key the key to be searched in the resourceBundle of the logger. */ #define LOG4CXX_L7DLOG(logger, level, key) { \ if (logger->isEnabledFor(level)) {\ logger->l7dlog(level, key, LOG4CXX_LOCATION); }} /** Logs a localized message with one parameter. @param logger the logger to be used. @param level the level to log. @param key the key to be searched in the resourceBundle of the logger. @param p1 the unique parameter. */ #define LOG4CXX_L7DLOG1(logger, level, key, p1) { \ if (logger->isEnabledFor(level)) {\ logger->l7dlog(level, key, LOG4CXX_LOCATION, p1); }} /** Logs a localized message with two parameters. @param logger the logger to be used. @param level the level to log. @param key the key to be searched in the resourceBundle of the logger. @param p1 the first parameter. @param p2 the second parameter. */ #define LOG4CXX_L7DLOG2(logger, level, key, p1, p2) { \ if (logger->isEnabledFor(level)) {\ logger->l7dlog(level, key, LOG4CXX_LOCATION, p1, p2); }} /** Logs a localized message with three parameters. @param logger the logger to be used. @param level the level to log. @param key the key to be searched in the resourceBundle of the logger. @param p1 the first parameter. @param p2 the second parameter. @param p3 the third parameter. */ #define LOG4CXX_L7DLOG3(logger, level, key, p1, p2, p3) { \ if (logger->isEnabledFor(level)) {\ logger->l7dlog(level, key, LOG4CXX_LOCATION, p1, p2, p3); }} /**@}*/ #if defined(_MSC_VER) #pragma warning ( pop ) #endif #include <log4cxx/spi/loggerrepository.h> #endif //_LOG4CXX_LOGGER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PROPERTY_CONFIGURATOR_H #define _LOG4CXX_PROPERTY_CONFIGURATOR_H #if defined(_MSC_VER) #pragma warning (push) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/helpers/objectptr.h> #include <log4cxx/helpers/objectimpl.h> #include <log4cxx/logstring.h> #include <log4cxx/spi/configurator.h> #include <map> #include <log4cxx/file.h> namespace log4cxx { class Logger; typedef helpers::ObjectPtrT<Logger> LoggerPtr; class Appender; typedef helpers::ObjectPtrT<Appender> AppenderPtr; namespace helpers { class Properties; } namespace spi { class LoggerFactory; } /** Allows the configuration of log4cxx from an external file. See <b>{@link #doConfigure(const File&, log4cxx::spi::LoggerRepositoryPtr&)}</b> for the expected format. <p>It is sometimes useful to see how log4cxx is reading configuration files. You can enable log4cxx internal logging by defining the <b>log4j.debug</b> variable. <P>At class initialization time class, the file <b>log4j.properties</b> will be searched in the current directory. If the file can be found, then it will be fed to the {@link PropertyConfigurator#configure(const File& configFilename)} method. <p>The <code>PropertyConfigurator</code> does not handle the advanced configuration features supported by the {@link xml::DOMConfigurator DOMConfigurator} such as support for {@link spi::Filter Filters}, custom {@link spi::ErrorHandler ErrorHandlers}, nested appenders such as the {@link AsyncAppender AsyncAppender}, etc. <p>All option <em>values</em> admit variable substitution. 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. The value of the substituted variable can be defined as a system property or in the configuration file itself. The value of the key is first searched in the system properties, and if not found there, it is then searched in the configuration file being parsed. The corresponding value replaces the ${variableName} sequence. For example, if <code>java.home</code> system property is set to <code>/home/xyz</code>, then every occurrence of the sequence <code>${java.home}</code> will be interpreted as <code>/home/xyz</code>. */ class LOG4CXX_EXPORT PropertyConfigurator : virtual public spi::Configurator, virtual public helpers::ObjectImpl { protected: /** Used internally to keep track of configured appenders. */ std::map<LogString, AppenderPtr>* registry; /** Used to create new instances of logger */ helpers::ObjectPtrT<spi::LoggerFactory> loggerFactory; public: DECLARE_LOG4CXX_OBJECT(PropertyConfigurator) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(spi::Configurator) END_LOG4CXX_CAST_MAP() PropertyConfigurator(); virtual ~PropertyConfigurator(); void addRef() const; void releaseRef() const; /** Read configuration from a file. <b>The existing configuration is not cleared nor reset.</b> If you require a different behavior, then call {@link LogManager#resetConfiguration resetConfiguration} method before calling <code>doConfigure</code>. <p>The configuration file consists of statements in the format <code>key=value</code>. The syntax of different configuration elements are discussed below. <h3>Repository-wide threshold</h3> <p>The repository-wide threshold filters logging requests by level regardless of logger. The syntax is: <pre> log4j.threshold=[level] </pre> <p>The level value can consist of the string values OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL or a <em>custom level</em> value. A custom level value can be specified in the form level#classname. By default the repository-wide threshold is set to the lowest possible value, namely the level <code>ALL</code>. </p> <h3>Appender configuration</h3> <p>Appender configuration syntax is: <pre> # For appender named <i>appenderName</i>, set its class. # Note: The appender name can contain dots. log4j.appender.appenderName=fully.qualified.name.of.appender.class # Set appender specific options. log4j.appender.appenderName.option1=value1 ... log4j.appender.appenderName.optionN=valueN </pre> For each named appender you can configure its {@link Layout Layout}. The syntax for configuring an appender's layout is: <pre> log4j.appender.appenderName.layout=fully.qualified.name.of.layout.class log4j.appender.appenderName.layout.option1=value1 .... log4j.appender.appenderName.layout.optionN=valueN </pre> <h3>Configuring loggers</h3> <p>The syntax for configuring the root logger is: <pre> log4j.rootLogger=[level], appenderName, appenderName, ... </pre> <p>This syntax means that an optional <em>level</em> can be supplied followed by appender names separated by commas. <p>The level value can consist of the string values OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL or a <em>custom level</em> value. A custom level value can be specified in the form <code>level#classname</code>. <p>If a level value is specified, then the root level is set to the corresponding level. If no level value is specified, then the root level remains untouched. <p>The root logger can be assigned multiple appenders. <p>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. <p>For non-root categories the syntax is almost the same: <pre> log4j.logger.logger_name=[level|INHERITED|NULL], appenderName, appenderName, ... </pre> <p>The meaning of the optional level 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 level from the logger hierarchy. <p>If no level value is supplied, then the level of the named logger remains untouched. <p>By default categories inherit their level from the hierarchy. However, if you set the level of a logger and later decide that that logger should inherit its level, then you should specify INHERITED as the value for the level value. NULL is a synonym for INHERITED. <p>Similar to the root logger syntax, each <i>appenderName</i> (separated by commas) will be attached to the named logger. <p>See the <a href="Introduction.html#additivity">appender additivity rule</a> in the user manual for the meaning of the <code>additivity</code> flag. <h3>Logger Factories</h3> The usage of custom logger factories is discouraged and no longer documented. <h3>Example</h3> <p>An example configuration is given below. Other configuration file examples are given in the <code>examples</code> folder. <pre> # Set options for appender named "A1". # Appender "A1" will be a SyslogAppender log4j.appender.A1=SyslogAppender # The syslog daemon resides on www.abc.net log4j.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 level 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 PatternLayout for further information # on the syntax of the ConversionPattern key. log4j.appender.A1.layout=PatternLayout log4j.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. log4j.appender.A2=RollingFileAppender log4j.appender.A2.MaxFileSize=10MB log4j.appender.A2.MaxBackupIndex=1 log4j.appender.A2.layout=TTCCLayout log4j.appender.A2.layout.ContextPrinting=enabled log4j.appender.A2.layout.DateFormat=ISO8601 # Root logger set to DEBUG using the A2 appender defined above. log4j.rootLogger=DEBUG, A2 # Logger definitions: # The SECURITY logger inherits is level from root. However, it's output # will go to A1 appender defined above. It's additivity is non-cumulative. log4j.logger.SECURITY=INHERIT, A1 log4j.additivity.SECURITY=false # Only warnings or above will be logged for the logger "SECURITY.access". # Output will go to A1. log4j.logger.SECURITY.access=WARN # The logger "class.of.the.day" inherits its level from the # logger hierarchy. Output will go to the appender's of the root # logger, A2 in this case. log4j.logger.class.of.the.day=INHERIT </pre> <p>Refer to the <b>setOption</b> method in each Appender and Layout for class specific options. <p>Use the <code>#</code> or <code>!</code> characters at the beginning of a line for comments. <p> @param configFileName The name of the configuration file where the configuration information is stored. @param hierarchy The hierarchy to operation upon. */ void doConfigure(const File& configFileName, spi::LoggerRepositoryPtr& hierarchy); /** Read configuration options from file <code>configFilename</code>. */ static void configure(const File& configFilename); /** Like {@link #configureAndWatch(const File& configFilename, long delay)} except that the default delay as defined by helpers::FileWatchdog#DEFAULT_DELAY is used. @param configFilename A file in key=value format. */ static void configureAndWatch(const File& configFilename); /** Read the configuration file <code>configFilename</code> if it exists. Moreover, a thread will be created that will periodically check if <code>configFilename</code> has been created or modified. The period is determined by the <code>delay</code> argument. If a change or file creation is detected, then <code>configFilename</code> is read to configure log4j. @param configFilename A file in key=value format. @param delay The delay in milliseconds to wait between each check. */ static void configureAndWatch(const File& configFilename, long delay); /** Read configuration options from <code>properties</code>. See #doConfigure(const File&, log4cxx::spi::LoggerRepositoryPtr&) for the expected format. */ static void configure(helpers::Properties& properties); /** Read configuration options from <code>properties</code>. See #doConfigure(const File&, log4cxx::spi::LoggerRepositoryPtr&) for the expected format. */ void doConfigure(helpers::Properties& properties, spi::LoggerRepositoryPtr& hierarchy); // -------------------------------------------------------------------------- // Internal stuff // -------------------------------------------------------------------------- protected: /** Check the provided <code>Properties</code> object for a #loggerFactory entry specified by LOGGER_FACTORY_KEY. If such an entry exists, an attempt is made to create an instance using the default constructor. This instance is used for subsequent Logger creations within this configurator. @see #parseCatsAndRenderers */ void configureLoggerFactory(helpers::Properties& props); void configureRootLogger(helpers::Properties& props, spi::LoggerRepositoryPtr& hierarchy); /** Parse non-root elements, such non-root categories and renderers. */ void parseCatsAndRenderers(helpers::Properties& props, spi::LoggerRepositoryPtr& hierarchy); /** Parse the additivity option for a non-root logger. */ void parseAdditivityForLogger(helpers::Properties& props, LoggerPtr& cat, const LogString& loggerName); /** This method must work for the root logger as well. */ void parseLogger( helpers::Properties& props, LoggerPtr& logger, const LogString& optionKey, const LogString& loggerName, const LogString& value); AppenderPtr parseAppender( helpers::Properties& props, const LogString& appenderName); void registryPut(const AppenderPtr& appender); AppenderPtr registryGet(const LogString& name); private: PropertyConfigurator(const PropertyConfigurator&); PropertyConfigurator& operator=(const PropertyConfigurator&); }; // class PropertyConfigurator } // namespace log4cxx #if defined(_MSC_VER) #pragma warning (pop) #endif #endif //_LOG4CXX_PROPERTY_CONFIGURATOR_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_FILTER_LOCATIONINFOFILTER_H #define _LOG4CXX_FILTER_LOCATIONINFOFILTER_H #include <log4cxx/spi/filter.h> namespace log4cxx { namespace rule { class ExpressionRule; class Rule; typedef helpers::ObjectPtrT < Rule > RulePtr; typedef helpers::ObjectPtrT < ExpressionRule > ExpressionRulePtr; } namespace filter { /** * Location information is usually specified at the appender level - all events associated * with an appender either create and parse stack traces or they do not. This is * an expensive operation and in some cases not needed for all events associated with * an appender. * * This filter creates event-level location information only if the provided expression evaluates to true. * * For information on expression syntax, see org.apache.log4j.rule.ExpressionRule * * */ class LOG4CXX_EXPORT LocationInfoFilter:public log4cxx::spi::Filter { bool convertInFixToPostFix; LogString expression; log4cxx::rule::RulePtr expressionRule; //HACK: Category is the last of the internal layers - pass this in as the class name //in order for parsing to work correctly LogString className; public: DECLARE_LOG4CXX_OBJECT(LocationInfoFilter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(log4cxx::spi::Filter) END_LOG4CXX_CAST_MAP() LocationInfoFilter(); void activateOptions(log4cxx::helpers::Pool &); void setExpression(const LogString & expression); LogString getExpression() const; void setConvertInFixToPostFix(bool convertInFixToPostFix); bool getConvertInFixToPostFix() const; /** * If this event does not already contain location information, * evaluate the event against the expression. * * If the expression evaluates to true, generate a LocationInfo instance * by creating an exception and set this LocationInfo on the event. * * Returns {@link log4cxx::spi::Filter#NEUTRAL} */ FilterDecision decide(const spi::LoggingEventPtr & event) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_FILTER_EXPRESSIONFILTER_H #define _LOG4CXX_FILTER_EXPRESSIONFILTER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/spi/filter.h> namespace log4cxx { namespace rule { class Rule; typedef helpers::ObjectPtrT < Rule > RulePtr; } namespace filter { /** *A filter supporting complex expressions - supports both infix and postfix * expressions (infix expressions must first be converted to postfix prior * to processing). * * <p>See <code>org.apache.log4j.chainsaw.LoggingEventFieldResolver.java</code> * for the correct names for logging event fields used when building expressions. * * <p>See <code>org.apache.log4j.chainsaw.rule</code> package for a list of available * rules which can be applied using the expression syntax. * * <p>See <code>org.apache.log4j.chainsaw.RuleFactory</code> for the symbols * used to activate the corresponding rules. * *NOTE: Grouping using parentheses is supported - all tokens must be separated by spaces, and *operands which contain spaces are not yet supported. * *Example: * *In order to build a filter that displays all messages with infomsg-45 or infomsg-44 in the message, *as well as all messages with a level of WARN or higher, build an expression using *the LikeRule (supports ORO-based regular expressions) and the InequalityRule. * <b> ( MSG LIKE infomsg-4[4,5] ) && ( LEVEL >= WARN ) </b> * *Three options are required: * <b>Expression</b> - the expression to match * <b>ConvertInFixToPostFix</b> - convert from infix to posfix (default true) * <b>AcceptOnMatch</b> - true or false (default true) * * Meaning of <b>AcceptToMatch</b>: * If there is a match between the value of the * Expression option and the {@link log4cxx::spi::LoggingEvent} and AcceptOnMatch is true, * the {@link #decide} method returns {@link log4cxx::spi::Filter#ACCEPT}. * * If there is a match between the value of the * Expression option and the {@link log4cxx::spi::LoggingEvent} and AcceptOnMatch is false, * {@link log4cxx::spi::Filter#DENY} is returned. * * If there is no match, {@link log4cxx::spi::Filter#NEUTRAL} is returned. * * */ class LOG4CXX_EXPORT ExpressionFilter:public log4cxx::spi::Filter { private: bool acceptOnMatch; bool convertInFixToPostFix; LogString expression; log4cxx::rule::RulePtr expressionRule; ExpressionFilter(const ExpressionFilter &); ExpressionFilter & operator=(const ExpressionFilter &); public: DECLARE_LOG4CXX_OBJECT(ExpressionFilter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(log4cxx::spi::Filter) END_LOG4CXX_CAST_MAP() ExpressionFilter(); void activateOptions(log4cxx::helpers::Pool & p); void setExpression(const LogString & expression); LogString getExpression() const; void setConvertInFixToPostFix(bool convertInFixToPostFix); bool getConvertInFixToPostFix() const; void setAcceptOnMatch(bool acceptOnMatch); bool getAcceptOnMatch() const; /** Returns {@link log4cxx::spi::Filter#NEUTRAL} is there is no string match. */ FilterDecision decide(const spi::LoggingEventPtr & event) const; }; } } #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_FILTER_ANDFILTER_H #define _LOG4CXX_FILTER_ANDFILTER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/spi/filter.h> namespace log4cxx { namespace filter { /** * A filter that 'and's the results of any number of contained filters together. * * For the filter to process events, all contained filters must return Filter::ACCEPT. * * If the contained filters do not return Filter::ACCEPT, Filter::NEUTRAL is returned. * * If acceptOnMatch is set to true, Filter::ACCEPT is returned. * If acceptOnMatch is set to false, Filter::DENY is returned. * * Here is an example config that will accept only events that contain BOTH * a DEBUG level AND 'test' in the message: * *&lt;appender name="STDOUT" class="org.apache.log4j.ConsoleAppender"&gt; * &lt;filter class="org.apache.log4j.filter.AndFilter"&gt; * &lt;filter class="org.apache.log4j.filter.LevelMatchFilter"&gt; * &lt;param name="levelToMatch" value="DEBUG" /&gt; * &lt;param name="acceptOnMatch" value="true" /&gt; * &lt;/filter> * &lt;filter class="org.apache.log4j.filter.StringMatchFilter"&gt; * &lt;param name="stringToMatch" value="test" /&gt; * &lt;param name="acceptOnMatch" value="true" /&gt; * &lt;/filter> * &lt;param name="acceptOnMatch" value="false"/&gt; * &lt;/filter&gt; * &lt;filter class="org.apache.log4j.filter.DenyAllFilter"/&gt; *&lt;layout class="org.apache.log4j.SimpleLayout"/&gt; *&lt;/appender&gt; * * To accept all events EXCEPT those events that contain a * DEBUG level and 'test' in the message: * change the AndFilter's acceptOnMatch param to false and remove the DenyAllFilter * * NOTE: If you are defining a filter that is only relying on logging event content * (no external or filter-managed state), you could opt instead * to use an ExpressionFilter with one of the following expressions: * * LEVEL == DEBUG && MSG ~= 'test' * or * ! ( LEVEL == DEBUG && MSG ~= 'test' ) * * */ class LOG4CXX_EXPORT AndFilter:public log4cxx::spi::Filter { private: log4cxx::spi::FilterPtr headFilter; log4cxx::spi::FilterPtr tailFilter; bool acceptOnMatch; AndFilter(const AndFilter &); AndFilter & operator=(const AndFilter &); public: DECLARE_LOG4CXX_OBJECT(AndFilter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(log4cxx::spi::Filter) END_LOG4CXX_CAST_MAP() AndFilter(); void addFilter(const log4cxx::spi::FilterPtr & filter); void setAcceptOnMatch(bool acceptOnMatch); FilterDecision decide(const spi::LoggingEventPtr & event) const; }; } } #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_FILTER_DENY_ALL_FILTER_H #define _LOG4CXX_FILTER_DENY_ALL_FILTER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/spi/filter.h> namespace log4cxx { namespace filter { /** This filter drops all logging events. <p>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 LOG4CXX_EXPORT DenyAllFilter : public spi::Filter { public: DenyAllFilter() : spi::Filter() { } typedef spi::Filter BASE_CLASS; DECLARE_LOG4CXX_OBJECT(DenyAllFilter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(DenyAllFilter) LOG4CXX_CAST_ENTRY_CHAIN(BASE_CLASS) END_LOG4CXX_CAST_MAP() /** Always returns the integer constant {@link spi::Filter#DENY DENY} regardless of the {@link spi::LoggingEvent LoggingEvent} parameter. @param event The LoggingEvent to filter. @return Always returns {@link spi::Filter#DENY DENY}. */ FilterDecision decide(const spi::LoggingEventPtr& /* event */) const { return spi::Filter::DENY; } }; // class DenyAllFilter LOG4CXX_PTR_DEF(DenyAllFilter); } // namespace filter } // namespace log4cxx #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif // _LOG4CXX_FILTER_DENY_ALL_FILTER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_FILTER_MAPFILTER_H #define _LOG4CXX_FILTER_MAPFILTER_H #include <log4cxx/spi/filter.h> namespace log4cxx { namespace filter { class LOG4CXX_EXPORT MapFilter:public log4cxx::spi::Filter { public: DECLARE_LOG4CXX_OBJECT(MapFilter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(log4cxx::spi::Filter) END_LOG4CXX_CAST_MAP() MapFilter(); FilterDecision decide(const spi::LoggingEventPtr & event) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_FILTER_LEVEL_RANGE_FILTER_H #define _LOG4CXX_FILTER_LEVEL_RANGE_FILTER_H #include <log4cxx/spi/filter.h> #include <log4cxx/level.h> namespace log4cxx { namespace filter { /** This is a very simple filter based on level matching, which can be used to reject messages with priorities outside a certain range. <p>The filter admits three options <b>LevelMin</b>, <b>LevelMax</b> and <b>AcceptOnMatch</b>. <p>If the level of the {@link spi::LoggingEvent LoggingEvent} is not between Min and Max (inclusive), then {@link spi::Filter#DENY DENY} is returned. <p> If the Logging event level is within the specified range, then if <b>AcceptOnMatch</b> is true, {@link spi::Filter#ACCEPT ACCEPT} is returned, and if <b>AcceptOnMatch</b> is false, {@link spi::Filter#NEUTRAL NEUTRAL} is returned. <p>If <code>LevelMin</code>w is not defined, then there is no minimum acceptable level (ie a level is never rejected for being too "low"/unimportant). If <code>LevelMax</code> is not defined, then there is no maximum acceptable level (ie a level is never rejected for beeing too "high"/important). <p>Refer to the {@link AppenderSkeleton#setThreshold setThreshold} method available to <code>all</code> appenders extending AppenderSkeleton for a more convenient way to filter out events by level. */ class LOG4CXX_EXPORT LevelRangeFilter : public spi::Filter { private: /** Do we return ACCEPT when a match occurs. Default is <code>false</code>, so that later filters get run by default */ bool acceptOnMatch; LevelPtr levelMin; LevelPtr levelMax; public: typedef spi::Filter BASE_CLASS; DECLARE_LOG4CXX_OBJECT(LevelRangeFilter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(LevelRangeFilter) LOG4CXX_CAST_ENTRY_CHAIN(BASE_CLASS) END_LOG4CXX_CAST_MAP() LevelRangeFilter(); /** Set options */ virtual void setOption(const LogString& option, const LogString& value); /** Set the <code>LevelMin</code> option. */ void setLevelMin(const LevelPtr& levelMin1) { this->levelMin = levelMin1; } /** Get the value of the <code>LevelMin</code> option. */ const LevelPtr& getLevelMin() const { return levelMin; } /** Set the <code>LevelMax</code> option. */ void setLevelMax(const LevelPtr& levelMax1) { this->levelMax = levelMax1; } /** Get the value of the <code>LevelMax</code> option. */ const LevelPtr& getLevelMax() const { return levelMax; } /** Set the <code>AcceptOnMatch</code> option. */ inline void setAcceptOnMatch(bool acceptOnMatch1) { this->acceptOnMatch = acceptOnMatch1; } /** Get the value of the <code>AcceptOnMatch</code> option. */ inline bool getAcceptOnMatch() const { return acceptOnMatch; } /** Return the decision of this filter. Returns {@link spi::Filter#NEUTRAL NEUTRAL} if the <b>LevelToMatch</b> option is not set or if there is not match. Otherwise, if there is a match, then the returned decision is {@link spi::Filter#ACCEPT ACCEPT} if the <b>AcceptOnMatch</b> property is set to <code>true</code>. The returned decision is {@link spi::Filter#DENY DENY} if the <b>AcceptOnMatch</b> property is set to false. */ FilterDecision decide(const spi::LoggingEventPtr& event) const; }; // class LevelRangeFilter LOG4CXX_PTR_DEF(LevelRangeFilter); } // namespace filter } // namespace log4cxx #endif // _LOG4CXX_FILTER_LEVEL_RANGE_FILTER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_FILTER_STRING_MATCH_FILTER_H #define _LOG4CXX_FILTER_STRING_MATCH_FILTER_H #include <log4cxx/spi/filter.h> namespace log4cxx { namespace filter { /** This is a very simple filter based on string matching. <p>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 {@link spi::LoggingEvent LoggingEvent}, then the #decide method returns {@link log4cxx::spi::Filter#ACCEPT ACCEPT} if the <b>AcceptOnMatch</b> option value is true, if it is false then {@link log4cxx::spi::Filter#DENY DENY} is returned. If there is no match, {@link log4cxx::spi::Filter#NEUTRAL NEUTRAL} is returned. <p>See configuration files <a href="../xml/doc-files/test6.xml">test6.xml</a>, <a href="../xml/doc-files/test7.xml">test7.xml</a>, <a href="../xml/doc-files/test8.xml">test8.xml</a>, <a href="../xml/doc-files/test9.xml">test9.xml</a>, and <a href="../xml/doc-files/test10.xml">test10.xml</a> for examples of seeting up a <code>StringMatchFilter</code>. */ class LOG4CXX_EXPORT StringMatchFilter : public spi::Filter { private: bool acceptOnMatch; LogString stringToMatch; public: typedef spi::Filter BASE_CLASS; DECLARE_LOG4CXX_OBJECT(StringMatchFilter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(StringMatchFilter) LOG4CXX_CAST_ENTRY_CHAIN(BASE_CLASS) END_LOG4CXX_CAST_MAP() StringMatchFilter(); /** Set options */ virtual void setOption(const LogString& option, const LogString& value); inline void setStringToMatch(const LogString& stringToMatch1) { this->stringToMatch.assign(stringToMatch1); } inline const LogString& getStringToMatch() const { return stringToMatch; } inline void setAcceptOnMatch(bool acceptOnMatch1) { this->acceptOnMatch = acceptOnMatch1; } inline bool getAcceptOnMatch() const { return acceptOnMatch; } /** Returns {@link log4cxx::spi::Filter#NEUTRAL NEUTRAL} is there is no string match. */ FilterDecision decide(const spi::LoggingEventPtr& event) const; }; // class StringMatchFilter LOG4CXX_PTR_DEF(StringMatchFilter); } // namespace filter } // namespace log4cxx #endif // _LOG4CXX_FILTER_STRING_MATCH_FILTER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_FILTER_PROPERTYFILTER_H #define _LOG4CXX_FILTER_PROPERTYFILTER_H #if defined(_MSC_VER) #pragma warning (push) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/spi/filter.h> #include <map> namespace log4cxx { namespace filter { /** * NOTE: This filter modifies logging events by adding properties to the event. * * The 'properties' param is converted to event properties, which are * set on every event processed by the filter. * * Individual properties are only set if they do not already exist on the * logging event (will not override existing properties). * * This class relies on the convention that property name/value pairs are * equals-symbol delimited, and each name/value pair is comma-delimited * * Example properties param: * somename=somevalue,anothername=anothervalue,thirdname=third value * * */ class LOG4CXX_EXPORT PropertyFilter : public log4cxx::spi::Filter { typedef std::map < LogString, LogString > PropertyMap; PropertyMap* properties; PropertyFilter(const PropertyFilter &); PropertyFilter & operator=(const PropertyFilter &); public: DECLARE_LOG4CXX_OBJECT(PropertyFilter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(log4cxx::spi::Filter) END_LOG4CXX_CAST_MAP() PropertyFilter(); ~PropertyFilter(); void setProperties(const LogString & props); FilterDecision decide(const spi::LoggingEventPtr & event) const; }; } } #if defined(_MSC_VER) #pragma warning (pop) #endif #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_FILTER_LEVEL_MATCH_FILTER_H #define _LOG4CXX_FILTER_LEVEL_MATCH_FILTER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/spi/filter.h> #include <log4cxx/level.h> namespace log4cxx { class Level; namespace filter { /** This is a very simple filter based on level matching. <p>The filter admits two options <b>LevelToMatch</b> and <b>AcceptOnMatch</b>. If there is an exact match between the value of the <b>LevelToMatch</b> option and the level of the {@link spi::LoggingEvent LoggingEvent}, then the #decide method returns {@link spi::Filter#ACCEPT ACCEPT} in case the <b>AcceptOnMatch</b> option value is set to <code>true</code>, if it is <code>false</code> then {@link spi::Filter#DENY DENY} is returned. If there is no match, {@link spi::Filter#NEUTRAL NEUTRAL} is returned. */ class LOG4CXX_EXPORT LevelMatchFilter : public spi::Filter { private: bool acceptOnMatch; LevelPtr levelToMatch; public: typedef spi::Filter BASE_CLASS; DECLARE_LOG4CXX_OBJECT(LevelMatchFilter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(LevelMatchFilter) LOG4CXX_CAST_ENTRY_CHAIN(BASE_CLASS) END_LOG4CXX_CAST_MAP() LevelMatchFilter(); /** Set options */ virtual void setOption(const LogString& option, const LogString& value); void setLevelToMatch(const LogString& levelToMatch); LogString getLevelToMatch() const; inline void setAcceptOnMatch(bool acceptOnMatch1) { this->acceptOnMatch = acceptOnMatch1; } inline bool getAcceptOnMatch() const { return acceptOnMatch; } /** Return the decision of this filter. Returns {@link spi::Filter#NEUTRAL NEUTRAL} if the <b>LevelToMatch</b> option is not set or if there is not match. Otherwise, if there is a match, then the returned decision is {@link spi::Filter#ACCEPT ACCEPT} if the <b>AcceptOnMatch</b> property is set to <code>true</code>. The returned decision is {@link spi::Filter#DENY DENY} if the <b>AcceptOnMatch</b> property is set to false. */ FilterDecision decide(const spi::LoggingEventPtr& event) const; }; // class LevelMatchFilter LOG4CXX_PTR_DEF(LevelMatchFilter); } // namespace filter } // namespace log4cxx #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif // _LOG4CXX_FILTER_STRING_MATCH_FILTER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_CONFIG_PROPERTYSETTER_H #define _LOG4CXX_CONFIG_PROPERTYSETTER_H #include <log4cxx/logstring.h> #include <log4cxx/helpers/objectptr.h> namespace log4cxx { namespace helpers { class Object; typedef ObjectPtrT<Object> ObjectPtr; class Properties; class Pool; } namespace config { /** General purpose Object property setter. Clients repeatedly invokes {@link #setProperty setProperty(name,value)} in order to invoke setters on the Object specified in the constructor. <p>Usage: <pre> PropertySetter ps(anObject); ps.set("name", "Joe"); ps.set("age", "32"); ps.set("isMale", "true"); </pre> will cause the invocations anObject->setOption("name", "Joe"), anObject->setOption("age", "32") and anObject->setOption("isMale", "true") if the spi::OptionHandler interface is supported by anObject. */ class LOG4CXX_EXPORT PropertySetter { protected: helpers::ObjectPtr obj; public: /** Create a new PropertySetter for the specified Object. This is done in prepartion for invoking #setProperty one or more times. @param obj the object for which to set properties */ PropertySetter(const helpers::ObjectPtr& obj); /** Set the properties of an object passed as a parameter in one go. The <code>properties</code> are parsed relative to a <code>prefix</code>. @param obj The object to configure. @param properties A java.util.Properties containing keys and values. @param prefix Only keys having the specified prefix will be set. @param p pool to use for any allocations required during call. */ static void setProperties(const helpers::ObjectPtr& obj, helpers::Properties& properties, const LogString& prefix, log4cxx::helpers::Pool& p); /** Set the properites for the object that match the <code>prefix</code> passed as parameter. */ void setProperties(helpers::Properties& properties, const LogString& prefix, log4cxx::helpers::Pool& p); /** Set a property on this PropertySetter's Object. If the underlying Object supports the spi::OptionHandler interface, the {@link spi::OptionHandler#setOption setOption} method is called. @param option name of the property @param value String value of the property @param p pool to use for any allocations required during call. */ void setProperty(const LogString& option, const LogString& value, log4cxx::helpers::Pool& p); void activate(log4cxx::helpers::Pool& p); }; // class PropertySetter } // namespace config; } // namespace log4cxx #endif //_LOG4CXX_CONFIG_PROPERTYSETTER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_NET_SMTP_H #define _LOG4CXX_NET_SMTP_H #include <log4cxx/appenderskeleton.h> #include <log4cxx/helpers/cyclicbuffer.h> #include <log4cxx/spi/triggeringeventevaluator.h> namespace log4cxx { namespace net { /** Send an e-mail when a specific logging event occurs, typically on errors or fatal errors. <p>The number of logging events delivered in this e-mail depend on the value of <b>BufferSize</b> option. The <code>SMTPAppender</code> keeps only the last <code>BufferSize</code> logging events in its cyclic buffer. This keeps memory requirements at a reasonable level while still delivering useful application context. */ class LOG4CXX_EXPORT SMTPAppender : public AppenderSkeleton { private: private: SMTPAppender(const SMTPAppender&); SMTPAppender& operator=(const SMTPAppender&); static bool asciiCheck(const LogString& value, const LogString& label); /** This method determines if there is a sense in attempting to append. <p>It checks whether there is a set output target and also if there is a set layout. If these checks fail, then the boolean value <code>false</code> is returned. */ bool checkEntryConditions(); LogString to; LogString cc; LogString bcc; LogString from; LogString subject; LogString smtpHost; LogString smtpUsername; LogString smtpPassword; int smtpPort; int bufferSize; // 512 bool locationInfo; helpers::CyclicBuffer cb; spi::TriggeringEventEvaluatorPtr evaluator; public: DECLARE_LOG4CXX_OBJECT(SMTPAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(SMTPAppender) LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) END_LOG4CXX_CAST_MAP() SMTPAppender(); /** The default constructor will instantiate the appender with a spi::TriggeringEventEvaluator that will trigger on events with level ERROR or higher.*/ SMTPAppender(log4cxx::helpers::Pool& p); /** Use <code>evaluator</code> passed as parameter as the spi::TriggeringEventEvaluator for this net::SMTPAppender. */ SMTPAppender(spi::TriggeringEventEvaluatorPtr evaluator); ~SMTPAppender(); /** Set options */ virtual void setOption(const LogString& option, const LogString& value); /** Activate the specified options, such as the smtp host, the recipient, from, etc. */ virtual void activateOptions(log4cxx::helpers::Pool& p); /** Perform SMTPAppender specific appending actions, mainly adding the event to a cyclic buffer and checking if the event triggers an e-mail to be sent. */ virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p); virtual void close(); /** Returns value of the <b>To</b> option. */ LogString getTo() const; /** Returns value of the <b>cc</b> option. */ LogString getCc() const; /** Returns value of the <b>bcc</b> option. */ LogString getBcc() const; /** The <code>SMTPAppender</code> requires a {@link Layout layout}. */ virtual bool requiresLayout() const; /** Send the contents of the cyclic buffer as an e-mail message. */ void sendBuffer(log4cxx::helpers::Pool& p); /** Returns value of the <b>EvaluatorClass</b> option. */ LogString getEvaluatorClass(); /** Returns value of the <b>From</b> option. */ LogString getFrom() const; /** Returns value of the <b>Subject</b> option. */ LogString getSubject() const; /** The <b>From</b> option takes a string value which should be a e-mail address of the sender. */ void setFrom(const LogString& from); /** The <b>Subject</b> option takes a string value which should be a the subject of the e-mail message. */ void setSubject(const LogString& subject); /** The <b>BufferSize</b> option takes a positive integer representing the maximum number of logging events to collect in a cyclic buffer. When the <code>BufferSize</code> is reached, oldest events are deleted as new events are added to the buffer. By default the size of the cyclic buffer is 512 events. */ void setBufferSize(int bufferSize); /** The <b>SMTPHost</b> option takes a string value which should be a the host name of the SMTP server that will send the e-mail message. */ void setSMTPHost(const LogString& smtpHost); /** Returns value of the <b>SMTPHost</b> option. */ LogString getSMTPHost() const; /** The <b>SMTPPort</b> option takes a string value which should be a the port of the SMTP server that will send the e-mail message. */ void setSMTPPort(int port); /** Returns value of the <b>SMTPHost</b> option. */ int getSMTPPort() const; /** The <b>To</b> option takes a string value which should be a comma separated list of e-mail address of the recipients. */ void setTo(const LogString& to); /** The <b>Cc</b> option takes a string value which should be a comma separated list of e-mail address of the cc'd recipients. */ void setCc(const LogString& to); /** The <b>Bcc</b> option takes a string value which should be a comma separated list of e-mail address of the bcc'd recipients. */ void setBcc(const LogString& to); /** The <b>SMTPUsername</b> option takes a string value which should be a the user name for the SMTP server. */ void setSMTPUsername(const LogString& newVal); /** Returns value of the <b>SMTPUsername</b> option. */ LogString getSMTPUsername() const; /** The <b>SMTPPassword</b> option takes a string value which should be a the password for the SMTP server. */ void setSMTPPassword(const LogString& newVal); /** Returns value of the <b>SMTPPassword</b> option. */ LogString getSMTPPassword() const; /** Returns value of the <b>BufferSize</b> option. */ inline int getBufferSize() const { return bufferSize; } /** * Gets the current triggering evaluator. * @return triggering evaluator. */ log4cxx::spi::TriggeringEventEvaluatorPtr getEvaluator() const; /** * Sets the triggering evaluator. * @param trigger triggering evaluator. */ void setEvaluator(log4cxx::spi::TriggeringEventEvaluatorPtr& trigger); /** The <b>EvaluatorClass</b> option takes a string value representing the name of the class implementing the spi::TriggeringEventEvaluator interface. A corresponding object will be instantiated and assigned as the triggering event evaluator for the SMTPAppender. */ void setEvaluatorClass(const LogString& value); /** The <b>LocationInfo</b> option is provided for compatibility with log4j and has no effect in log4cxx. */ void setLocationInfo(bool locationInfo); /** Returns value of the <b>LocationInfo</b> option. */ bool getLocationInfo() const; }; // class SMTPAppender LOG4CXX_PTR_DEF(SMTPAppender); } // namespace net } // namespace log4cxx #endif // _LOG4CXX_NET_SMTP_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_NET_SYSLOG_APPENDER_H #define _LOG4CXX_NET_SYSLOG_APPENDER_H #include <log4cxx/appenderskeleton.h> #include <log4cxx/helpers/syslogwriter.h> namespace log4cxx { namespace net { /** Use SyslogAppender to send log messages to a remote syslog daemon.*/ class LOG4CXX_EXPORT SyslogAppender : public AppenderSkeleton { public: DECLARE_LOG4CXX_OBJECT(SyslogAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(SyslogAppender) LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) END_LOG4CXX_CAST_MAP() SyslogAppender(); SyslogAppender(const LayoutPtr& layout, int syslogFacility); SyslogAppender(const LayoutPtr& layout, const LogString& syslogHost, int syslogFacility); ~SyslogAppender(); /** Release any resources held by this SyslogAppender.*/ void close(); /** Returns the specified syslog facility as a lower-case String, e.g. "kern", "user", etc. */ static LogString getFacilityString(int syslogFacility); /** Returns the integer value corresponding to the named syslog facility, or -1 if it couldn't be recognized. @param facilityName one of the strings KERN, USER, MAIL, DAEMON, AUTH, SYSLOG, LPR, NEWS, UUCP, CRON, AUTHPRIV, FTP, LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7. The matching is case-insensitive. */ static int getFacility(const LogString &facilityName); void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p); /** This method returns immediately as options are activated when they are set. */ void activateOptions(log4cxx::helpers::Pool& p); void setOption(const LogString& option, const LogString& value); /** The SyslogAppender requires a layout. Hence, this method returns <code>true</code>. */ virtual bool requiresLayout() const { return true; } /** The <b>SyslogHost</b> option is the name of the the syslog host where log output should go. <b>WARNING</b> If the SyslogHost is not set, then this appender will fail. */ void setSyslogHost(const LogString& syslogHost); /** Returns the value of the <b>SyslogHost</b> option. */ inline const LogString& getSyslogHost() const { return syslogHost; } /** Set the syslog facility. This is the <b>Facility</b> option. <p>The <code>facilityName</code> parameter must be one of the strings KERN, USER, MAIL, DAEMON, AUTH, SYSLOG, LPR, NEWS, UUCP, CRON, AUTHPRIV, FTP, LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7. Case is unimportant. */ void setFacility(const LogString& facilityName); /** Returns the value of the <b>Facility</b> option. */ inline LogString getFacility() const { return getFacilityString(syslogFacility); } /** If the <b>FacilityPrinting</b> option is set to true, the printed message will include the facility name of the application. It is <em>false</em> by default. */ inline void setFacilityPrinting(bool facilityPrinting1) { this->facilityPrinting = facilityPrinting1; } /** Returns the value of the <b>FacilityPrinting</b> option. */ inline bool getFacilityPrinting() const { return facilityPrinting; } protected: void initSyslogFacilityStr(); int syslogFacility; // Have LOG_USER as default LogString facilityStr; bool facilityPrinting; helpers::SyslogWriter * sw; LogString syslogHost; private: SyslogAppender(const SyslogAppender&); SyslogAppender& operator=(const SyslogAppender&); }; // class SyslogAppender LOG4CXX_PTR_DEF(SyslogAppender); } // namespace net } // namespace log4cxx #endif // _LOG4CXX_NET_SYSLOG_APPENDER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_NET_TELNET_APPENDER_H #define _LOG4CXX_NET_TELNET_APPENDER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/appenderskeleton.h> #include <log4cxx/helpers/socket.h> #include <log4cxx/helpers/serversocket.h> #include <log4cxx/helpers/thread.h> #include <vector> #include <log4cxx/helpers/charsetencoder.h> namespace log4cxx { namespace helpers { class ByteBuffer; } namespace net { /** <p>The TelnetAppender is a log4cxx appender that specializes in writing to a read-only socket. The output is provided in a telnet-friendly way so that a log can be monitored over TCP/IP. Clients using telnet connect to the socket and receive log data. This is handy for remote monitoring, especially when monitoring a servlet. <p>Here is a list of the available configuration options: <table border=1> <tr> <td align=center><b>Name</b></td> <td align=center><b>Requirement</b></td> <td align=center><b>Description</b></td> <td align=center><b>Sample Value</b></td> </tr> <tr> <td>Port</td> <td>optional</td> <td>This parameter determines the port to use for announcing log events. The default port is 23 (telnet).</td> <td>5875</td> </table> */ class LOG4CXX_EXPORT TelnetAppender : public AppenderSkeleton { class SocketHandler; friend class SocketHandler; private: static const int DEFAULT_PORT; static const int MAX_CONNECTIONS; int port; public: DECLARE_LOG4CXX_OBJECT(TelnetAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(TelnetAppender) LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) END_LOG4CXX_CAST_MAP() TelnetAppender(); ~TelnetAppender(); /** This appender requires a layout to format the text to the attached client(s). */ virtual bool requiresLayout() const { return true; } LogString getEncoding() const; void setEncoding(const LogString& value); /** all of the options have been set, create the socket handler and wait for connections. */ void activateOptions(log4cxx::helpers::Pool& p); /** Set options */ virtual void setOption(const LogString& option, const LogString& value); /** Returns value of the <b>Port</b> option. */ int getPort() const { return port; } /** The <b>Port</b> option takes a positive integer representing the port where the server is waiting for connections. */ void setPort(int port1) { this->port = port1; } /** shuts down the appender. */ void close(); protected: /** Handles a log event. For this appender, that means writing the message to each connected client. */ virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p) ; //---------------------------------------------------------- SocketHandler: private: // prevent copy and assignment statements TelnetAppender(const TelnetAppender&); TelnetAppender& operator=(const TelnetAppender&); typedef log4cxx::helpers::SocketPtr Connection; LOG4CXX_LIST_DEF(ConnectionList, Connection); void write(log4cxx::helpers::ByteBuffer&); void writeStatus(const log4cxx::helpers::SocketPtr& socket, const LogString& msg, log4cxx::helpers::Pool& p); ConnectionList connections; LogString encoding; log4cxx::helpers::CharsetEncoderPtr encoder; helpers::ServerSocket* serverSocket; helpers::Thread sh; size_t activeConnections; static void* LOG4CXX_THREAD_FUNC acceptConnections(apr_thread_t* thread, void* data); }; // class TelnetAppender LOG4CXX_PTR_DEF(TelnetAppender); } // namespace net } // namespace log4cxx #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif // _LOG4CXX_NET_TELNET_APPENDER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_NET_XML_SOCKET_APPENDER_H #define _LOG4CXX_NET_XML_SOCKET_APPENDER_H #include <log4cxx/net/socketappenderskeleton.h> #include <log4cxx/helpers/writer.h> namespace log4cxx { namespace net { /** Sends {@link log4cxx::spi::LoggingEvent LoggingEvent} objects in XML format to a remote a log server, usually a XMLSocketNode. <p>The XMLSocketAppender has the following properties: - If sent to a XMLSocketNode, 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, {@link NDC NDC}, location info as if it were logged locally by the client. - XMLSocketAppenders use exclusively an XMLLayout. They ship an XML stream representing a {@link spi::LoggingEvent LoggingEvent} object to the server side. - Remote logging uses the TCP protocol. Consequently, if the server is reachable, then log events will eventually arrive at the server. - 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. - 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. @n @n 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. - Even if an <code>XMLSocketAppender</code> is no longer attached to any logger, it will not be destroyed in the presence of a connector thread. A connector thread exists only if the connection to the server is down. To avoid this destruction problem, you should #close the the <code>XMLSocketAppender</code> explicitly. See also next item. @n @n Long lived applications which create/destroy many <code>XMLSocketAppender</code> instances should be aware of this destruction problem. Most other applications can safely ignore it. - If the application hosting the <code>XMLSocketAppender</code> exits before the <code>XMLSocketAppender</code> is closed either explicitly or subsequent to destruction, then there might be untransmitted data in the pipe which might be lost. @n @n To avoid lost data, it is usually sufficient to #close the <code>XMLSocketAppender</code> either explicitly or by calling the LogManager#shutdown method before exiting the application. */ class LOG4CXX_EXPORT XMLSocketAppender : public SocketAppenderSkeleton { public: /** The default port number of remote logging server (4560). */ static int DEFAULT_PORT; /** The default reconnection delay (30000 milliseconds or 30 seconds). */ static int DEFAULT_RECONNECTION_DELAY; /** An event XML stream cannot exceed 1024 bytes. */ static const int MAX_EVENT_LEN; DECLARE_LOG4CXX_OBJECT(XMLSocketAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(XMLSocketAppender) LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) END_LOG4CXX_CAST_MAP() XMLSocketAppender(); ~XMLSocketAppender(); /** Connects to remote server at <code>address</code> and <code>port</code>. */ XMLSocketAppender(helpers::InetAddressPtr address, int port); /** Connects to remote server at <code>host</code> and <code>port</code>. */ XMLSocketAppender(const LogString& host, int port); protected: virtual void setSocket(log4cxx::helpers::SocketPtr& socket, log4cxx::helpers::Pool& p); virtual void cleanUp(log4cxx::helpers::Pool& p); virtual int getDefaultDelay() const; virtual int getDefaultPort() const; void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool); private: log4cxx::helpers::WriterPtr writer; // prevent copy and assignment statements XMLSocketAppender(const XMLSocketAppender&); XMLSocketAppender& operator=(const XMLSocketAppender&); }; // class XMLSocketAppender LOG4CXX_PTR_DEF(XMLSocketAppender); } // namespace net } // namespace log4cxx #endif // _LOG4CXX_NET_XML_SOCKET_APPENDER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_NET_SOCKET_APPENDER_SKELETON_H #define _LOG4CXX_NET_SOCKET_APPENDER_SKELETON_H #include <log4cxx/appenderskeleton.h> #include <log4cxx/helpers/socket.h> #include <log4cxx/helpers/thread.h> #include <log4cxx/helpers/objectoutputstream.h> namespace log4cxx { namespace net { /** * Abstract base class for SocketAppender and XMLSocketAppender */ class LOG4CXX_EXPORT SocketAppenderSkeleton : public AppenderSkeleton { private: /** host name */ LogString remoteHost; /** IP address */ helpers::InetAddressPtr address; int port; int reconnectionDelay; bool locationInfo; public: SocketAppenderSkeleton(int defaultPort, int reconnectionDelay); ~SocketAppenderSkeleton(); /** Connects to remote server at <code>address</code> and <code>port</code>. */ SocketAppenderSkeleton(helpers::InetAddressPtr address, int port, int reconnectionDelay); /** Connects to remote server at <code>host</code> and <code>port</code>. */ SocketAppenderSkeleton(const LogString& host, int port, int reconnectionDelay); /** Connect to the specified <b>RemoteHost</b> and <b>Port</b>. */ void activateOptions(log4cxx::helpers::Pool& p); void close(); /** * This appender does not use a layout. Hence, this method * returns <code>false</code>. * */ bool requiresLayout() const { return false; } /** * The <b>RemoteHost</b> option takes a string value which should be * the host name of the server where a * Apache Chainsaw or compatible is running. * */ inline void setRemoteHost(const LogString& host) { address = helpers::InetAddress::getByName(host); remoteHost.assign(host); } /** Returns value of the <b>RemoteHost</b> option. */ inline const LogString& getRemoteHost() const { return remoteHost; } /** The <b>Port</b> option takes a positive integer representing the port where the server is waiting for connections. */ void setPort(int port1) { this->port = port1; } /** Returns value of the <b>Port</b> option. */ int getPort() const { return port; } /** The <b>LocationInfo</b> option takes a boolean value. If true, the information sent to the remote host will include location information. By default no location information is sent to the server. */ void setLocationInfo(bool locationInfo1) { this->locationInfo = locationInfo1; } /** Returns value of the <b>LocationInfo</b> option. */ bool getLocationInfo() const { return locationInfo; } /** The <b>ReconnectionDelay</b> option takes a positive integer representing the number of milliseconds to wait between each failed connection attempt to the server. The default value of this option is 30000 which corresponds to 30 seconds. <p>Setting this option to zero turns off reconnection capability. */ void setReconnectionDelay(int reconnectionDelay1) { this->reconnectionDelay = reconnectionDelay1; } /** Returns value of the <b>ReconnectionDelay</b> option. */ int getReconnectionDelay() const { return reconnectionDelay; } void fireConnector(); void setOption(const LogString& option, const LogString& value); protected: virtual void setSocket(log4cxx::helpers::SocketPtr& socket, log4cxx::helpers::Pool& p) = 0; virtual void cleanUp(log4cxx::helpers::Pool& p) = 0; virtual int getDefaultDelay() const = 0; virtual int getDefaultPort() const = 0; private: void connect(log4cxx::helpers::Pool& p); /** The Connector will reconnect when the server becomes available again. It does this by attempting to open a new connection every <code>reconnectionDelay</code> milliseconds. <p>It stops trying whenever a connection is established. It will restart to try reconnect to the server when previpously open connection is droppped. */ helpers::Thread thread; static void* LOG4CXX_THREAD_FUNC monitor(apr_thread_t* thread, void* data); SocketAppenderSkeleton(const SocketAppenderSkeleton&); SocketAppenderSkeleton& operator=(const SocketAppenderSkeleton&); }; // class SocketAppenderSkeleton } // namespace net } // namespace log4cxx #endif // _LOG4CXX_NET_SOCKET_APPENDER_SKELETON_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_NET_SOCKET_HUB_APPENDER_H #define _LOG4CXX_NET_SOCKET_HUB_APPENDER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/appenderskeleton.h> #include <vector> #include <log4cxx/helpers/thread.h> #include <log4cxx/helpers/objectoutputstream.h> namespace log4cxx { namespace helpers { class ObjectOutputStream; typedef ObjectPtrT<ObjectOutputStream> ObjectOutputStreamPtr; } namespace net { /** Sends {@link log4cxx::spi::LoggingEvent LoggingEvent} objects to a set of remote log servers, usually a SocketNode. <p>Acts just like SocketAppender except that instead of connecting to a given remote log server, <code>SocketHubAppender</code> accepts connections from the remote log servers as clients. It can accept more than one connection. When a log event is received, the event is sent to the set of currently connected remote log servers. Implemented this way it does not require any update to the configuration file to send data to another remote log server. The remote log server simply connects to the host and port the <code>SocketHubAppender</code> is running on. <p>The <code>SocketHubAppender</code> does not store events such that the remote side will events that arrived after the establishment of its connection. Once connected, events arrive in order as guaranteed by the TCP protocol. <p>This implementation borrows heavily from the SocketAppender. <p>The SocketHubAppender has the following characteristics: - If sent to a SocketNode, 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. - <code>SocketHubAppender</code> does not use a layout. It ships a serialized spi::LoggingEvent object to the remote side. - <code>SocketHubAppender</code> relies on the TCP protocol. Consequently, if the remote side is reachable, then log events will eventually arrive at remote client. - If no remote clients are attached, the logging requests are simply dropped. - Logging events are automatically <em>buffered</em> by the native TCP implementation. This means that if the link to remote client is slow but still faster than the rate of (log) event production, the application will not be affected by the slow network connection. However, if the network connection is slower then the rate of event production, then the local application can only progress at the network rate. In particular, if the network link to the the remote client is down, the application will be blocked. @n @n On the other hand, if the network link is up, but the remote client is down, the client will not be blocked when making log requests but the log events will be lost due to client unavailability. @n @n The single remote client case extends to multiple clients connections. The rate of logging will be determined by the slowest link. - If the application hosting the <code>SocketHubAppender</code> exits before the <code>SocketHubAppender</code> is closed either explicitly or subsequent to garbage collection, then there might be untransmitted data in the pipe which might be lost. This is a common problem on Windows based systems. @n @n To avoid lost data, it is usually sufficient to #close the <code>SocketHubAppender</code> either explicitly or by calling the LogManager#shutdown method before exiting the application. */ class LOG4CXX_EXPORT SocketHubAppender : public AppenderSkeleton { private: /** The default port number of the ServerSocket will be created on. */ static int DEFAULT_PORT; int port; LOG4CXX_LIST_DEF(ObjectOutputStreamList, log4cxx::helpers::ObjectOutputStreamPtr); ObjectOutputStreamList streams; bool locationInfo; public: DECLARE_LOG4CXX_OBJECT(SocketHubAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(SocketHubAppender) LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) END_LOG4CXX_CAST_MAP() SocketHubAppender(); ~SocketHubAppender(); /** Connects to remote server at <code>address</code> and <code>port</code>. */ SocketHubAppender(int port) ; /** Set up the socket server on the specified port. */ virtual void activateOptions(log4cxx::helpers::Pool& p); /** Set options */ virtual void setOption(const LogString& option, const LogString& value); virtual void close(); /** Append an event to all of current connections. */ virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p); /** The SocketHubAppender does not use a layout. Hence, this method returns <code>false</code>. */ virtual bool requiresLayout() const { return false; } /** The <b>Port</b> option takes a positive integer representing the port where the server is waiting for connections. */ inline void setPort(int port1) { this->port = port1; } /** Returns value of the <b>Port</b> option. */ inline int getPort() const { return port; } /** The <b>LocationInfo</b> option takes a boolean value. If true, the information sent to the remote host will include location information. By default no location information is sent to the server. */ inline void setLocationInfo(bool locationInfo1) { this->locationInfo = locationInfo1; } /** Returns value of the <b>LocationInfo</b> option. */ inline bool getLocationInfo() const { return locationInfo; } /** Start the ServerMonitor thread. */ private: void startServer(); helpers::Thread thread; static void* LOG4CXX_THREAD_FUNC monitor(apr_thread_t* thread, void* data); }; // class SocketHubAppender LOG4CXX_PTR_DEF(SocketHubAppender); } // namespace net } // namespace log4cxx #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif // _LOG4CXX_NET_SOCKET_HUB_APPENDER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_NET_SOCKET_APPENDER_H #define _LOG4CXX_NET_SOCKET_APPENDER_H #include <log4cxx/net/socketappenderskeleton.h> #include <log4cxx/helpers/objectoutputstream.h> namespace log4cxx { namespace net { /** Sends {@link log4cxx::spi::LoggingEvent LoggingEvent} objects to a remote a log server, usually Apache Chainsaw. <p>The SocketAppender has the following properties: - If sent to Apache Chainsaw, 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, {@link NDC NDC}, location info as if it were logged locally by the client. - SocketAppenders do not use a layout. They ship a serialized {@link log4cxx::spi::LoggingEvent LoggingEvent} object to the server side. - Remote logging uses the TCP protocol. Consequently, if the server is reachable, then log events will eventually arrive at the server. - 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. - 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. @n @n 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. - Even if a <code>SocketAppender</code> is no longer attached to any logger, it will not be destroyed in the presence of a connector thread. A connector thread exists only if the connection to the server is down. To avoid this destruction problem, you should #close the the <code>SocketAppender</code> explicitly. See also next item. @n @n Long lived applications which create/destroy many <code>SocketAppender</code> instances should be aware of this destruction problem. Most other applications can safely ignore it. - If the application hosting the <code>SocketAppender</code> exits before the <code>SocketAppender</code> is closed either explicitly or subsequent to destruction, then there might be untransmitted data in the pipe which might be lost. @n @n To avoid lost data, it is usually sufficient to #close the <code>SocketAppender</code> either explicitly or by calling the LogManager#shutdown method before exiting the application. */ class LOG4CXX_EXPORT SocketAppender : public SocketAppenderSkeleton { public: /** The default port number of remote logging server (4560). */ static int DEFAULT_PORT; /** The default reconnection delay (30000 milliseconds or 30 seconds). */ static int DEFAULT_RECONNECTION_DELAY; DECLARE_LOG4CXX_OBJECT(SocketAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(SocketAppender) LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) END_LOG4CXX_CAST_MAP() SocketAppender(); ~SocketAppender(); /** Connects to remote server at <code>address</code> and <code>port</code>. */ SocketAppender(helpers::InetAddressPtr& address, int port); /** Connects to remote server at <code>host</code> and <code>port</code>. */ SocketAppender(const LogString& host, int port); protected: virtual void setSocket(log4cxx::helpers::SocketPtr& socket, log4cxx::helpers::Pool& p); virtual void cleanUp(log4cxx::helpers::Pool& p); virtual int getDefaultDelay() const; virtual int getDefaultPort() const; void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool); private: log4cxx::helpers::ObjectOutputStreamPtr oos; }; // class SocketAppender LOG4CXX_PTR_DEF(SocketAppender); } // namespace net } // namespace log4cxx #endif // _LOG4CXX_NET_SOCKET_APPENDER_H
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_DAILYROLLINGFILEAPPENDER_H #define _LOG4CXX_DAILYROLLINGFILEAPPENDER_H #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #include <log4cxx/appender.h> #include <log4cxx/fileappender.h> #include <log4cxx/spi/optionhandler.h> #include <log4cxx/rolling/rollingfileappenderskeleton.h> namespace log4cxx { namespace helpers { class Pool; } namespace spi { class ErrorHandler; typedef log4cxx::helpers::ObjectPtrT<ErrorHandler> ErrorHandlerPtr; } /** DailyRollingFileAppender extends {@link log4cxx::FileAppender FileAppender} so that the underlying file is rolled over at a user chosen frequency. <p>The rolling schedule is specified by the <b>DatePattern</b> option. This pattern should follow the {@link log4cxx::helpers::SimpleDateFormat SimpleDateFormat} conventions. In particular, you <em>must</em> escape literal text within a pair of single quotes. A formatted version of the date pattern is used as the suffix for the rolled file name. <p>For example, if the <b>File</b> option is set to <code>/foo/bar.log</code> and the <b>DatePattern</b> set to <code>'.'yyyy-MM-dd</code>, on 2001-02-16 at midnight, the logging file <code>/foo/bar.log</code> will be copied to <code>/foo/bar.log.2001-02-16</code> and logging for 2001-02-17 will continue in <code>/foo/bar.log</code> until it rolls over the next day. <p>Is is possible to specify monthly, weekly, half-daily, daily, hourly, or minutely rollover schedules. <p><table border="1" cellpadding="2"> <tr> <th>DatePattern</th> <th>Rollover schedule</th> <th>Example</th> <tr> <td><code>'.'yyyy-MM</code> <td>Rollover at the beginning of each month</td> <td>At midnight of May 31st, 2002 <code>/foo/bar.log</code> will be copied to <code>/foo/bar.log.2002-05</code>. Logging for the month of June will be output to <code>/foo/bar.log</code> until it is also rolled over the next month. <tr> <td><code>'.'yyyy-ww</code> <td>Rollover at the first day of each week. The first day of the week depends on the locale.</td> <td>Assuming the first day of the week is Sunday, on Saturday midnight, June 9th 2002, the file <i>/foo/bar.log</i> will be copied to <i>/foo/bar.log.2002-23</i>. Logging for the 24th week of 2002 will be output to <code>/foo/bar.log</code> until it is rolled over the next week. <tr> <td><code>'.'yyyy-MM-dd</code> <td>Rollover at midnight each day.</td> <td>At midnight, on March 8th, 2002, <code>/foo/bar.log</code> will be copied to <code>/foo/bar.log.2002-03-08</code>. Logging for the 9th day of March will be output to <code>/foo/bar.log</code> until it is rolled over the next day. <tr> <td><code>'.'yyyy-MM-dd-a</code> <td>Rollover at midnight and midday of each day.</td> <td>At noon, on March 9th, 2002, <code>/foo/bar.log</code> will be copied to <code>/foo/bar.log.2002-03-09-AM</code>. Logging for the afternoon of the 9th will be output to <code>/foo/bar.log</code> until it is rolled over at midnight. <tr> <td><code>'.'yyyy-MM-dd-HH</code> <td>Rollover at the top of every hour.</td> <td>At approximately 11:00.000 o'clock on March 9th, 2002, <code>/foo/bar.log</code> will be copied to <code>/foo/bar.log.2002-03-09-10</code>. Logging for the 11th hour of the 9th of March will be output to <code>/foo/bar.log</code> until it is rolled over at the beginning of the next hour. <tr> <td><code>'.'yyyy-MM-dd-HH-mm</code> <td>Rollover at the beginning of every minute.</td> <td>At approximately 11:23,000, on March 9th, 2001, <code>/foo/bar.log</code> will be copied to <code>/foo/bar.log.2001-03-09-10-22</code>. Logging for the minute of 11:23 (9th of March) will be output to <code>/foo/bar.log</code> until it is rolled over the next minute. </table> <p>Do not use the colon ":" character in anywhere in the <b>DatePattern</b> option. The text before the colon is interpeted as the protocol specificaion of a URL which is probably not what you want. */ class LOG4CXX_EXPORT DailyRollingFileAppender : public log4cxx::rolling::RollingFileAppenderSkeleton { DECLARE_LOG4CXX_OBJECT(DailyRollingFileAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(DailyRollingFileAppender) LOG4CXX_CAST_ENTRY_CHAIN(FileAppender) END_LOG4CXX_CAST_MAP() /** The date pattern used to initiate rollover. */ LogString datePattern; public: /** The default constructor simply calls its {@link FileAppender#FileAppender parents constructor}. */ DailyRollingFileAppender(); /** Instantiate a DailyRollingFileAppender and open the file designated by <code>filename</code>. The opened filename will become the ouput destination for this appender. */ DailyRollingFileAppender( const LayoutPtr& layout, const LogString& filename, const LogString& datePattern); /** The <b>DatePattern</b> takes a string in the same format as expected by {@link log4cxx::helpers::SimpleDateFormat SimpleDateFormat}. This options determines the rollover schedule. */ void setDatePattern(const LogString& pattern); /** Returns the value of the <b>DatePattern</b> option. */ LogString getDatePattern(); void setOption(const LogString& option, const LogString& value); /** * Prepares DailyRollingFileAppender for use. */ void activateOptions(log4cxx::helpers::Pool&); }; LOG4CXX_PTR_DEF(DailyRollingFileAppender); } #if defined(_MSC_VER) #pragma warning ( pop ) #endif #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_METHOD_LOCATION_PATTERN_CONVERTER #define _LOG4CXX_PATTERN_METHOD_LOCATION_PATTERN_CONVERTER #include <log4cxx/pattern/loggingeventpatternconverter.h> namespace log4cxx { namespace pattern { /** * Return the event's line location information in a StringBuffer. * * * */ class LOG4CXX_EXPORT MethodLocationPatternConverter : public LoggingEventPatternConverter { /** * Private constructor. */ MethodLocationPatternConverter(); public: DECLARE_LOG4CXX_PATTERN(MethodLocationPatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(MethodLocationPatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() /** * Obtains an instance of MethodLocationPatternConverter. * @param options options, may be null. * @return instance of MethodLocationPatternConverter. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_PATTERN_CONVERTER_H #define _LOG4CXX_PATTERN_PATTERN_CONVERTER_H #include <log4cxx/helpers/objectimpl.h> #include <log4cxx/logstring.h> #include <vector> #ifdef _MSC_VER // disable identifier too wide for debugging warning #pragma warning ( disable: 4231 4251 4275 4786 ) #endif #define DECLARE_LOG4CXX_PATTERN(cls) DECLARE_ABSTRACT_LOG4CXX_OBJECT(cls) namespace log4cxx { namespace pattern { typedef std::vector<LogString> OptionsList; /** <p>PatternConverter is an abstract class that provides the formatting functionality that derived classes need. <p>Conversion specifiers in a conversion patterns are parsed to individual PatternConverters. Each of which is responsible for converting an object in a converter specific manner. */ class LOG4CXX_EXPORT PatternConverter : public virtual log4cxx::helpers::ObjectImpl { /** * Converter name. */ const LogString name; /** * Converter style name. */ const LogString style; protected: /** * Create a new pattern converter. * @param name name for pattern converter. * @param style CSS style for formatted output. */ PatternConverter(const LogString& name, const LogString& style); virtual ~PatternConverter(); public: DECLARE_LOG4CXX_PATTERN(PatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(PatternConverter) END_LOG4CXX_CAST_MAP() /** * Formats an object into a string buffer. * @param obj event to format, may not be null. * @param toAppendTo string buffer to which the formatted event will be appended. May not be null. * @param p pool for any allocations necessary during formatting. */ virtual void format(const log4cxx::helpers::ObjectPtr& obj, LogString& toAppendTo, log4cxx::helpers::Pool& p) const = 0; /** * This method returns the name of the conversion pattern. * * The name can be useful to certain Layouts such as HTMLLayout. * * @return the name of the conversion pattern */ LogString getName() const; /** * This method returns the CSS style class that should be applied to * the LoggingEvent passed as parameter, which can be null. * * This information is currently used only by HTMLLayout. * * @param e null values are accepted * @return the name of the conversion pattern */ virtual LogString getStyleClass(const log4cxx::helpers::ObjectPtr& e) const; protected: /** * Appends content in the locale code page to a LogString. * @param toAppendTo string to which content is appended. * @param src content. */ static void append(LogString& toAppendTo, const std::string& src); }; LOG4CXX_PTR_DEF(PatternConverter); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_LOGGER_PATTERN_CONVERTER_H #define _LOG4CXX_PATTERN_LOGGER_PATTERN_CONVERTER_H #include <log4cxx/pattern/namepatternconverter.h> namespace log4cxx { namespace pattern { /** * Formats a logger name. * * * * */ class LOG4CXX_EXPORT LoggerPatternConverter : public NamePatternConverter { /** * Private constructor. * @param options options, may be null. * @param logger logger for diagnostic messages, may be null. */ LoggerPatternConverter(const std::vector<LogString>& options); public: DECLARE_LOG4CXX_PATTERN(LoggerPatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(LoggerPatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(NamePatternConverter) END_LOG4CXX_CAST_MAP() /** * Obtains an instance of pattern converter. * @param options options, may be null. * @return instance of pattern converter. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_CLASSNAME_PATTERN_CONVERTER_H #define _LOG4CXX_PATTERN_CLASSNAME_PATTERN_CONVERTER_H #include <log4cxx/pattern/namepatternconverter.h> namespace log4cxx { namespace pattern { /** * Formats the class name of the site of the logging request. * * * */ class LOG4CXX_EXPORT ClassNamePatternConverter : public NamePatternConverter { /** * Private constructor. * @param options options, may be null. * @param logger logger for diagnostic messages, may be null. */ ClassNamePatternConverter( const std::vector<LogString>& options); public: DECLARE_LOG4CXX_PATTERN(ClassNamePatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(ClassNamePatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(NamePatternConverter) END_LOG4CXX_CAST_MAP() /** * Gets an instance of ClassNamePatternConverter. * @param options options, may be null. * @return instance of pattern converter. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr&event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_LOGGING_EVENT_PATTERN_CONVERTER_H #define _LOG4CXX_PATTERN_LOGGING_EVENT_PATTERN_CONVERTER_H #include <log4cxx/pattern/patternconverter.h> #include <log4cxx/spi/loggingevent.h> namespace log4cxx { namespace pattern { /** * LoggingEventPatternConverter is a base class for pattern converters * that can format information from instances of LoggingEvent. * * * * */ class LOG4CXX_EXPORT LoggingEventPatternConverter : public PatternConverter { protected: /** * Constructs an instance of LoggingEventPatternConverter. * @param name name of converter. * @param style CSS style for output. */ LoggingEventPatternConverter( const LogString& name, const LogString& style); public: DECLARE_LOG4CXX_PATTERN(LoggingEventPatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(LoggingEventPatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(PatternConverter) END_LOG4CXX_CAST_MAP() /** * Formats an event into a string buffer. * @param event event to format, may not be null. * @param toAppendTo string buffer to which the formatted event will be appended. May not be null. * @param p pool for memory allocations needing during format. */ virtual void format( const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const = 0; void format(const log4cxx::helpers::ObjectPtr& obj, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; /** * Normally pattern converters are not meant to handle Exceptions although * few pattern converters might. * * By examining the return values for this method, the containing layout will * determine whether it handles throwables or not. * @return true if this PatternConverter handles throwables */ virtual bool handlesThrowable() const; }; LOG4CXX_PTR_DEF(LoggingEventPatternConverter); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_LITERAL_PATTERN_CONVERTER_H #define _LOG4CXX_PATTERN_LITERAL_PATTERN_CONVERTER_H #include <log4cxx/pattern/loggingeventpatternconverter.h> namespace log4cxx { namespace pattern { /** * Formats a string literal. * * * * */ class LOG4CXX_EXPORT LiteralPatternConverter : public LoggingEventPatternConverter { /** * String literal. */ const LogString literal; /** * Create a new instance. * @param literal string literal. */ LiteralPatternConverter(const LogString& literal); public: DECLARE_LOG4CXX_PATTERN(LiteralPatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(LiteralPatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() static PatternConverterPtr newInstance(const LogString& literal); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; void format(const log4cxx::helpers::ObjectPtr& obj, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_NAMED_PATTERN_CONVERTER_H #define _LOG4CXX_PATTERN_NAMED_PATTERN_CONVERTER_H #include <log4cxx/pattern/loggingeventpatternconverter.h> #include <log4cxx/pattern/nameabbreviator.h> #include <vector> namespace log4cxx { namespace pattern { /** * * Base class for other pattern converters which can return only parts of their name. * */ class LOG4CXX_EXPORT NamePatternConverter : public LoggingEventPatternConverter { /** * Abbreviator. */ const NameAbbreviatorPtr abbreviator; public: DECLARE_LOG4CXX_PATTERN(NamePatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(NamePatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() protected: /** * Constructor. * @param name name of converter. * @param style style name for associated output. * @param options options, may be null, first element will be interpreted as an abbreviation pattern. */ NamePatternConverter( const LogString& name, const LogString& style, const std::vector<LogString>& options); /** * Abbreviate name in string buffer. * @param nameStart starting position of name to abbreviate. * @param buf string buffer containing name. */ void abbreviate(int nameStart, LogString& buf) const; private: NameAbbreviatorPtr getAbbreviator(const std::vector<LogString>& options); }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_MESSAGE_PATTERN_CONVERTER #define _LOG4CXX_PATTERN_MESSAGE_PATTERN_CONVERTER #include <log4cxx/pattern/loggingeventpatternconverter.h> namespace log4cxx { namespace pattern { /** * Formats the message of an logging event. * * * */ class LOG4CXX_EXPORT MessagePatternConverter : public LoggingEventPatternConverter { /** * Private constructor. */ MessagePatternConverter(); public: DECLARE_LOG4CXX_PATTERN(MessagePatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(MessagePatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() /** * Obtains an instance of pattern converter. * @param options options, may be null. * @return instance of pattern converter. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_THROWABLE_INFORMATION_PATTERN_CONVERTER #define _LOG4CXX_PATTERN_THROWABLE_INFORMATION_PATTERN_CONVERTER #include <log4cxx/pattern/loggingeventpatternconverter.h> namespace log4cxx { namespace pattern { /** * Outputs the ThrowableInformation portion of the LoggingiEvent as a full stacktrace * unless this converter's option is 'short', where it just outputs the first line of the trace. * * * * */ class LOG4CXX_EXPORT ThrowableInformationPatternConverter : public LoggingEventPatternConverter { /** * If "short", only first line of throwable report will be formatted. */ const bool shortReport; /** * Private constructor. */ ThrowableInformationPatternConverter(bool shortReport); public: DECLARE_LOG4CXX_PATTERN(ThrowableInformationPatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(ThrowableInformationPatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() /** * Gets an instance of the class. * @param options pattern options, may be null. If first element is "short", * only the first line of the throwable will be formatted. * @return instance of class. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; /** * This converter obviously handles throwables. * @return true. */ bool handlesThrowable() const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_RELATIVE_TIME_PATTERN_CONVERTER #define _LOG4CXX_PATTERN_RELATIVE_TIME_PATTERN_CONVERTER #include <log4cxx/pattern/loggingeventpatternconverter.h> namespace log4cxx { namespace pattern { /** * Format the relative time in milliseconds. * * * */ class LOG4CXX_EXPORT RelativeTimePatternConverter : public LoggingEventPatternConverter { public: DECLARE_LOG4CXX_PATTERN(RelativeTimePatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(RelativeTimePatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() /** * Private constructor. */ RelativeTimePatternConverter(); /** * Obtains an instance of RelativeTimePatternConverter. * @param options options, currently ignored, may be null. * @return instance of RelativeTimePatternConverter. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_INTEGER_PATTERN_CONVERTER #define _LOG4CXX_PATTERN_INTEGER_PATTERN_CONVERTER #include <log4cxx/pattern/patternconverter.h> namespace log4cxx { namespace pattern { /** * Formats an integer. * * * */ class LOG4CXX_EXPORT IntegerPatternConverter : public PatternConverter { /** * Private constructor. */ IntegerPatternConverter(); public: DECLARE_LOG4CXX_PATTERN(IntegerPatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(IntegerPatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(PatternConverter) END_LOG4CXX_CAST_MAP() /** * Obtains an instance of pattern converter. * @param options options, may be null. * @return instance of pattern converter. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::helpers::ObjectPtr& obj, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; LOG4CXX_PTR_DEF(IntegerPatternConverter); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_THREAD_PATTERN_CONVERTER #define _LOG4CXX_PATTERN_THREAD_PATTERN_CONVERTER #include <log4cxx/pattern/loggingeventpatternconverter.h> namespace log4cxx { namespace pattern { /** * Formats the event thread name. * * * */ class LOG4CXX_EXPORT ThreadPatternConverter : public LoggingEventPatternConverter { /** * Private constructor. */ ThreadPatternConverter(); public: DECLARE_LOG4CXX_PATTERN(ThreadPatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(ThreadPatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() /** * Obtains an instance of ThreadPatternConverter. * @param options options, currently ignored, may be null. * @return instance of ThreadPatternConverter. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_FULL_LOCATION_PATTERN_CONVERTER #define _LOG4CXX_PATTERN_FULL_LOCATION_PATTERN_CONVERTER #include <log4cxx/pattern/loggingeventpatternconverter.h> namespace log4cxx { namespace pattern { /** * Format the event's line location information. * * * */ class LOG4CXX_EXPORT FullLocationPatternConverter : public LoggingEventPatternConverter { /** * Private constructor. */ FullLocationPatternConverter(); public: DECLARE_LOG4CXX_PATTERN(FullLocationPatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(FullLocationPatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() /** * Obtains an instance of pattern converter. * @param options options, may be null. * @return instance of pattern converter. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_LEVEL_PATTERN_CONVERTER #define _LOG4CXX_PATTERN_LEVEL_PATTERN_CONVERTER #include <log4cxx/pattern/loggingeventpatternconverter.h> namespace log4cxx { namespace pattern { /** * Return the event's level in a StringBuffer. * * * */ class LOG4CXX_EXPORT LevelPatternConverter : public LoggingEventPatternConverter { /** * Private constructor. */ LevelPatternConverter(); public: DECLARE_LOG4CXX_PATTERN(LevelPatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(LevelPatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() /** * Obtains an instance of pattern converter. * @param options options, may be null. * @return instance of pattern converter. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; LogString getStyleClass(const log4cxx::helpers::ObjectPtr& e) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_FILE_LOCATION_PATTERN_CONVERTER #define _LOG4CXX_PATTERN_FILE_LOCATION_PATTERN_CONVERTER #include <log4cxx/pattern/loggingeventpatternconverter.h> namespace log4cxx { namespace pattern { /** * Return the event's line location information in a StringBuffer. * * * */ class LOG4CXX_EXPORT FileLocationPatternConverter : public LoggingEventPatternConverter { /** * Private constructor. */ FileLocationPatternConverter(); public: DECLARE_LOG4CXX_PATTERN(FileLocationPatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(FileLocationPatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() /** * Obtains an instance of pattern converter. * @param options options, may be null. * @return instance of pattern converter. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_NDC_PATTERN_CONVERTER #define _LOG4CXX_PATTERN_NDC_PATTERN_CONVERTER #include <log4cxx/pattern/loggingeventpatternconverter.h> namespace log4cxx { namespace pattern { /** * Return the event's NDC in a StringBuffer. * * * */ class LOG4CXX_EXPORT NDCPatternConverter : public LoggingEventPatternConverter { /** * Private constructor. */ NDCPatternConverter(); public: DECLARE_LOG4CXX_PATTERN(NDCPatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(NDCPatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() /** * Obtains an instance of NDCPatternConverter. * @param options options, may be null. * @return instance of NDCPatternConverter. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_DATE_PATTERN_CONVERTER #define _LOG4CXX_PATTERN_DATE_PATTERN_CONVERTER #include <log4cxx/pattern/loggingeventpatternconverter.h> #include <log4cxx/helpers/cacheddateformat.h> #include <log4cxx/helpers/date.h> #include <vector> namespace log4cxx { namespace pattern { /** * Convert and format the event's date in a StringBuffer. * * * */ class LOG4CXX_EXPORT DatePatternConverter : public LoggingEventPatternConverter { /** * Date format. */ log4cxx::helpers::DateFormatPtr df; /** * Private constructor. * @param options options, may be null. * @param logger logger for diagnostic messages, may be null. */ DatePatternConverter(const OptionsList& options); /** * Obtains an instance of pattern converter. * @param options options, may be null. * @return instance of pattern converter. */ static log4cxx::helpers::DateFormatPtr getDateFormat(const OptionsList& options); public: DECLARE_LOG4CXX_PATTERN(DatePatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(DatePatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& output, log4cxx::helpers::Pool& p) const; void format(const log4cxx::helpers::ObjectPtr& obj, LogString& output, log4cxx::helpers::Pool& p) const; void format(const log4cxx::helpers::DatePtr& date, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; LOG4CXX_PTR_DEF(DatePatternConverter); } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_PROPERTIES_PATTERN_CONVERTER #define _LOG4CXX_PATTERN_PROPERTIES_PATTERN_CONVERTER #include <log4cxx/pattern/loggingeventpatternconverter.h> namespace log4cxx { namespace pattern { /** * Able to handle the contents of the LoggingEvent's Property bundle and either * output the entire contents of the properties in a similar format to the * java.util.Hashtable.toString(), or to output the value of a specific key * within the property bundle * when this pattern converter has the option set. * * * */ class LOG4CXX_EXPORT PropertiesPatternConverter : public LoggingEventPatternConverter { /** * Name of property to output. */ const LogString option; /** * Private constructor. * @param options options, may be null. * @param logger logger for diagnostic messages, may be null. */ PropertiesPatternConverter(const LogString& name, const LogString& option); public: DECLARE_LOG4CXX_PATTERN(PropertiesPatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(PropertiesPatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() /** * Obtains an instance of PropertiesPatternConverter. * @param options options, may be null or first element contains name of property to format. * @return instance of PropertiesPatternConverter. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_NAME_ABBREVIATOR #define _LOG4CXX_PATTERN_NAME_ABBREVIATOR #include <log4cxx/logstring.h> #include <log4cxx/helpers/objectptr.h> #include <log4cxx/helpers/objectimpl.h> namespace log4cxx { namespace pattern { class NameAbbreviator; LOG4CXX_PTR_DEF(NameAbbreviator); /** * NameAbbreviator generates abbreviated logger and class names. * * * */ class LOG4CXX_EXPORT NameAbbreviator : public log4cxx::helpers::ObjectImpl { public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(NameAbbreviator) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(NameAbbreviator) END_LOG4CXX_CAST_MAP() protected: NameAbbreviator(); public: virtual ~NameAbbreviator(); /** * Gets an abbreviator. * * For example, "%logger{2}" will output only 2 elements of the logger name, * "%logger{1.}" will output only the first character of the non-final elements in the name, * "%logger(1~.2~} will output the first character of the first element, two characters of * the second and subsequent elements and will use a tilde to indicate abbreviated characters. * * @param pattern abbreviation pattern. * @return abbreviator, will not be null. */ static NameAbbreviatorPtr getAbbreviator(const LogString& pattern); /** * Gets default abbreviator. * * @return default abbreviator. */ static NameAbbreviatorPtr getDefaultAbbreviator(); /** * Abbreviates a name in a StringBuffer. * * @param nameStart starting position of name in buf. * @param buf buffer, may not be null. */ virtual void abbreviate(LogString::size_type nameStart, LogString& buf) const = 0; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_PATTERN_LINE_SEPARATOR_PATTERN_CONVERTER #define _LOG4CXX_PATTERN_LINE_SEPARATOR_PATTERN_CONVERTER #include <log4cxx/pattern/loggingeventpatternconverter.h> namespace log4cxx { namespace pattern { /** * Formats a line separator. * * * */ class LOG4CXX_EXPORT LineSeparatorPatternConverter : public LoggingEventPatternConverter { /** * Private constructor. */ LineSeparatorPatternConverter(); public: DECLARE_LOG4CXX_PATTERN(LineSeparatorPatternConverter) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(LineSeparatorPatternConverter) LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) END_LOG4CXX_CAST_MAP() /** * Obtains an instance of pattern converter. * @param options options, may be null. * @return instance of pattern converter. */ static PatternConverterPtr newInstance( const std::vector<LogString>& options); void format(const log4cxx::spi::LoggingEventPtr& event, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; void format(const log4cxx::helpers::ObjectPtr& obj, LogString& toAppendTo, log4cxx::helpers::Pool& p) const; }; } } #endif
C++
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _LOG4CXX_HELPER_FORMATTING_INFO_H #define _LOG4CXX_HELPER_FORMATTING_INFO_H #include <log4cxx/helpers/objectimpl.h> #include <log4cxx/logstring.h> namespace log4cxx { namespace pattern { class FormattingInfo; typedef helpers::ObjectPtrT<FormattingInfo> FormattingInfoPtr; /** * Modifies the output of a pattern converter for a specified minimum * and maximum width and alignment. * * * * */ class LOG4CXX_EXPORT FormattingInfo : public virtual log4cxx::helpers::ObjectImpl { /** * Minimum length. */ const int minLength; /** * Maximum length. */ const int maxLength; /** * Alignment. */ const bool leftAlign; public: DECLARE_ABSTRACT_LOG4CXX_OBJECT(FormattingInfo) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(FormattingInfo) END_LOG4CXX_CAST_MAP() /** * Creates new instance. * @param leftAlign left align if true. * @param minLength minimum length. * @param maxLength maximum length. */ FormattingInfo( const bool leftAlign, const int minLength, const int maxLength); /** * Gets default instance. * @return default instance. */ static FormattingInfoPtr getDefault(); /** * Determine if left aligned. * @return true if left aligned. */ inline bool isLeftAligned() const { return leftAlign; } /** * Get minimum length. * @return minimum length. */ inline int getMinLength() const { return minLength; } /** * Get maximum length. * @return maximum length. */ inline int getMaxLength() const { return maxLength; } /** * Adjust the content of the buffer based on the specified lengths and alignment. * * @param fieldStart start of field in buffer. * @param buffer buffer to be modified. */ void format(const int fieldStart, LogString& buffer) const; }; LOG4CXX_PTR_DEF(FormattingInfo); } } #endif
C++