Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

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

Generated on Mon Jun 16 11:20:01 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002