Logging_Strategy.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Logging_Strategy.h
00006  *
00007  *  $Id: Logging_Strategy.h 80826 2008-03-04 14:51:23Z wotte $
00008  *
00009  *  @author Prashant Jain <pjain@cs.wustl.edu>
00010  *  @author Orlando Ribeiro <oribeiro@inescporto.pt>
00011  */
00012 //=============================================================================
00013 
00014 #ifndef ACE_LOGGING_STRATEGY_H
00015 #define ACE_LOGGING_STRATEGY_H
00016 
00017 #include "ace/Service_Object.h"
00018 #include "ace/Log_Msg.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #if !defined (ACE_DEFAULT_LOGFILE_POLL_INTERVAL)
00025 #define ACE_DEFAULT_LOGFILE_POLL_INTERVAL 600 /* Seconds */
00026 #endif /* ACE_DEFAULT_LOGFILE_POLL_INTERVAL */
00027 
00028 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00029 
00030 /**
00031  * @class ACE_Logging_Strategy
00032  *
00033  * @brief This class provides a way to dynamically configure the ACE logging
00034  * mechanism at run time as well as enable the mechanisms for limiting
00035  * log file size and log file backup/rotation capability.
00036  *
00037  * Depending upon when this service is invoked and with what
00038  * flags, the output of other network services can be
00039  * controlled. The output can be streamed to stderr, to a file,
00040  * to a logging daemon, or it can be set to be "silent".
00041  * If logging records are output to a file, the file can be set
00042  * to a maximum size and repeatedly split into new files.  The
00043  * log file size can be limited at any logging point (i.e.,
00044  * application, client logging daemon, or server logging daemon)
00045  * by specifying the -i @param sample_interval_in_secs and -m
00046  * @param max_size_in_KB options for the Logging_Strategy class in a
00047  * svc.conf file.
00048  *
00049  * By default, two logfiles are generated.  It's possible, however, to
00050  * generate as many logfiles as necessary to store all the
00051  * information.  To achieve this, it is only necessary to indicate the
00052  * maximum size of the logfiles via the -m option and the process will
00053  * generate automatically the logfiles.  You can control the total
00054  * number of logfiles created via the -n option.
00055  *
00056  * By using the -o option we can also choose the mode of organization
00057  * of the files, e.g., the first one is the normal used in Unix
00058  * systems (when cron rotates the logs it keeps the lowest number the
00059  * most recent one), the second is for increasing speed (we only
00060  * create a new log file, and don't rotate the others (fewer accesses
00061  * to disk)).
00062  *
00063  * By default, the @c ACE_Logging_Strategy uses the singleton reactor,
00064  * i.e., what's returned by @c ACE_Reactor::instance().  If you want
00065  * to set the reactor used by @c ACE_Logging_Strategy to something
00066  * other than the singleton reactor you'll need to get a pointer to
00067  * the @c ACE_Logging_Strategy instance and do this
00068  *
00069  * ACE_Reactor my_reactor;
00070  * ACE_Logging_Strategy *logging_strategy = ...... // Get instance.
00071  *
00072  * logging_strategy->reactor (&my_reactor);
00073  *
00074  * and then logging_strategy will use your reactor.  If you're
00075  * dynamically linking the @c ACE_Logging_Strategy then you can use
00076  * the @c ACE_Dynamic_Service template to get a pointer to the
00077  * @c ACE_Logging_Strategy.
00078  */
00079 class ACE_Export ACE_Logging_Strategy : public ACE_Service_Object
00080 {
00081 public:
00082   /// Constructor.
00083   ACE_Logging_Strategy (void);
00084 
00085   /// Destructor.
00086   ~ACE_Logging_Strategy (void);
00087 
00088   /// Dynamic linking initialization hook.
00089   virtual int init (int argc, ACE_TCHAR *argv[]);
00090 
00091   /// Dynamic linking termination hook.
00092   virtual int fini (void);
00093 
00094   /**
00095    * Timeout handler which tests logfile size.  If the current logfile
00096    * size exceeds <max_size_>, the current logfile is closed, saved to
00097    * logfile.old, and a new logfile is reopened.
00098    */
00099   virtual int handle_timeout (const ACE_Time_Value& tv,
00100                               const void* arg);
00101 
00102   /**
00103    * Parse arguments provided in svc.conf file.
00104    * @arg '-f' Pass in the flags (such as OSTREAM, STDERR, LOGGER, VERBOSE,
00105    *           SILENT, VERBOSE_LITE) used to control logging.
00106    * @arg '-i' The interval (in seconds) at which the logfile size is sampled
00107    *           (default is 0, i.e., do not sample by default).
00108    * @arg '-k' Set the logging key.
00109    * @arg '-m' Maximum logfile size in Kbytes.
00110    * @arg '-n' Set the program name for the %n format specifier.
00111    * @arg '-N' The maximum number of logfiles that we want created.
00112    * @arg '-o' Specifies that we want the no standard logfiles ordering
00113    *           (fastest processing in <handle_timeout>).  Default is not to
00114    *           order logfiles.
00115    * @arg '-p' Pass in the process-wide priorities to either enable (e.g.,
00116    *           DEBUG, INFO, WARNING, NOTICE, ERROR, CRITICAL, ALERT,
00117    *           EMERGENCY) or to disable (e.g., ~DEBUG, ~INFO, ~WARNING,
00118    *           ~NOTICE, ~ERROR, ~CRITICAL, ~ALERT, ~EMERGENCY).
00119    * @arg '-s' Ensure that the OSTREAM flag is set and log to the @a filename.
00120    * @arg '-t' Pass in the thread-wide priorities to either enable (e.g.,
00121    *           DEBUG, INFO, WARNING, NOTICE, ERROR, CRITICAL, ALERT,
00122    *           EMERGENCY) or to disable (e.g., ~DEBUG, ~INFO, ~WARNING,
00123    *           ~NOTICE, ~ERROR, ~CRITICAL, ~ALERT, ~EMERGENCY).
00124    * @arg '-w' Cause the logfile to be wiped out, both on startup and on
00125    *           reconfiguration.
00126    */
00127   int parse_args (int argc, ACE_TCHAR *argv[]);
00128 
00129   void log_msg (ACE_Log_Msg *log_msg);
00130 
00131 protected:
00132   /// Tokenize to set all the flags
00133   void tokenize (ACE_TCHAR *flag_string);
00134 
00135   /// Tokenize to set priorities (either process or thread one).
00136   void priorities (ACE_TCHAR *priority_string,
00137                    ACE_Log_Msg::MASK_TYPE mask);
00138 
00139   /// Current thread's priority mask set by <priorities>
00140   u_long thread_priority_mask_;
00141 
00142   /// Process-wide priority mask set by <priorities>
00143   u_long process_priority_mask_;
00144 
00145   /// Flags we keep track of.
00146   u_long flags_;
00147 
00148   /// File name we're logging to.
00149   ACE_TCHAR *filename_;
00150 
00151   /// Logger key for distributed logging.
00152   ACE_TCHAR *logger_key_;
00153 
00154   /// Program name to be used for %n format specifier.
00155   ACE_TCHAR *program_name_;
00156 
00157   /// If non-0 then wipeout the logfile, otherwise append to it.
00158   /// Default value is 0.
00159   bool wipeout_logfile_;
00160 
00161   /// If non-0 we have a maximum number of log files we can write.
00162   /// Default value is 0, i.e., no maximum number.
00163   bool fixed_number_;
00164 
00165   /// If non-0 we order the files as we rotate them.  Default value
00166   /// is 0, i.e., we do not rotate files by default.
00167   bool order_files_;
00168 
00169   /// This tells us in what file we last wrote. It will be increased
00170   /// to enable multiple log files
00171   int count_;
00172 
00173   /// Tells us what is the maximum log file to write. We will write
00174   /// <max_file_number_> + 1 files (includes the current log file).
00175   /// Default value is 1, i.e., 2 files by default.
00176   int max_file_number_;
00177 
00178   /// If non-zero, sampling interval (in secs) at which maximum logfile
00179   /// size is checked, otherwise logfile size can grow indefinitely.
00180   /// Default value is 0.
00181   u_long interval_;
00182 
00183   /// Maximum logfile size (in KB).  Default value is
00184   /// <ACE_DEFAULT_MAX_LOGFILE_SIZE>.
00185   u_long max_size_;
00186 
00187   /// ACE_Log_Msg instance to work with
00188   ACE_Log_Msg *log_msg_;
00189 };
00190 
00191 ACE_END_VERSIONED_NAMESPACE_DECL
00192 
00193 ACE_FACTORY_DECLARE (ACE, ACE_Logging_Strategy)
00194 
00195 #endif /* ACE_LOGGING_STRATEGY_H */

Generated on Tue Feb 2 17:18:40 2010 for ACE by  doxygen 1.4.7