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