summaryrefslogtreecommitdiff
path: root/modules/CIAO/DAnCE/Logger
diff options
context:
space:
mode:
Diffstat (limited to 'modules/CIAO/DAnCE/Logger')
-rw-r--r--modules/CIAO/DAnCE/Logger/DAnCELoggerFactory.h19
-rw-r--r--modules/CIAO/DAnCE/Logger/DAnCE_Logger_Export.h58
-rw-r--r--modules/CIAO/DAnCE/Logger/File_Logger_Backend.cpp46
-rw-r--r--modules/CIAO/DAnCE/Logger/File_Logger_Backend.h50
-rw-r--r--modules/CIAO/DAnCE/Logger/Log_Macros.h90
-rw-r--r--modules/CIAO/DAnCE/Logger/Logger.mpc18
-rw-r--r--modules/CIAO/DAnCE/Logger/Logger_Service.cpp159
-rw-r--r--modules/CIAO/DAnCE/Logger/Logger_Service.h29
8 files changed, 469 insertions, 0 deletions
diff --git a/modules/CIAO/DAnCE/Logger/DAnCELoggerFactory.h b/modules/CIAO/DAnCE/Logger/DAnCELoggerFactory.h
new file mode 100644
index 00000000000..f2ed4800950
--- /dev/null
+++ b/modules/CIAO/DAnCE/Logger/DAnCELoggerFactory.h
@@ -0,0 +1,19 @@
+// $Id$
+#ifndef DAnCE_LOGGERFACTORY_BASE_H_
+#define DAnCE_LOGGERFACTORY_BASE_H_
+
+#include "ace/Service_Object.h"
+#include "tao/ORB.h"
+#include "ace/Log_Msg_Backend.h"
+
+namespace DAnCE
+ {
+
+ class DAnCELoggerFactory : public ACE_Service_Object
+ {
+ public:
+ virtual ACE_Log_Msg_Backend * get_logger_backend (CORBA::ORB_ptr orb) = 0;
+ };
+} // DAnCE
+
+#endif /*LOGGERFACTORY_H_*/
diff --git a/modules/CIAO/DAnCE/Logger/DAnCE_Logger_Export.h b/modules/CIAO/DAnCE/Logger/DAnCE_Logger_Export.h
new file mode 100644
index 00000000000..e8e7cb3c81a
--- /dev/null
+++ b/modules/CIAO/DAnCE/Logger/DAnCE_Logger_Export.h
@@ -0,0 +1,58 @@
+
+// -*- C++ -*-
+// $Id$
+// Definition for Win32 Export directives.
+// This file is generated automatically by generate_export_file.pl DAnCE_Logger
+// ------------------------------
+#ifndef DANCE_LOGGER_EXPORT_H
+#define DANCE_LOGGER_EXPORT_H
+
+#include "ace/config-all.h"
+
+#if defined (ACE_AS_STATIC_LIBS) && !defined (DANCE_LOGGER_HAS_DLL)
+# define DANCE_LOGGER_HAS_DLL 0
+#endif /* ACE_AS_STATIC_LIBS && DANCE_LOGGER_HAS_DLL */
+
+#if !defined (DANCE_LOGGER_HAS_DLL)
+# define DANCE_LOGGER_HAS_DLL 1
+#endif /* ! DANCE_LOGGER_HAS_DLL */
+
+#if defined (DANCE_LOGGER_HAS_DLL) && (DANCE_LOGGER_HAS_DLL == 1)
+# if defined (DANCE_LOGGER_BUILD_DLL)
+# define DAnCE_Logger_Export ACE_Proper_Export_Flag
+# define DANCE_LOGGER_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T)
+# define DANCE_LOGGER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
+# else /* DANCE_LOGGER_BUILD_DLL */
+# define DAnCE_Logger_Export ACE_Proper_Import_Flag
+# define DANCE_LOGGER_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T)
+# define DANCE_LOGGER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
+# endif /* DANCE_LOGGER_BUILD_DLL */
+#else /* DANCE_LOGGER_HAS_DLL == 1 */
+# define DAnCE_Logger_Export
+# define DANCE_LOGGER_SINGLETON_DECLARATION(T)
+# define DANCE_LOGGER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
+#endif /* DANCE_LOGGER_HAS_DLL == 1 */
+
+// Set DANCE_LOGGER_NTRACE = 0 to turn on library specific tracing even if
+// tracing is turned off for ACE.
+#if !defined (DANCE_LOGGER_NTRACE)
+# if (ACE_NTRACE == 1)
+# define DANCE_LOGGER_NTRACE 1
+# else /* (ACE_NTRACE == 1) */
+# define DANCE_LOGGER_NTRACE 0
+# endif /* (ACE_NTRACE == 1) */
+#endif /* !DANCE_LOGGER_NTRACE */
+
+#if (DANCE_LOGGER_NTRACE == 1)
+# define DANCE_LOGGER_TRACE(X)
+#else /* (DANCE_LOGGER_NTRACE == 1) */
+# if !defined (ACE_HAS_TRACE)
+# define ACE_HAS_TRACE
+# endif /* ACE_HAS_TRACE */
+# define DANCE_LOGGER_TRACE(X) ACE_TRACE_IMPL(X)
+# include "ace/Trace.h"
+#endif /* (DANCE_LOGGER_NTRACE == 1) */
+
+#endif /* DANCE_LOGGER_EXPORT_H */
+
+// End of auto generated file.
diff --git a/modules/CIAO/DAnCE/Logger/File_Logger_Backend.cpp b/modules/CIAO/DAnCE/Logger/File_Logger_Backend.cpp
new file mode 100644
index 00000000000..7e45b0fa26a
--- /dev/null
+++ b/modules/CIAO/DAnCE/Logger/File_Logger_Backend.cpp
@@ -0,0 +1,46 @@
+// $Id$
+#include "File_Logger_Backend.h"
+#include "ace/OS_NS_stdio.h"
+#include "ace/Log_Record.h"
+#include "ace/Log_Msg.h"
+#include "Log_Macros.h"
+
+namespace DAnCE
+ {
+
+ int
+ File_Logger_Backend::open (const ACE_TCHAR *)
+ {
+ DANCE_DEBUG ((LM_DEBUG, "[%M] Setting logger's output to file \"%s\"\n", this->filename_.c_str()));
+ this->fh_ = ACE_OS::fopen (this->filename_.c_str(), "a+");
+ if (0 == this->fh_)
+ {
+ ACE_TString s = ACE_TEXT("Failed to open log file \"");
+ s += this->filename_;
+ s += ACE_TEXT("\"\n");
+ throw LoggerError (s.c_str());
+ }
+ return 0;
+ }
+
+ int
+ File_Logger_Backend::close (void)
+ {
+ if (0 != this->fh_)
+ {
+ ACE_OS::fclose (this->fh_);
+ this->fh_ = 0;
+ }
+ return 0;
+ }
+
+ ssize_t
+ File_Logger_Backend::log (ACE_Log_Record &log_record)
+ {
+ int res = log_record.print (0, ACE_Log_Msg::VERBOSE, this->fh_);
+ ACE_OS::fflush (this->fh_);
+ return res;
+ }
+
+}
+
diff --git a/modules/CIAO/DAnCE/Logger/File_Logger_Backend.h b/modules/CIAO/DAnCE/Logger/File_Logger_Backend.h
new file mode 100644
index 00000000000..6a02326f429
--- /dev/null
+++ b/modules/CIAO/DAnCE/Logger/File_Logger_Backend.h
@@ -0,0 +1,50 @@
+// $Id$
+#ifndef FILE_LOGGER_BACKEND_H_
+#define FILE_LOGGER_BACKEND_H_
+
+#include "ace/Log_Msg_Backend.h"
+#include "DAnCE_Logger_Export.h"
+#include "ace/SString.h"
+
+namespace DAnCE
+ {
+
+ class DAnCE_Logger_Export LoggerError
+ {
+ public:
+ LoggerError (const ACE_TCHAR * msg)
+ : errmsg_ (msg) {};
+ ACE_TString errmsg_;
+ };
+
+ class DAnCE_Logger_Export File_Logger_Backend : public ACE_Log_Msg_Backend
+ {
+ public:
+ File_Logger_Backend (const ACE_TCHAR * fname)
+ : fh_ (0), filename_ (fname) {}
+
+ virtual ~File_Logger_Backend (void)
+ {
+ this->close();
+ };
+
+ virtual int open (const ACE_TCHAR *logger_key);
+
+ virtual int reset (void)
+ {
+ this->close();
+ return this->open (0);
+ };
+
+ virtual int close (void);
+
+ virtual ssize_t log (ACE_Log_Record &log_record);
+
+ private:
+ FILE * fh_;
+ ACE_TString filename_;
+ };
+
+} // DAnCE
+
+#endif /*FILE_LOGGER_BACKEND_H_*/
diff --git a/modules/CIAO/DAnCE/Logger/Log_Macros.h b/modules/CIAO/DAnCE/Logger/Log_Macros.h
new file mode 100644
index 00000000000..4b2f9c35274
--- /dev/null
+++ b/modules/CIAO/DAnCE/Logger/Log_Macros.h
@@ -0,0 +1,90 @@
+/**
+ * @file Log_Macros.h
+ * @author William R. Otte <wotte@dre.vanderbilt.edu>
+ * // $Id$
+ * Macros used for logging in DAnCE
+ */
+
+
+#ifndef DANCE_LOG_MACROS_H_
+#define DANCE_LOG_MACROS_H_
+
+/*
+// By default tracing is turned off.
+#if !defined (DANCE_NTRACE)
+# if !defined (ACE_NTRACE)
+# define DANCE_NTRACE 1
+# else
+# define DANCE_NTRACE ACE_NTRACE
+# endif
+#endif DANCE_NTRACE
+*/
+#define DLINFO ACE_TEXT("(%P|%t) [%M] - %T - ")
+
+#if (DANCE_NTRACE == 1)
+# if !defined (ACE_NTRACE)
+# define DANCE_TRACE(X) do {} while (0)
+# define DANCE_ENABLE_TRACE(X) do {} while (0)
+# define DANCE_DISABLE_TRACE(X) do {} while (0)
+# else
+# if (ACE_NTRACE == 0)
+# error DANCE_TRACE cannot be disabled if ACE_TRACE is enabled
+# else
+# define DANCE_TRACE(X) do {} while (0)
+# define DANCE_ENABLE_TRACE(X) do {} while (0)
+# define DANCE_DISABLE_TRACE(X) do {} while (0)
+# endif
+# endif
+#else
+# if !defined (ACE_HAS_TRACE)
+# define ACE_HAS_TRACE
+# endif /* ACE_HAS_TRACE */
+# define DANCE_TRACE(X) ACE_TRACE_IMPL (X)
+# define DANCE_ENABLE_TRACE() ACE_Trace::start_tracing ()
+# define DANCE_DISABLE_TRACE() ACE_Trace::stop_tracing ()
+# undef DLINFO // Make log messages indent with tracing.
+# define DLINFO ACE_TEXT("%I(%P|%t) [%M] - %T - ")
+# include "ace/Trace.h"
+#endif /* DANCE_NTRACE */
+
+#if defined (DANCE_NLOGGING)
+# define DANCE_ERROR(X) do {} while (0)
+# define DANCE_DEBUG(X) do {} while (0)
+#define DANCE_ERROR_RETURN(X, Y) return (Y)
+#define DANCE_ERROR_BREAK(X) { break; }
+#else
+# if !defined (DANCE_ERROR)
+# define DANCE_ERROR(X) \
+ do { \
+ int __ace_error = ACE_Log_Msg::last_error_adapter (); \
+ ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
+ ace___->conditional_set (__FILE__, __LINE__, -1, __ace_error); \
+ ace___->log X; \
+ } while (0)
+# endif
+# if !defined (DANCE_DEBUG)
+# define DANCE_DEBUG(X) \
+ do { \
+ int __ace_error = ACE_Log_Msg::last_error_adapter (); \
+ ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
+ ace___->conditional_set (__FILE__, __LINE__, 0, __ace_error); \
+ ace___->log X; \
+ } while (0)
+# endif
+# if !defined (DANCE_ERROR_RETURN)
+# define DANCE_ERROR_RETURN(X, Y) \
+ do { \
+ int __ace_error = ACE_Log_Msg::last_error_adapter (); \
+ ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
+ ace___->conditional_set (__FILE__, __LINE__, Y, __ace_error); \
+ ace___->log X; \
+ return Y; \
+ } while (0)
+# endif
+# if !defined (DANCE_ERROR_BREAK)
+# define DANCE_ERROR_BREAK(X) { DANCE_ERROR (X); break; }
+# endif
+#endif
+
+
+#endif
diff --git a/modules/CIAO/DAnCE/Logger/Logger.mpc b/modules/CIAO/DAnCE/Logger/Logger.mpc
new file mode 100644
index 00000000000..6dc00272492
--- /dev/null
+++ b/modules/CIAO/DAnCE/Logger/Logger.mpc
@@ -0,0 +1,18 @@
+// -*- MPC -*-
+// $Id$
+
+project(DAnCE_Logger): dance_lib, messaging, acelib {
+ sharedname = DAnCE_Logger
+ dynamicflags = DANCE_LOGGER_BUILD_DLL
+
+ Source_Files {
+ File_Logger_Backend.cpp
+ Logger_Service.cpp
+ }
+ Header_Files {
+ }
+}
+
+
+
+
diff --git a/modules/CIAO/DAnCE/Logger/Logger_Service.cpp b/modules/CIAO/DAnCE/Logger/Logger_Service.cpp
new file mode 100644
index 00000000000..ff87b584097
--- /dev/null
+++ b/modules/CIAO/DAnCE/Logger/Logger_Service.cpp
@@ -0,0 +1,159 @@
+// $Id$
+#include "Logger_Service.h"
+#include "ace/Get_Opt.h"
+#include "ace/Env_Value_T.h"
+#include "ace/CORBA_macros.h"
+#include "tao/SystemException.h"
+#include "Log_Macros.h"
+
+namespace DAnCE
+ {
+ Logger_Service::Logger_Service (void)
+ : filename_ (ACE_TEXT("")),
+ trace_ (false),
+ log_level_ (5)
+ {
+ }
+
+ int
+ Logger_Service::init (int argc, ACE_TCHAR * argv[])
+ {
+ // Get prospective values from the environment first, those given on
+ // command line can override
+ ACE_Env_Value<int> log (ACE_TEXT("DANCE_LOG_LEVEL"), this->log_level_);
+
+ this->log_level_ = log;
+
+ ACE_Env_Value<int> trace (ACE_TEXT("DANCE_TRACE_ENABLE"), this->trace_);
+ this->trace_ = trace;
+
+ ACE_Env_Value<const ACE_TCHAR *> filename (ACE_TEXT("DANCE_LOG_FILE"), this->filename_.c_str ());
+ this->filename_ = filename;
+
+ this->parse_args (argc, argv);
+
+ this->set_levels ();
+
+ return 0;
+ }
+
+
+ void
+ Logger_Service::parse_args (int argc, ACE_TCHAR **argv)
+ {
+ const ACE_TCHAR *shortl = ACE_TEXT("-l");
+ const ACE_TCHAR *longl = ACE_TEXT("--log-level");
+ const ACE_TCHAR *tracel = ACE_TEXT("--trace");
+ // const ACE_TCHAR *traces = "-t";
+ const ACE_TCHAR *lfl = ACE_TEXT("--log-file");
+ const ACE_TCHAR *lfs = ACE_TEXT("-f");
+
+ // We need to actually FIND the -l option, as the get_opt won't ignore
+ // the ORB options and such.
+ for (int i = 0; i < argc; ++i)
+ {
+ if (//ACE_OS::strncmp (argv[i], traces, 2) == 0 ||
+ ACE_OS::strncmp (argv[i], tracel, 7) == 0)
+ {
+ this->trace_ = true;
+ continue;
+ }
+
+ if (ACE_OS::strncmp (argv[i], shortl, 2) == 0 ||
+ ACE_OS::strncmp (argv[i], longl, 11 ) == 0)
+ {
+ if ((i + 1) < argc && *argv[i + 1] != '-')
+ {
+ int level = ACE_OS::atoi (argv[i + 1]);
+
+ if (level != 0)
+ this->log_level_ = level;
+ }
+ }
+
+ if (ACE_OS::strncmp (argv[i], lfs, 2) == 0 ||
+ ACE_OS::strncmp (argv[i], lfl, 10 ) == 0)
+ {
+ if ((i + 1) < argc && *argv[i + 1] != '-')
+ {
+ this->filename_ = argv[i+1];
+ }
+ }
+ }
+ }
+
+ void
+ Logger_Service::set_levels (void)
+ {
+ if (this->trace_)
+ {
+ DANCE_ENABLE_TRACE ();
+ this->log_level_ = 10;
+ }
+ else
+ {
+ DANCE_DISABLE_TRACE ();
+ }
+
+ u_long new_mask = 0;
+
+ if (this->log_level_ >= 9)
+ {
+ new_mask |= LM_TRACE;
+ }
+ if (this->log_level_ >= 8)
+ {
+ new_mask |= LM_DEBUG;
+ }
+ if (this->log_level_ >= 7)
+ {
+ new_mask |= LM_INFO;
+ }
+ if (this->log_level_ >= 6)
+ {
+ new_mask |= LM_NOTICE;
+ }
+ if (this->log_level_ >= 5)
+ {
+ new_mask |= LM_WARNING;
+ }
+ if (this->log_level_ >= 4)
+ {
+ new_mask |= LM_ERROR;
+ }
+ if (this->log_level_ >= 3)
+ {
+ new_mask |= LM_CRITICAL;
+ }
+ if (this->log_level_ >= 2)
+ {
+ new_mask |= LM_ALERT;
+ }
+ if (this->log_level_ >= 1)
+ {
+ new_mask |= LM_EMERGENCY;
+ }
+
+ ACE_Log_Msg::instance()->priority_mask(new_mask, ACE_Log_Msg::PROCESS);
+ DANCE_DEBUG ( (LM_TRACE, DLINFO ACE_TEXT("Logging level is set to %i\n"), this->log_level_));
+ }
+
+ ACE_Log_Msg_Backend *
+ Logger_Service::get_logger_backend (CORBA::ORB_ptr)
+ {
+ if (this->filename_ != ACE_TEXT(""))
+ {
+ File_Logger_Backend * the_backend = 0;
+ ACE_NEW_THROW_EX (the_backend,
+ File_Logger_Backend (this->filename_.c_str()),
+ CORBA::NO_MEMORY());
+ return the_backend;
+ }
+ return 0;
+ }
+
+} // DAnCE
+
+using namespace DAnCE;
+ACE_FACTORY_DEFINE (DAnCE_Logger, Logger_Service)
+
diff --git a/modules/CIAO/DAnCE/Logger/Logger_Service.h b/modules/CIAO/DAnCE/Logger/Logger_Service.h
new file mode 100644
index 00000000000..5713bf96755
--- /dev/null
+++ b/modules/CIAO/DAnCE/Logger/Logger_Service.h
@@ -0,0 +1,29 @@
+// $Id$
+#ifndef LOGGER_SERVICE_H_
+#define LOGGER_SERVICE_H_
+
+#include "DAnCE/Logger/DAnCE_Logger_Export.h"
+#include "DAnCE/Logger/DAnCELoggerFactory.h"
+#include "DAnCE/Logger/File_Logger_Backend.h"
+
+namespace DAnCE
+{
+ class DAnCE_Logger_Export Logger_Service : public ::DAnCE::DAnCELoggerFactory
+ {
+ public:
+ Logger_Service (void);
+ virtual int init (int argc, ACE_TCHAR * argv[]);
+ virtual ACE_Log_Msg_Backend * get_logger_backend (CORBA::ORB_ptr orb);
+ private:
+ void parse_args (int argc, ACE_TCHAR **argv);
+ void set_levels (void);
+
+ ACE_TString filename_;
+ bool trace_;
+ int log_level_;
+ };
+} // DAnCE
+
+ACE_FACTORY_DECLARE (DAnCE_Logger, Logger_Service)
+
+#endif /*LOGGER_SERVICE_H_*/