diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 2001-02-15 13:25:18 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 2001-02-15 13:25:18 +0000 |
commit | 28a4dbafd0b8854c3d2ec782f6b31216ecdade30 (patch) | |
tree | 248a20ddfebb81b098c89ad1468f2b769c378cae /ace | |
parent | 049b4725a0197fbb92759b3d309033a4dbeec060 (diff) | |
download | ATCD-28a4dbafd0b8854c3d2ec782f6b31216ecdade30.tar.gz |
ChangeLogTag:Thu Feb 15 07:15:39 2001 Douglas C. Schmidt <schmidt@ace.cs.wustl.edu>
Diffstat (limited to 'ace')
-rw-r--r-- | ace/Logging_Strategy.cpp | 106 | ||||
-rw-r--r-- | ace/Logging_Strategy.h | 35 |
2 files changed, 130 insertions, 11 deletions
diff --git a/ace/Logging_Strategy.cpp b/ace/Logging_Strategy.cpp index 43648f76ec5..2d4a261c142 100644 --- a/ace/Logging_Strategy.cpp +++ b/ace/Logging_Strategy.cpp @@ -106,12 +106,19 @@ ACE_Logging_Strategy::parse_args (int argc, ACE_TCHAR *argv[]) ACE_TRACE ("ACE_Logging_Strategy::parse_args"); ACE_TCHAR *temp; + // Perform data member initializations. + this->thread_priority_mask_ = 0; + this->process_priority_mask_ = 0; this->flags_ = 0; this->wipeout_logfile_ = 0; + this->count_ = 0; + this->fixed_number_ = 0; + this->order_files_ = 0; + this->max_file_number_ = 1; this->interval_ = 0; this->max_size_ = ACE_DEFAULT_MAX_LOGFILE_SIZE; - ACE_Get_Opt get_opt (argc, argv, ACE_LIB_TEXT ("f:i:m:p:s:t:w"), 0); + ACE_Get_Opt get_opt (argc, argv, ACE_LIB_TEXT ("f:i:m:p:s:t:wn:o"), 0); for (int c; (c = get_opt ()) != -1; ) { @@ -133,6 +140,15 @@ ACE_Logging_Strategy::parse_args (int argc, ACE_TCHAR *argv[]) this->max_size_ = ACE_DEFAULT_MAX_LOGFILE_SIZE; this->max_size_ <<= 10; // convert to KB break; + case 'n': + // The max number for the log_file being created + this->max_file_number_ = atoi (get_opt.optarg) - 1; + this->fixed_number_ = 1; + break; + case 'o': + // Log_files generation order + this->order_files_ = 1; + break; case 'p': temp = get_opt.optarg; // Now tokenize the string to setup process log priority @@ -166,7 +182,8 @@ ACE_Logging_Strategy::ACE_Logging_Strategy (void) #if defined (ACE_DEFAULT_LOGFILE) this->filename_ = ACE::strnew (ACE_DEFAULT_LOGFILE); #else /* ACE_DEFAULT_LOGFILE */ - ACE_NEW (this->filename_, ACE_TCHAR[MAXPATHLEN + 1]); + ACE_NEW (this->filename_, + ACE_TCHAR[MAXPATHLEN + 1]); // Get the temporary directory if (ACE_Lib_Find::get_temp_dir (this->filename_, @@ -301,22 +318,93 @@ ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &, ofstream *output_file = (ofstream *) ACE_LOG_MSG->msg_ostream (); output_file->close (); #endif /* ACE_LACKS_IOSTREAM_TOTALLY */ - // Save current logfile to logfile.old - if (ACE_OS::strlen (this->filename_) + 4 <= MAXPATHLEN) // 4 for ".old" + // Save current logfile to logfile.old analyse if it was set any + // fixed number for the log_files + if (fixed_number_) + { + if (max_file_number_ < 1) //we only want one file + { + // Just unlink the file. + ACE_OS::unlink (this->filename_); + + // Open a new log file with the same name. + output_file->open (ACE_TEXT_ALWAYS_CHAR (this->filename_), + ios::out); + + // Release the lock previously acquired. + ACE_LOG_MSG->release (); + return 0; + } + } + count_++; + + // Set the number of digits of the log_files labels. + int digits = 1, res = count_; + while((res = (res / 10))>0) + digits++; + + if (ACE_OS::strlen (this->filename_) + digits <= MAXPATHLEN) { ACE_TCHAR backup[MAXPATHLEN+1]; - ACE_OS::strcpy (backup, this->filename_); - ACE_OS::strcat (backup, ACE_LIB_TEXT (".old")); + // analyse if it was chosen the mode which will order the + // log_files + if (order_files_) + { + ACE_TCHAR to_backup[MAXPATHLEN+1]; + + // reorder the logs starting at the oldest (the biggest + // number) watch if we reached max_file_number_. + int max_num; + if (fixed_number_ && count_ > max_file_number_) + // count_ will always be bigger than max_file_number_, + // so do nothing so to always reorder files from + // max_file_number_. + max_num = max_file_number_; + else + max_num = count_; + + for (int i = max_num ; i > 1 ;i--) + { + ACE_OS::sprintf (backup, + "%s.%d", + this->filename_, + i); + ACE_OS::sprintf (to_backup, + "%s.%d", + this->filename_, + i - 1); + + // Remove any existing old file; ignore error as + // file may not exist. + ACE_OS::unlink (backup); + + // Rename the current log file to the name of the + // backup log file. + ACE_OS::rename (to_backup, backup); + } + ACE_OS::sprintf (backup, + "%s.1", + this->filename_); + } + else + { + if (fixed_number_ && count_>max_file_number_) //start over from 1 + count_ = 1; + + ACE_OS::sprintf (backup, + "%s.%d", + this->filename_, + count_); + } - // Remove any existing .old file; ignore error as file may + // Remove any existing old file; ignore error as file may // not exist. ACE_OS::unlink (backup); // Rename the current log file to the name of the backup log // file. - ACE_OS::rename (this->filename_, - backup); + ACE_OS::rename (this->filename_, backup); } else ACE_ERROR ((LM_ERROR, diff --git a/ace/Logging_Strategy.h b/ace/Logging_Strategy.h index d411fc7ef58..01fb4d8c8ae 100644 --- a/ace/Logging_Strategy.h +++ b/ace/Logging_Strategy.h @@ -62,7 +62,19 @@ public: */ virtual int handle_timeout (const ACE_Time_Value& tv, const void* arg); - /// Parse svc.conf arguments. + /** Parse arguments provided in svc.conf file. + '-f' + '-i' + '-m' + '-n' The maximum number of log_files that we want created. + '-o' Specifies that we want the no standard log_files ordering + (fastest processing in <handle_timeout>). Default is not to order + log files. + '-p' + '-s' + '-t' + '-w' + */ int parse_args (int argc, ACE_TCHAR *argv[]); private: @@ -86,13 +98,32 @@ private: ACE_TCHAR *filename_; /// If non-0 then wipeout the logfile, otherwise append to it. + /// Default value is 0. int wipeout_logfile_; + /// This tells us in what file we last wrote. It will be increased + /// to enable multiple log files + int count_; + + /// If non-0 we have a maximum number of log files we can write. + /// Default value is 0, i.e., no maximum number. + int fixed_number_; + + /// If non-0 we order the files as we rotate them. Default value + /// is 0, i.e., we do not rotate files by default. + int order_files_; + + /// Tells us what is the maximum log file to write. We will write + /// <max_file_number_> + 1 files (includes the current log file). + /// Default value is 1, i.e., 2 files by default. + int max_file_number_; + /// If non-zero, sampling interval (in secs) at which maximum logfile /// size is checked, otherwise logfile size can grow indefinitely. + /// Default value is 0. u_long interval_; - /// Maximum logfile size (in KB). + /// Maximum logfile size (in KB). Default value is <ACE_DEFAULT_MAX_LOGFILE_SIZE>. u_long max_size_; }; |