summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>2001-08-26 16:58:56 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>2001-08-26 16:58:56 +0000
commit2734d02efe58cb994e0cc71952c6003d7aa2dd7a (patch)
tree4e90f2b6e2e69b8b2afbc0883e5841f8c2efc064
parent3b72915d6688584274a33393d4abf05291703887 (diff)
downloadATCD-2734d02efe58cb994e0cc71952c6003d7aa2dd7a.tar.gz
ChangeLogTag:Sun Aug 26 08:13:12 2001 Douglas C. Schmidt <schmidt@macarena.cs.wustl.edu>
-rw-r--r--ChangeLog31
-rw-r--r--ChangeLogs/ChangeLog-02a31
-rw-r--r--ChangeLogs/ChangeLog-03a31
-rw-r--r--ace/Logging_Strategy.cpp134
-rw-r--r--ace/Logging_Strategy.h23
-rw-r--r--tests/Logging_Strategy_Test.cpp158
-rw-r--r--tests/test_config.h2
7 files changed, 291 insertions, 119 deletions
diff --git a/ChangeLog b/ChangeLog
index 2815063fe99..20e42d633f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Aug 26 08:13:12 2001 Douglas C. Schmidt <schmidt@macarena.cs.wustl.edu>
+
+ * tests/test_config.h: Added a new ACE_CLOSE_TEST_LOG macro. Thanks to
+ Edan for this.
+
Sun Aug 26 09:07:32 2001 Balachandran Natarajan <bala@cs.wustl.edu>
* ace/TP_Reactor.cpp: Fixed a compile error with SunCC4.2
@@ -9,6 +14,32 @@ Sun Aug 26 08:28:09 2001 Balachandran Natarajan <bala@cs.wustl.edu>
Sun Aug 26 08:13:12 2001 Douglas C. Schmidt <schmidt@macarena.cs.wustl.edu>
+ * tests/Logging_Strategy_Test.cpp: Applied the following fixes from
+ Edan:
+
+ - Included ace/Logging_Strategy.h
+ - Addition of -w switch to enable initial wipeout of logfile
+ - Removal of the redundant ACE_LOG_MSG->open()
+ - Explicitly close the previous log before applying the changes to the
+ ACE_LOG_MSG
+ - Moved remove_files() call higher, just before logfile close
+
+ * ace/Logging_Strategy.{h,cpp}: Added the following fixes from
+ Edan Ayal:
+
+ - Logging_Strategy now supports any ACE_Log_Msg, not just the
+ ACE_LOG_MSG singleton.
+ - Added a check for success (ios::goodbit) of new ofstream
+ creation.
+ - Changed default values for max_size and interval. Now the
+ default interval is 10 minutes (instead of 0) and the default
+ log file size is 0 (was 16K). The timer is now activated only
+ if both are non-zero.
+ - Added a mutator to set the ACE_Log_Msg to work with, and a
+ member variable
+ - Added definition for ACE_DEFAULT_LOGFILE_POLL_INTERVAL
+ - Removed definition of ACE_DEFAULT_MAX_LOGFILE_SIZE
+
* ace/Log_Record.{h,cpp}: Enhanced this implementation to (1)
be consistent with recent changes to Log_Msg.h and (2) to
replace problematic use of strncpy(). Thanks to Alain
diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a
index 2815063fe99..20e42d633f4 100644
--- a/ChangeLogs/ChangeLog-02a
+++ b/ChangeLogs/ChangeLog-02a
@@ -1,3 +1,8 @@
+Sun Aug 26 08:13:12 2001 Douglas C. Schmidt <schmidt@macarena.cs.wustl.edu>
+
+ * tests/test_config.h: Added a new ACE_CLOSE_TEST_LOG macro. Thanks to
+ Edan for this.
+
Sun Aug 26 09:07:32 2001 Balachandran Natarajan <bala@cs.wustl.edu>
* ace/TP_Reactor.cpp: Fixed a compile error with SunCC4.2
@@ -9,6 +14,32 @@ Sun Aug 26 08:28:09 2001 Balachandran Natarajan <bala@cs.wustl.edu>
Sun Aug 26 08:13:12 2001 Douglas C. Schmidt <schmidt@macarena.cs.wustl.edu>
+ * tests/Logging_Strategy_Test.cpp: Applied the following fixes from
+ Edan:
+
+ - Included ace/Logging_Strategy.h
+ - Addition of -w switch to enable initial wipeout of logfile
+ - Removal of the redundant ACE_LOG_MSG->open()
+ - Explicitly close the previous log before applying the changes to the
+ ACE_LOG_MSG
+ - Moved remove_files() call higher, just before logfile close
+
+ * ace/Logging_Strategy.{h,cpp}: Added the following fixes from
+ Edan Ayal:
+
+ - Logging_Strategy now supports any ACE_Log_Msg, not just the
+ ACE_LOG_MSG singleton.
+ - Added a check for success (ios::goodbit) of new ofstream
+ creation.
+ - Changed default values for max_size and interval. Now the
+ default interval is 10 minutes (instead of 0) and the default
+ log file size is 0 (was 16K). The timer is now activated only
+ if both are non-zero.
+ - Added a mutator to set the ACE_Log_Msg to work with, and a
+ member variable
+ - Added definition for ACE_DEFAULT_LOGFILE_POLL_INTERVAL
+ - Removed definition of ACE_DEFAULT_MAX_LOGFILE_SIZE
+
* ace/Log_Record.{h,cpp}: Enhanced this implementation to (1)
be consistent with recent changes to Log_Msg.h and (2) to
replace problematic use of strncpy(). Thanks to Alain
diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a
index 2815063fe99..20e42d633f4 100644
--- a/ChangeLogs/ChangeLog-03a
+++ b/ChangeLogs/ChangeLog-03a
@@ -1,3 +1,8 @@
+Sun Aug 26 08:13:12 2001 Douglas C. Schmidt <schmidt@macarena.cs.wustl.edu>
+
+ * tests/test_config.h: Added a new ACE_CLOSE_TEST_LOG macro. Thanks to
+ Edan for this.
+
Sun Aug 26 09:07:32 2001 Balachandran Natarajan <bala@cs.wustl.edu>
* ace/TP_Reactor.cpp: Fixed a compile error with SunCC4.2
@@ -9,6 +14,32 @@ Sun Aug 26 08:28:09 2001 Balachandran Natarajan <bala@cs.wustl.edu>
Sun Aug 26 08:13:12 2001 Douglas C. Schmidt <schmidt@macarena.cs.wustl.edu>
+ * tests/Logging_Strategy_Test.cpp: Applied the following fixes from
+ Edan:
+
+ - Included ace/Logging_Strategy.h
+ - Addition of -w switch to enable initial wipeout of logfile
+ - Removal of the redundant ACE_LOG_MSG->open()
+ - Explicitly close the previous log before applying the changes to the
+ ACE_LOG_MSG
+ - Moved remove_files() call higher, just before logfile close
+
+ * ace/Logging_Strategy.{h,cpp}: Added the following fixes from
+ Edan Ayal:
+
+ - Logging_Strategy now supports any ACE_Log_Msg, not just the
+ ACE_LOG_MSG singleton.
+ - Added a check for success (ios::goodbit) of new ofstream
+ creation.
+ - Changed default values for max_size and interval. Now the
+ default interval is 10 minutes (instead of 0) and the default
+ log file size is 0 (was 16K). The timer is now activated only
+ if both are non-zero.
+ - Added a mutator to set the ACE_Log_Msg to work with, and a
+ member variable
+ - Added definition for ACE_DEFAULT_LOGFILE_POLL_INTERVAL
+ - Removed definition of ACE_DEFAULT_MAX_LOGFILE_SIZE
+
* ace/Log_Record.{h,cpp}: Enhanced this implementation to (1)
be consistent with recent changes to Log_Msg.h and (2) to
replace problematic use of strncpy(). Thanks to Alain
diff --git a/ace/Logging_Strategy.cpp b/ace/Logging_Strategy.cpp
index 8b579680d8e..2fbd0b14ab2 100644
--- a/ace/Logging_Strategy.cpp
+++ b/ace/Logging_Strategy.cpp
@@ -8,7 +8,8 @@
ACE_RCSID(lib, Logging_Strategy, "$Id$")
-// Parse the string containing (thread) priorities and set them accordingly.
+// Parse the string containing (thread) priorities and set them
+// accordingly.
void
ACE_Logging_Strategy::priorities (ACE_TCHAR *priority_string,
@@ -25,7 +26,8 @@ ACE_Logging_Strategy::priorities (ACE_TCHAR *priority_string,
// Parse string and alternate priority mask.
- for (ACE_TCHAR *priority = ACE_OS::strtok (priority_string, ACE_LIB_TEXT ("|"));
+ for (ACE_TCHAR *priority = ACE_OS::strtok (priority_string,
+ ACE_LIB_TEXT ("|"));
priority != 0;
priority = ACE_OS::strtok (0, ACE_LIB_TEXT ("|")))
{
@@ -81,7 +83,8 @@ ACE_Logging_Strategy::priorities (ACE_TCHAR *priority_string,
void
ACE_Logging_Strategy::tokenize (ACE_TCHAR *flag_string)
{
- for (ACE_TCHAR *flag = ACE_OS::strtok (flag_string, ACE_LIB_TEXT ("|"));
+ for (ACE_TCHAR *flag = ACE_OS::strtok (flag_string,
+ ACE_LIB_TEXT ("|"));
flag != 0;
flag = ACE_OS::strtok (0, ACE_LIB_TEXT ("|")))
{
@@ -118,10 +121,11 @@ ACE_Logging_Strategy::parse_args (int argc, ACE_TCHAR *argv[])
this->fixed_number_ = 0;
this->order_files_ = 0;
this->max_file_number_ = 1;
- this->interval_ = 0;
- this->max_size_ = ACE_DEFAULT_MAX_LOGFILE_SIZE;
+ this->interval_ = ACE_DEFAULT_LOGFILE_POLL_INTERVAL;
+ this->max_size_ = 0;
- ACE_Get_Opt get_opt (argc, argv, ACE_LIB_TEXT ("f:i:k:m:n:N:op:s:t:w"), 0);
+ ACE_Get_Opt get_opt (argc, argv,
+ ACE_LIB_TEXT ("f:i:k:m:n:N:op:s:t:w"), 0);
for (int c; (c = get_opt ()) != -1; )
{
@@ -145,8 +149,6 @@ ACE_Logging_Strategy::parse_args (int argc, ACE_TCHAR *argv[])
case 'm':
// Maximum logfile size (in KB). Must be a non-zero value.
this->max_size_ = ACE_OS::strtoul (get_opt.optarg, 0, 10);
- if (this->max_size_ == 0)
- this->max_size_ = ACE_DEFAULT_MAX_LOGFILE_SIZE;
this->max_size_ <<= 10; // convert to KB
break;
case 'n':
@@ -191,6 +193,7 @@ ACE_Logging_Strategy::parse_args (int argc, ACE_TCHAR *argv[])
}
ACE_Logging_Strategy::ACE_Logging_Strategy (void)
+ : log_msg_ (ACE_Log_Msg::instance ())
{
#if defined (ACE_DEFAULT_LOGFILE)
this->filename_ = ACE::strnew (ACE_DEFAULT_LOGFILE);
@@ -199,8 +202,9 @@ ACE_Logging_Strategy::ACE_Logging_Strategy (void)
ACE_TCHAR[MAXPATHLEN + 1]);
// Get the temporary directory
- if (ACE_Lib_Find::get_temp_dir (this->filename_,
- MAXPATHLEN - 7) == -1) // 7 for "logfile"
+ if (ACE_Lib_Find::get_temp_dir
+ (this->filename_,
+ MAXPATHLEN - 7) == -1) // 7 for "logfile"
{
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT ("Temporary path too long, ")
@@ -233,34 +237,34 @@ ACE_Logging_Strategy::init (int argc, ACE_TCHAR *argv[])
// Store current priority masks for changes in <parse_args>.
this->process_priority_mask_ =
- ACE_Log_Msg::instance ()->priority_mask (ACE_Log_Msg::PROCESS);
+ this->log_msg_->priority_mask (ACE_Log_Msg::PROCESS);
this->thread_priority_mask_ =
- ACE_Log_Msg::instance ()->priority_mask (ACE_Log_Msg::THREAD);
+ this->log_msg_->priority_mask (ACE_Log_Msg::THREAD);
// Use the options hook to parse the command line arguments.
this->parse_args (argc, argv);
// Setup priorities (to original if not specified on command line)
- ACE_Log_Msg::instance ()->priority_mask (thread_priority_mask_,
- ACE_Log_Msg::THREAD);
+ this->log_msg_->priority_mask (thread_priority_mask_,
+ ACE_Log_Msg::THREAD);
- ACE_Log_Msg::instance ()->priority_mask (process_priority_mask_,
- ACE_Log_Msg::PROCESS);
+ this->log_msg_->priority_mask (process_priority_mask_,
+ ACE_Log_Msg::PROCESS);
// Check if any flags were specified. If none were specified, let
// the default behavior take effect.
if (this->flags_ != 0)
{
// Clear all flags
- ACE_Log_Msg::instance ()->clr_flags (ACE_Log_Msg::STDERR
- | ACE_Log_Msg::LOGGER
- | ACE_Log_Msg::OSTREAM
- | ACE_Log_Msg::VERBOSE
- | ACE_Log_Msg::VERBOSE_LITE
- | ACE_Log_Msg::SILENT
- | ACE_Log_Msg::SYSLOG);
+ this->log_msg_->clr_flags (ACE_Log_Msg::STDERR
+ | ACE_Log_Msg::LOGGER
+ | ACE_Log_Msg::OSTREAM
+ | ACE_Log_Msg::VERBOSE
+ | ACE_Log_Msg::VERBOSE_LITE
+ | ACE_Log_Msg::SILENT
+ | ACE_Log_Msg::SYSLOG);
// Check if OSTREAM bit is set
if (ACE_BIT_ENABLED (this->flags_,
ACE_Log_Msg::OSTREAM))
@@ -277,37 +281,47 @@ ACE_Logging_Strategy::init (int argc, ACE_TCHAR *argv[])
ofstream *output_file = 0;
// Create a new ofstream to direct output to the file.
if (wipeout_logfile_)
- ACE_NEW_RETURN (output_file,
- ofstream (ACE_TEXT_ALWAYS_CHAR (this->filename_)),
- -1);
+ ACE_NEW_RETURN
+ (output_file,
+ ofstream (ACE_TEXT_ALWAYS_CHAR (this->filename_)),
+ -1);
else
- ACE_NEW_RETURN (output_file,
- ofstream (ACE_TEXT_ALWAYS_CHAR (this->filename_),
- ios::app | ios::out),
- -1);
+ ACE_NEW_RETURN
+ (output_file,
+ ofstream (ACE_TEXT_ALWAYS_CHAR (this->filename_),
+ ios::app | ios::out),
+ -1);
+ if (output_file->rdstate () != ios::goodbit)
+ {
+ delete output_file;
+ return -1;
+ }
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
// Set the <output_file> that'll be used by the rest of the
// code.
- ACE_Log_Msg::instance ()->msg_ostream (output_file);
+ this->log_msg_->msg_ostream (output_file);
// Setup a timeout handler to perform the maximum file size
// check (if required).
- if (this->interval_ > 0)
+ if ((this->interval_ > 0) && (this->max_size_ > 0))
{
if (this->reactor () == 0)
- this->reactor (ACE_Reactor::instance ()); // Use singleton
- this->reactor ()->schedule_timer (this, 0,
- ACE_Time_Value (this->interval_),
- ACE_Time_Value (this->interval_));
+ // Use singleton.
+ this->reactor (ACE_Reactor::instance ());
+
+ this->reactor ()->schedule_timer
+ (this, 0,
+ ACE_Time_Value (this->interval_),
+ ACE_Time_Value (this->interval_));
}
}
// Now set the flags for Log_Msg
- ACE_Log_Msg::instance ()->set_flags (this->flags_);
+ this->log_msg_->set_flags (this->flags_);
}
- return ACE_LOG_MSG->open (this->program_name_,
- ACE_LOG_MSG->flags (),
- this->logger_key_);
+ return this->log_msg_->open (this->program_name_,
+ this->log_msg_->flags (),
+ this->logger_key_);
}
int
@@ -315,30 +329,32 @@ ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &,
const void *)
{
#if defined (ACE_LACKS_IOSTREAM_TOTALLY)
- if ((size_t) ACE_OS::fseek (ACE_LOG_MSG->msg_ostream (),
+ if ((size_t) ACE_OS::fseek (this->log_msg_->msg_ostream (),
0,
SEEK_CUR) > this->max_size_)
#else
- if ((size_t) ACE_LOG_MSG->msg_ostream ()->tellp () > this->max_size_)
+ if ((size_t) this->log_msg_->msg_ostream ()->tellp ()
+ > this->max_size_)
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
{
// Lock out any other logging.
- if (ACE_LOG_MSG->acquire ())
+ if (this->log_msg_->acquire ())
ACE_ERROR_RETURN ((LM_ERROR,
ACE_LIB_TEXT ("Cannot acquire lock!\n")),
-1);
// Close the current ostream.
#if defined (ACE_LACKS_IOSTREAM_TOTALLY)
- FILE *output_file = (FILE *) ACE_LOG_MSG->msg_ostream ();
+ FILE *output_file = (FILE *) this->log_msg_->msg_ostream ();
ACE_OS::fclose (output_file);
// We'll call msg_ostream() modifier later.
#else
- ofstream *output_file = (ofstream *) ACE_LOG_MSG->msg_ostream ();
+ ofstream *output_file =
+ (ofstream *) this->log_msg_->msg_ostream ();
output_file->close ();
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
- // Save current logfile to logfile.old analyse if it was set any
- // fixed number for the log_files
+ // Save current logfile to logfile.old analyze if it was set any
+ // fixed number for the log_files.
if (fixed_number_)
{
if (max_file_number_ < 1) //we only want one file
@@ -353,14 +369,14 @@ ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &,
if (output_file == 0)
return -1;
- ACE_LOG_MSG->msg_ostream (output_file);
+ this->log_msg_->msg_ostream (output_file);
#else
output_file->open (ACE_TEXT_ALWAYS_CHAR (this->filename_),
ios::out);
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
// Release the lock previously acquired.
- ACE_LOG_MSG->release ();
+ this->log_msg_->release ();
return 0;
}
}
@@ -417,8 +433,8 @@ ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &,
}
else
{
- if (fixed_number_ && count_>max_file_number_) //start over from 1
- count_ = 1;
+ if (fixed_number_ && count_>max_file_number_)
+ count_ = 1; // start over from 1
ACE_OS::sprintf (backup,
ACE_LIB_TEXT ("%s.%d"),
@@ -436,7 +452,8 @@ ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &,
}
else
ACE_ERROR ((LM_ERROR,
- ACE_LIB_TEXT ("Backup file name too long; backup logfile not saved.\n")));
+ ACE_LIB_TEXT ("Backup file name too long; ")
+ ACE_LIB_TEXT ("backup logfile not saved.\n")));
// Open a new log file by the same name
#if defined (ACE_LACKS_IOSTREAM_TOTALLY)
@@ -445,20 +462,27 @@ ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &,
if (output_file == 0)
return -1;
- ACE_LOG_MSG->msg_ostream (output_file);
+ this->log_msg_->msg_ostream (output_file);
#else
output_file->open (ACE_TEXT_ALWAYS_CHAR (this->filename_),
ios::out);
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
// Release the lock previously acquired.
- ACE_LOG_MSG->release ();
+ this->log_msg_->release ();
}
return 0;
}
+void
+ACE_Logging_Strategy::log_msg (ACE_Log_Msg *log_msg)
+{
+ this->log_msg_ = log_msg;
+}
+
// The following is a "Factory" used by the ACE_Service_Config and
-// svc.conf file to dynamically initialize the state of the Logging_Strategy.
+// svc.conf file to dynamically initialize the state of the
+// Logging_Strategy.
ACE_FACTORY_DEFINE (ACE, ACE_Logging_Strategy)
diff --git a/ace/Logging_Strategy.h b/ace/Logging_Strategy.h
index e035eaba24e..024455ddebb 100644
--- a/ace/Logging_Strategy.h
+++ b/ace/Logging_Strategy.h
@@ -10,7 +10,6 @@
*/
//=============================================================================
-
#ifndef ACE_LOGGING_STRATEGY_H
#define ACE_LOGGING_STRATEGY_H
@@ -21,9 +20,9 @@
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
-#if !defined (ACE_DEFAULT_MAX_LOGFILE_SIZE)
-#define ACE_DEFAULT_MAX_LOGFILE_SIZE 16384 /* KB */
-#endif /* ACE_DEFAULT_MAX_LOGFILE_SIZE */
+#if !defined (ACE_DEFAULT_LOGFILE_POLL_INTERVAL)
+#define ACE_DEFAULT_LOGFILE_POLL_INTERVAL 600 /* Seconds */
+#endif /* ACE_DEFAULT_LOGFILE_POLL_INTERVAL */
/**
* @class ACE_Logging_Strategy
@@ -74,7 +73,8 @@ public:
* size exceeds <max_size_>, the current logfile is closed, saved to
* logfile.old, and a new logfile is reopened.
*/
- virtual int handle_timeout (const ACE_Time_Value& tv, const void* arg);
+ virtual int handle_timeout (const ACE_Time_Value& tv,
+ const void* arg);
/** Parse arguments provided in svc.conf file.
'-f' Pass in the flags (such as OSTREAM, STDERR, LOGGER, VERBOSE,
@@ -86,8 +86,8 @@ public:
'-n' Set the program name for the %n format specifier.
'-N' The maximum number of logfiles that we want created.
'-o' Specifies that we want the no standard logfiles ordering
- (fastest processing in <handle_timeout>). Default is not to order
- logfiles.
+ (fastest processing in <handle_timeout>). Default is not to
+ order logfiles.
'-p' Pass in the process-wide priorities to either enable (e.g.,
DEBUG, INFO, WARNING, NOTICE, ERROR, CRITICAL, ALERT,
EMERGENCY) or to disable (e.g., ~DEBUG, ~INFO, ~WARNING,
@@ -102,6 +102,8 @@ public:
*/
int parse_args (int argc, ACE_TCHAR *argv[]);
+ void log_msg (ACE_Log_Msg *log_msg);
+
private:
/// Tokenize to set all the flags
void tokenize (ACE_TCHAR *flag_string);
@@ -124,6 +126,7 @@ private:
/// Logger key for distributed logging.
ACE_TCHAR *logger_key_;
+
/// Program name to be used for %n format specifier.
ACE_TCHAR *program_name_;
@@ -153,8 +156,12 @@ private:
/// Default value is 0.
u_long interval_;
- /// Maximum logfile size (in KB). Default value is <ACE_DEFAULT_MAX_LOGFILE_SIZE>.
+ /// Maximum logfile size (in KB). Default value is
+ /// <ACE_DEFAULT_MAX_LOGFILE_SIZE>.
u_long max_size_;
+
+ /// ACE_Log_Msg instance to work with
+ ACE_Log_Msg *log_msg_;
};
ACE_FACTORY_DECLARE (ACE, ACE_Logging_Strategy)
diff --git a/tests/Logging_Strategy_Test.cpp b/tests/Logging_Strategy_Test.cpp
index 5b94a84d4af..f2cd54cc5f7 100644
--- a/tests/Logging_Strategy_Test.cpp
+++ b/tests/Logging_Strategy_Test.cpp
@@ -9,17 +9,24 @@
// Logging_Strategy_Test.cpp
//
// = DESCRIPTION
-// This program tests the <ACE_Logging_Strategy> class in various ways
-// and also illustrates many of the features of the <ACE_Log_Msg>.
-// The test works as follows:
+// This program tests the <ACE_Logging_Strategy> class in various
+// ways and also illustrates many of the features of the
+// <ACE_Log_Msg>. The test works as follows:
// -Load the inserted arguments;
-// -Remove existent log_files with the file_name specified by the user;
-// -Generate 1000 messages to create the DEBUG statements to be stored in
-// the files;
-// -Counts the created log_files and if it was specified a maximum number
-// of log_files, compare and verify if they are the same.
+// -Remove existent log_files with the file_name specified by the
+// user;
+// -Generate 1000 messages to create the DEBUG statements to be
+// stored in the files;
+// -Counts the created log_files and if it was specified a maximum
+// number of log_files, compare and verify if they are the same.
// -Verify the order of the files with the order argument.
//
+// When Dlls are used, we utilize the dynamic service
+// configuration mechanism to activate the logging strategy. This
+// is not a must though, and you may activate the logging strategy
+// as described in the non-DLL section below under DLL
+// environments as well.
+//
// = AUTHOR
// Orlando Ribeiro <oribeiro@inescporto.pt>
//
@@ -28,10 +35,18 @@
#include "ace/OS.h"
#include "ace/Service_Config.h"
#include "ace/Thread_Manager.h"
-#include <ace/Get_Opt.h>
+
+#if defined (ACE_AS_STATIC_LIBS) || \
+ (!defined (ACE_WIN32) && !defined (ACE_HAS_SVR4_DYNAMIC_LINKING) && \
+ !defined (__hpux))
+#include "ace/Logging_Strategy.cpp"
+#endif
+
+#include "ace/Auto_Ptr.cpp"
+#include "ace/Get_Opt.h"
#include "test_config.h"
-ACE_RCSID(tests, Logging_Strategy_Test, "Logging_Strategy_Test.cpp,v 1.00 2001/02/19 05:17:39 oribeiro Exp")
+ACE_RCSID(tests, Logging_Strategy_Test, "$Id$")
#if !defined (ACE_LACKS_PRAGMA_ONCE)
#pragma once
@@ -71,11 +86,13 @@ static int max_num_files = 0;
static int interval_time = 0;
static int order_state = 0;
static int num_files = 0;
+static int wipeout_logfile = 0;
void
run_reactor (void *)
{
- ACE_Reactor::instance ()->owner (ACE_Thread_Manager::instance ()->thr_self ());
+ ACE_Reactor::instance ()->owner
+ (ACE_Thread_Manager::instance ()->thr_self ());
ACE_Reactor::instance ()->run_event_loop ();
}
@@ -147,12 +164,14 @@ count_files (void)
{
if (max_num_files != num_files)
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("Creating files...Failed! Imput value=%d, Checked value=%d"),
+ ACE_TEXT ("Creating files...Failed!")
+ ACE_TEXT (" Input value=%d, Checked value=%d"),
max_num_files,
num_files));
else
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT (" Creating files...OK! Imput value=%d, Checked value=%d"),
+ ACE_TEXT (" Creating files...OK!")
+ ACE_TEXT (" Input value=%d, Checked value=%d"),
max_num_files,
num_files));
}
@@ -206,7 +225,8 @@ order (void)
if (num_files == 1)
get_statistic (file_name);
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT (" Ordering...OK! - Only %d file (s) was (were) generated"),
+ ACE_TEXT (" Ordering...OK! - ")
+ ACE_TEXT (" Only %d file (s) was (were) generated"),
num_files));
}
else
@@ -240,7 +260,8 @@ order (void)
if ((tm_bk_1 < tm_bk_2) && order_state)
{
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT (" %s (newest) ; %s (oldest)\n"),
+ ACE_TEXT (" %s (newest);")
+ ACE_TEXT ("%s (oldest)\n"),
backup_2,
backup_1));
ACE_DEBUG ((LM_DEBUG,
@@ -248,7 +269,8 @@ order (void)
}
else
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT (" Ordering...FAILED! - The files are disorderly")));
+ ACE_TEXT (" Ordering...FAILED!")
+ ACE_TEXT ("- The files are disorderly")));
}
}
@@ -278,12 +300,11 @@ remove_files (void)
test = ACE_OS::unlink (backup);
if (test != 0)
error = 1;
-
}
while (error != 1);
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("-< removing existent files finished... \n\n")));
+ ACE_TEXT ("-< removing existing files...\n\n")));
}
static int
@@ -291,7 +312,7 @@ parse_args (int argc, ACE_TCHAR *argv[])
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Specifications:\n")));
- ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("s:i:m:f:n:o"));
+ ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("s:i:m:f:N:ow"));
int c;
while ((c = get_opt ()) != EOF)
@@ -320,7 +341,7 @@ parse_args (int argc, ACE_TCHAR *argv[])
ACE_TEXT ("Modes: %s\n"),
get_opt.optarg));
break;
- case 'n':
+ case 'N':
max_num_files = ACE_OS::atoi (get_opt.optarg);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Maximum files number: %d\n"),
@@ -331,17 +352,27 @@ parse_args (int argc, ACE_TCHAR *argv[])
ACE_TEXT ("Ordering files activated\n")));
order_state = 1;
break;
+ case 'w':
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Wipeout logfile activated\n")));
+ wipeout_logfile = 1;
+ break;
default:
- ACE_ERROR_RETURN ((LM_ERROR,
- ACE_TEXT ("usage: [-s]<file_name>")
- ACE_TEXT ("[-i]<sample_interval> [-m]<max_size> [-f]<msg_flags> [-n]<num_files> [-o]\n")
- ACE_TEXT ("\t-s: Specify the name of the log files.\n")
- ACE_TEXT ("\t-i: Define the sample interval in secs.\n")
- ACE_TEXT ("\t-m: Define the max size for the log_files in KB.\n")
- ACE_TEXT ("\t-f: Indicates the Log_Msg flags.\n")
- ACE_TEXT ("\t-n: Define the maximum number of log_files.\n")
- ACE_TEXT ("\t-o: If activated puts the log_files ordered.\n")),
- -1);
+ ACE_ERROR_RETURN
+ ((LM_ERROR,
+ ACE_TEXT ("usage: [-s]<file_name>")
+ ACE_TEXT ("[-i]<sample_interval> ")
+ ACE_TEXT ("[-m]<max_size> [-f]<msg_flags> ")
+ ACE_TEXT ("[-n]<num_files> [-o]\n")
+ ACE_TEXT ("\t-s: Specify the name of the log files.\n")
+ ACE_TEXT ("\t-i: Define the sample interval in secs.\n")
+ ACE_TEXT ("\t-m: Define the max size for the log_files in KB.\n")
+ ACE_TEXT ("\t-f: Indicates the Log_Msg flags.\n")
+ ACE_TEXT ("\t-N: Define the maximum number of log_files.\n")
+ ACE_TEXT ("\t-o: If activated puts the log_files ordered.\n"),
+ ACE_TEXT ("\t-w: If activated cause the logfile to be wiped out,")
+ ACE_TEXT (" both on startup and on reconfigure.\n")),
+ -1);
/* NOTREACHED */
break;
}
@@ -354,13 +385,6 @@ int main (int argc, ACE_TCHAR *argv [])
{
ACE_START_TEST (ACE_TEXT ("Logging_Strategy_Test"));
- // Protection against this test being run on platforms not supporting Dlls.
-#if defined (ACE_WIN32) || defined (ACE_HAS_SVR4_DYNAMIC_LINKING) || \
- defined (__hpux)
-
- // Implement the dynamic entries via main arguments
- ACE_LOG_MSG->open (argv[0]);
-
ACE_TCHAR *l_argv[4];
if (argc > 1)
@@ -373,7 +397,8 @@ int main (int argc, ACE_TCHAR *argv [])
else
{
l_argv[0] = argv[0];
- l_argv[1] = (ACE_TCHAR *) ACE_TEXT ("-slog/Logging_Strategy_Test.log");
+ l_argv[1] =
+ (ACE_TCHAR *) ACE_TEXT ("-slog/Logging_Strategy_Test.log");
l_argv[2] = (ACE_TCHAR *) ACE_TEXT ("-o");
l_argv[3] = 0;
@@ -385,9 +410,28 @@ int main (int argc, ACE_TCHAR *argv [])
argc = 3;
}
+ // Remove the existent files
+ remove_files ();
+
+ // This is necessary only if the provided logfile name is the same
+ // as the default name. If so, nothing will be written as the
+ // previous ofstream is closed only at the end (ACE_END_TEST)
+ ACE_CLOSE_TEST_LOG;
+
+ // When Dlls are used, we utilize the dynamic service configuration
+ // mechanism to activate the logging strategy. This is not a must
+ // though, and you may activate the logging strategy as described in
+ // the non-DLL section below under DLL environments as well.
+
+#if !defined (ACE_AS_STATIC_LIBS) && \
+ (defined (ACE_WIN32) || defined (ACE_HAS_SVR4_DYNAMIC_LINKING) || \
+ defined (__hpux))
+ // Platform support DLLs, and not configured to link statically
ACE_TCHAR arg_str[250];
ACE_OS::sprintf (arg_str,
- ACE_TEXT ("dynamic Logger Service_Object *ACE:_make_ACE_Logging_Strategy() \""));
+ ACE_TEXT ("dynamic Logger Service_Object ")
+ ACE_TEXT ("*ACE:_make_ACE_Logging_Strategy()")
+ ACE_TEXT ("\""));
for (int i = 1; i < argc; i++)
{
@@ -399,18 +443,32 @@ int main (int argc, ACE_TCHAR *argv [])
if (ACE_Service_Config::process_directive (arg_str) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
- "Error opening _make_ACE_Log_Strategy object.\n"),
+ "Error opening _make_ACE_Log_Strategy.\n"),
1);
+#else // Platform doesn't support DLLs, or configured to link
+ // statically
+ ACE_Logging_Strategy logging_strategy;
+ char ls_argc = argc - 1;
+ auto_ptr<ACE_TCHAR *> ls_argv (new ACE_TCHAR *[ls_argc]);
+
+ for (char c = 0; c < ls_argc; c++)
+ (ls_argv.get ())[c] = argv[c+1];
+
+ if (logging_strategy.init (ls_argc, ls_argv.get ()) == -1)
+ ACE_ERROR_RETURN
+ ((LM_ERROR,
+ "Error initializing the ACE_Logging_Strategy.\n"),
+ 1);
+#endif /* !ACE_AS_STATIC_LIBS && (ACE_WIN32 ||
+ ACE_HAS_SVR4_DYNAMIC_LINKING || __hpux) */
// launch a new Thread
- if (ACE_Thread_Manager::instance ()->spawn (ACE_THR_FUNC (run_reactor)) < 0)
+ if (ACE_Thread_Manager::instance ()->spawn
+ (ACE_THR_FUNC (run_reactor)) < 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Spawning Reactor.\n"),
1);
- // Remove the existent files
- remove_files ();
-
// Function to print the message
print_till_death ();
@@ -425,18 +483,6 @@ int main (int argc, ACE_TCHAR *argv [])
"Error ending reactor.\n"),
1);
-#else
- ACE_ERROR ((LM_INFO,
- ACE_TEXT ("DLLs not supported on this platform\n")));
-
- ACE_UNUSED_ARG (argc);
- ACE_UNUSED_ARG (argv);
- ACE_UNUSED_ARG (print_till_death);
- ACE_UNUSED_ARG (order);
- ACE_UNUSED_ARG (remove_files);
- ACE_UNUSED_ARG (parse_args);
-#endif /* ACE_WIN32 || ACE_HAS_SVR4_DYNAMIC_LINKING || __hpux */
-
ACE_END_TEST;
return 0;
}
diff --git a/tests/test_config.h b/tests/test_config.h
index a8607168076..25604e36ad7 100644
--- a/tests/test_config.h
+++ b/tests/test_config.h
@@ -89,6 +89,8 @@ const size_t ACE_MAX_THREADS = 4;
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Ending %s test at %D\n"), program)); \
ace_file_stream::instance()->close ()
+#define ACE_CLOSE_TEST_LOG ace_file_stream::instance()->close ()
+
#if !defined (ACE_WIN32)
#define ACE_APPEND_LOG(NAME) \
const ACE_TCHAR *program = NAME; \