diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1996-10-21 21:41:34 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1996-10-21 21:41:34 +0000 |
commit | a5fdebc5f6375078ec1763850a4ca23ec7fe6458 (patch) | |
tree | bcf0a25c3d45a209a6e3ac37b233a4812f29c732 /netsvcs/lib/Logging_Strategy.cpp | |
download | ATCD-a5fdebc5f6375078ec1763850a4ca23ec7fe6458.tar.gz |
Initial revision
Diffstat (limited to 'netsvcs/lib/Logging_Strategy.cpp')
-rw-r--r-- | netsvcs/lib/Logging_Strategy.cpp | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/netsvcs/lib/Logging_Strategy.cpp b/netsvcs/lib/Logging_Strategy.cpp new file mode 100644 index 00000000000..af2a0fc5f31 --- /dev/null +++ b/netsvcs/lib/Logging_Strategy.cpp @@ -0,0 +1,145 @@ +// Logging_Strategy.cpp +// @(#)Logging_Strategy.cpp 1.1 10/18/96 + +#define ACE_BUILD_SVC_DLL +#include "iostream.h" +#include "fstream.h" +#include "ace/Get_Opt.h" +#include "ace/Log_Msg.h" +#include "ace/Service_Object.h" +#include "Logging_Strategy.h" + +class ACE_Logging_Strategy : public ACE_Service_Object + // = TITLE + // This class provides the hooks to control the output produced + // by any of the network services. + // + // = DESCRIPTION + // Depending upon when this service is invoked and with what + // flags, the output of other network services can be + // controlled. The output can be streamed to stderr, to a file, + // to a logging daemon, or it can be set to be "silent". +{ +public: + virtual int init (int argc, char *argv[]); + // Dynamic linking hook. + + int parse_args (int argc, char *argv[]); + // Parse svc.conf arguments. +private: + void tokenize (char *flag_string); + // Tokenize to set all the flags + u_long flags_; + char *filename_; +}; + +// Parse the string containing all the flags and set the flags accordingly +void +ACE_Logging_Strategy::tokenize (char *flag_string) +{ + char *flag; + if ((flag = ACE_OS::strtok (flag_string, "|")) != NULL) + { + while (flag) + { + if (ACE_OS::strcmp (flag, "STDERR") == 0) + ACE_SET_BITS (this->flags_, ACE_Log_Msg::STDERR); + else if (ACE_OS::strcmp (flag, "LOGGER") == 0) + ACE_SET_BITS (this->flags_, ACE_Log_Msg::LOGGER); + else if (ACE_OS::strcmp (flag, "OSTREAM") == 0) + ACE_SET_BITS (this->flags_, ACE_Log_Msg::OSTREAM); + else if (ACE_OS::strcmp (flag, "VERBOSE") == 0) + ACE_SET_BITS (this->flags_, ACE_Log_Msg::VERBOSE); + else if (ACE_OS::strcmp (flag, "SILENT") == 0) + ACE_SET_BITS (this->flags_, ACE_Log_Msg::SILENT); + + // Get the next flag + flag = ACE_OS::strtok(0, "|"); + } + } +} + +int +ACE_Logging_Strategy::parse_args (int argc, char *argv[]) +{ + ACE_TRACE ("ACE_Logging_Strategy::parse_args"); + char *temp; + u_long flag = 0; + + this->flags_ = 0; + this->filename_ = ACE_DEFAULT_LOGFILE; + + ACE_LOG_MSG->open ("Logging_Strategy"); + + ACE_Get_Opt get_opt (argc, argv, "f:s:", 0); + + for (int c; (c = get_opt ()) != -1; ) + { + switch (c) + { + case 'f': + temp = get_opt.optarg; + // Now tokenize the string to get all the flags + this->tokenize (temp); + break; + case 's': + // Ensure that the OSTREAM flag is set + ACE_SET_BITS (this->flags_, ACE_Log_Msg::OSTREAM); + this->filename_ = get_opt.optarg; + break; + default: + break; + } + } + return 0; +} + +int +ACE_Logging_Strategy::init (int argc, char *argv[]) +{ + ACE_TRACE ("ACE_Logging_Strategy::init"); + + // Use the options hook to parse the command line arguments. + this->parse_args (argc, argv); + + // 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::SILENT); + // Check if OSTREAM bit is set + if (ACE_BIT_ENABLED (this->flags_, ACE_Log_Msg::OSTREAM)) + { + // Create a new ofstream to direct output to the file + ofstream *output_file = new ofstream (this->filename_); + ACE_Log_Msg::instance()->msg_ostream (output_file); + } + // Now set the flags for Log_Msg + ACE_Log_Msg::instance()->set_flags (this->flags_); + } + return 0; +} + +// The following is a "Factory" used by the ACE_Service_Config and +// svc.conf file to dynamically initialize the state of the Logging_Strategy. + +ACE_SVC_FACTORY_DEFINE (ACE_Logging_Strategy) + +#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) +template class ACE_Strategy_Acceptor<ACE_TS_Server_Handler, ACE_SOCK_Acceptor, ACE_INET_Addr>; +template class ACE_Schedule_All_Reactive_Strategy<ACE_TS_Server_Handler>; +#if defined (ACE_HAS_THREADS) +template class ACE_Svc_Handler<ACE_SOCK_Stream, ACE_INET_Addr, ACE_Null_Mutex, ACE_Null_Condition_Mutex>; +template class ACE_Task<ACE_Null_Mutex, ACE_Null_Condition_Mutex>; +template class ACE_Message_Queue<ACE_Null_Mutex, ACE_Null_Condition_Mutex>; +template class ACE_Module<ACE_Null_Mutex, ACE_Null_Condition_Mutex>; +template class ACE_Task_Exit<ACE_Null_Mutex, ACE_Null_Condition_Mutex>; +template class ACE_TSS<ACE_Task_Exit<ACE_Null_Mutex, ACE_Null_Condition_Mutex> >; +template class ACE_Thru_Task<ACE_Null_Mutex, ACE_Null_Condition_Mutex>; +#endif +#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ |