123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- /*
- * FixedContextCategory.hh
- *
- * Copyright 2001, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
- * Copyright 2001, Bastiaan Bakker. All rights reserved.
- *
- * See the COPYING file for the terms of usage and distribution.
- */
- #ifndef _LOG4CPP_FIXEDCONTEXTCATEGORY_HH
- #define _LOG4CPP_FIXEDCONTEXTCATEGORY_HH
- #include <log4cpp/Portability.hh>
- #include <log4cpp/Category.hh>
- namespace log4cpp {
- /**
- * This Category subclass replaces the NDC field in LoggingEvents with
- * a fixed context string. All handling of Appenders, etc. is delgated
- * to the 'normal' Category with the same name. Its intended use is
- * for object instances that serve a single client: they contruct a
- * FixedContextCategory with the client identifier as context.
- * Unlike with regular Category instances one has to explicitly create
- * FixedContextCategory instances using the constructor. This also
- * implies one has to take cake of destruction of the instance as well.
- * @since 0.2.4
- **/
- class LOG4CPP_EXPORT FixedContextCategory : public Category {
- public:
- /**
- * Constructor
- * @param name the fully qualified name of this Categories delegate
- * Category.
- * @param context the context to fill the NDC field of LoggingEvents
- * with.
- **/
- FixedContextCategory(const std::string& name,
- const std::string& context = "");
-
-
- /**
- * Destructor for Category.
- **/
- virtual ~FixedContextCategory();
-
- /**
- * Set the context string used as NDC.
- * @param context the context string
- **/
- virtual void setContext(const std::string& context);
- /**
- * Return the context string used as NDC.
- * @return the context string.
- **/
- virtual std::string getContext() const;
- /**
- * Returns the assigned Priority, if any, for this Category.
- * @return Priority - the assigned Priority, can be Priority::NOTSET
- **/
- virtual Priority::Value getPriority() const LOG4CPP_NOTHROW;
- /**
- * Starting from this Category, search the category hierarchy for a
- * set priority and return it. Otherwise, return the priority
- * of the root category.
- *
- * <p>The Category class is designed so that this method executes as
- * quickly as possible.
- **/
- virtual Priority::Value getChainedPriority() const LOG4CPP_NOTHROW;
-
- /**
- * For the moment this method does nothing.
- **/
- virtual void addAppender(Appender* appender) LOG4CPP_NOTHROW;
- /**
- * For the moment this method does nothing.
- **/
- virtual void addAppender(Appender& appender);
- /**
- * Returns the Appender for this Category, or NULL if no Appender has
- * been set.
- * @returns The Appender.
- **/
- virtual Appender* getAppender() const;
- /**
- * Returns the specified Appender for this Category, or NULL if
- * the Appender is not attached to this Category.
- * @since 0.2.7
- * @returns The Appender.
- **/
- virtual Appender* getAppender(const std::string& name) const;
- /**
- * Returns the set of Appenders currently attached to this Catogory.
- * @since 0.3.1
- * @returns The set of attached Appenders.
- **/
- virtual AppenderSet getAllAppenders() const;
- /**
- * Removes all appenders set for this Category. Currently a Category
- * can have only one appender, but this may change in the future.
- **/
- virtual void removeAllAppenders();
- /**
- * FixedContextAppenders cannot own Appenders.
- * @returns false
- **/
- virtual bool ownsAppender() const LOG4CPP_NOTHROW;
- /**
- * FixedContextAppenders cannot own Appenders.
- * @returns false
- **/
- virtual bool ownsAppender(Appender* appender)
- const LOG4CPP_NOTHROW;
- /**
- * Call the appenders in the hierarchy starting at
- * <code>this</code>. If no appenders could be found, emit a
- * warning.
- *
- * <p>This method always calls all the appenders inherited form the
- * hierracy circumventing any evaluation of whether to log or not to
- * log the particular log request.
- *
- * @param event The LoggingEvent to log.
- **/
- virtual void callAppenders(const LoggingEvent& event) LOG4CPP_NOTHROW;
-
- /**
- * Set the additivity flag for this Category instance.
- **/
- virtual void setAdditivity(bool additivity);
- /**
- * Returns the additivity flag for this Category instance.
- **/
- virtual bool getAdditivity() const LOG4CPP_NOTHROW;
- protected:
- /**
- * Unconditionally log a message with the specified priority.
- * @param priority The priority of this log message.
- * @param message string to write in the log file
- **/
- virtual void _logUnconditionally2(Priority::Value priority,
- const std::string& message) LOG4CPP_NOTHROW;
- private:
- /**
- * The delegate category of this FixedContextCategory.
- **/
- Category& _delegate;
- /** The context of this FixedContextCategory. */
- std::string _context;
- };
- }
- #endif // _LOG4CPP_FIXEDCONTEXTCATEGORY_HH
|