summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-02-15 03:02:30 +0000
committernanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-02-15 03:02:30 +0000
commit05d6c8f4d4e165dd00a7aae5561b8f127512c14c (patch)
tree9608b020078f605b0a1593afb1fd1b56061b6e9a
parent028f64acab68488083f48809af433a64c833f329 (diff)
downloadATCD-05d6c8f4d4e165dd00a7aae5561b8f127512c14c.tar.gz
Added functions to allow writing messages to user specified ostream
-rw-r--r--netsvcs/lib/Log_Message_Receiver.cpp63
-rw-r--r--netsvcs/lib/Log_Message_Receiver.h61
2 files changed, 84 insertions, 40 deletions
diff --git a/netsvcs/lib/Log_Message_Receiver.cpp b/netsvcs/lib/Log_Message_Receiver.cpp
index b4d1471165f..6f4f5e63f81 100644
--- a/netsvcs/lib/Log_Message_Receiver.cpp
+++ b/netsvcs/lib/Log_Message_Receiver.cpp
@@ -14,19 +14,32 @@ Static_Log_Message_Receiver<ACE_SYNCH_USE>::log_record (char const *hostname,
static ACE_SYNCH_MUTEX_T lock_;
ACE_Guard<ACE_SYNCH_MUTEX_T> guard (lock_);
#endif /* ACE_HAS_THREADS */
-
+
record.print (hostname, 0, stderr);
}
+template<ACE_SYNCH_DECL> void
+Static_Log_Message_Receiver<ACE_SYNCH_USE>::log_output (char const *hostname,
+ ACE_Log_Record &record,
+ ostream *outputfile)
+{
+#if defined (ACE_HAS_THREADS)
+ static ACE_SYNCH_MUTEX_T lock_;
+ ACE_Guard<ACE_SYNCH_MUTEX_T> guard (lock_);
+#endif /* ACE_HAS_THREADS */
+
+ record.print (hostname, 0, (*outputfile) );
+}
+
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
-template<ACE_SYNCH_DECL>
+template<ACE_SYNCH_DECL>
ACE_SYNCH_MUTEX_T Log_Message_Receiver_Impl<ACE_SYNCH_USE>::copy_lock_;
#else
static ACE_SYNCH_MUTEX global_copy_lock_;
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
-template<ACE_SYNCH_DECL> inline
-Log_Message_Receiver_Impl<ACE_SYNCH_USE>::Log_Message_Receiver_Impl (void)
+template<ACE_SYNCH_DECL> inline
+Log_Message_Receiver_Impl<ACE_SYNCH_USE>::Log_Message_Receiver_Impl (void)
: count_ (0)
{
}
@@ -44,12 +57,12 @@ Log_Message_Receiver_Impl<ACE_SYNCH_USE>::attach (Log_Message_Receiver_Impl<ACE_
{
ACE_ASSERT (body != 0);
-#if defined (ACE_HAS_THREADS)
+#if defined (ACE_HAS_THREADS)
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
Guard guard (copy_lock_);
#else
// Use the "body"s print lock as copy lock.
- ACE_Guard<ACE_SYNCH_MUTEX> guard (global_copy_lock_);
+ ACE_Guard<ACE_SYNCH_MUTEX> guard (global_copy_lock_);
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
#endif /* ACE_HAS_THREADS */
++body->count_;
@@ -60,13 +73,13 @@ template<ACE_SYNCH_DECL> inline void
Log_Message_Receiver_Impl<ACE_SYNCH_USE>::detach(Log_Message_Receiver_Impl<ACE_SYNCH_USE> *body)
{
ACE_ASSERT (body != 0);
-
-#if defined (ACE_HAS_THREADS)
+
+#if defined (ACE_HAS_THREADS)
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
Guard guard (copy_lock_);
#else
// Use the "body"s print lock as copy lock.
- ACE_Guard<ACE_SYNCH_MUTEX> guard (global_copy_lock_);
+ ACE_Guard<ACE_SYNCH_MUTEX> guard (global_copy_lock_);
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
#endif /* ACE_HAS_THREADS */
if (body->count_-- == 0)
@@ -82,25 +95,34 @@ Log_Message_Receiver_Impl<ACE_SYNCH_USE>::log_record (char const *hostname,
record.print (hostname, 0, stderr);
}
-template<ACE_SYNCH_DECL> inline
+template<ACE_SYNCH_DECL> void
+Log_Message_Receiver_Impl<ACE_SYNCH_USE>::log_output (char const *hostname,
+ ACE_Log_Record &record,
+ ostream *outputfile)
+{
+ ACE_MT (Guard guard (print_lock_));
+ record.print (hostname, 0, (*outputfile) );
+}
+
+template<ACE_SYNCH_DECL> inline
Log_Message_Receiver_Impl<ACE_SYNCH_USE>::~Log_Message_Receiver_Impl (void)
{
ACE_ASSERT (count_ == 0 - 1);
}
template<ACE_SYNCH_DECL>
-Log_Message_Receiver<ACE_SYNCH_USE>::Log_Message_Receiver (void)
+Log_Message_Receiver<ACE_SYNCH_USE>::Log_Message_Receiver (void)
: receiver_impl_ (Log_Message_Receiver_Impl<ACE_SYNCH_USE>::create ())
{
- ACE_ASSERT (receiver_impl_ != 0);
+ ACE_ASSERT (receiver_impl_ != 0);
}
template<ACE_SYNCH_DECL>
-Log_Message_Receiver<ACE_SYNCH_USE>::Log_Message_Receiver
+Log_Message_Receiver<ACE_SYNCH_USE>::Log_Message_Receiver
(Log_Message_Receiver<ACE_SYNCH_USE> const &rhs)
: receiver_impl_ (Log_Message_Receiver_Impl<ACE_SYNCH_USE>::attach (rhs.receiver_impl_))
{
- ACE_ASSERT (receiver_impl_ != 0);
+ ACE_ASSERT (receiver_impl_ != 0);
}
// Type based log message receiver
@@ -108,14 +130,23 @@ template<ACE_SYNCH_DECL> void
Log_Message_Receiver<ACE_SYNCH_USE>::log_record(char const *hostname,
ACE_Log_Record &record)
{
- ACE_ASSERT (receiver_impl_ != 0);
+ ACE_ASSERT (receiver_impl_ != 0);
receiver_impl_->log_record (hostname, record);
}
+template<ACE_SYNCH_DECL> void
+Log_Message_Receiver<ACE_SYNCH_USE>::log_output(char const *hostname,
+ ACE_Log_Record &record,
+ ostream *outputfile)
+{
+ ACE_ASSERT (receiver_impl_ != 0);
+ receiver_impl_->log_output (hostname, record, outputfile);
+}
+
template<ACE_SYNCH_DECL>
Log_Message_Receiver<ACE_SYNCH_USE>::~Log_Message_Receiver (void)
{
- ACE_ASSERT (receiver_impl_ != 0);
+ ACE_ASSERT (receiver_impl_ != 0);
Log_Message_Receiver_Impl<ACE_SYNCH_USE>::detach (receiver_impl_);
}
diff --git a/netsvcs/lib/Log_Message_Receiver.h b/netsvcs/lib/Log_Message_Receiver.h
index 54c51107dac..f67ad7fa084 100644
--- a/netsvcs/lib/Log_Message_Receiver.h
+++ b/netsvcs/lib/Log_Message_Receiver.h
@@ -5,13 +5,13 @@
//
// = LIBRARY
// ace
-//
+//
// = FILENAME
// Log_Message_Receiver
//
// = AUTHOR
// Per Andersson
-//
+//
// ============================================================================
#if !defined (LOG_MESSAGE_RECEIVER_H)
@@ -36,17 +36,17 @@
//
//
// The semantics are also simple. A log message receiver should
-// behave as an accessor object (smart pointer or envelope class).
-// It should be very cheap to copy and the should be no noticeable
-// difference when using either the new copy or the old log message
+// behave as an accessor object (smart pointer or envelope class).
+// It should be very cheap to copy and the should be no noticeable
+// difference when using either the new copy or the old log message
// receiver.
//
// Methods:
// void log_record(char const* hostname,
// ACE_Log_Record& record)
-// Description:
+// Description:
// Processes the log record "record" from the host "hostname"
-// Precondition:
+// Precondition:
// hostname != 0;
// Requirements:
// Record must be a valid ACE_Log_Record.
@@ -63,13 +63,13 @@
// and forwards them to some operation and maintenance system (PATROL).
//
// The client logging handler and server logging handler are responsible
-// for forwarding, receiving, framing, processing log records.
+// for forwarding, receiving, framing, processing log records.
// That is a very usable service, but it should also be possible to change
-// how log records are processed without having to rewrite code in
-// the server log handler. This code should instead be written as a
-// separate entity, a Log Message Receiver.
+// how log records are processed without having to rewrite code in
+// the server log handler. This code should instead be written as a
+// separate entity, a Log Message Receiver.
//
-// A simple LMR should be very easy to write but it should also
+// A simple LMR should be very easy to write but it should also
// be possible to write more complex LMRs, like one that creates
// a new log file each day or keeps a fixed size, round robin,
// log file. It should also be possible to have separate LMRs
@@ -79,7 +79,7 @@
// Type based log message receiver
-template<ACE_SYNCH_DECL>
+template<ACE_SYNCH_DECL>
class Static_Log_Message_Receiver
// = TITLE
// Static_Log_Message_Receiver is a simple log message receiver. It
@@ -91,10 +91,15 @@ class Static_Log_Message_Receiver
// prints the content of log_records on stderr.
{
public:
- static void log_record(const char *hostname,
+ static void log_record(const char *hostname,
ACE_Log_Record &record);
// Prints the log_record to stderr using record.print (hostname, 0, stderr).
// Serializes the output by using a ACE_SYNCH_MUTEX.
+
+ static void log_output(const char *hostname,
+ ACE_Log_Record &record,
+ ostream *output);
+ // Prints the log_record to a user specified ostream.
};
// Instance based log message receiver
@@ -104,22 +109,22 @@ public:
// Log_Message_Receiver is little more complicated log message receiver.
// It is instance based and have a reference counted implementation.
// Log_Message_Receiver is the envelope class for Log_Message_Receiver_Impl.
-//
+//
// ------------------------------------------------------------------------- //
//Forward declaration
template<ACE_SYNCH_DECL> class Log_Message_Receiver_Impl;
-template<ACE_SYNCH_DECL>
+template<ACE_SYNCH_DECL>
class Log_Message_Receiver
// = TITLE
// Log_Message_Receiver is a little more complicated log message receiver.
// It is instance based and have a reference counted implementation.
// Log_Message_Receiver is the envelope class for Log_Message_Receiver_Impl.
- // The difference between Static_Log_Message_Receiver and
+ // The difference between Static_Log_Message_Receiver and
// Log_Message_Receiver is that is possible to have instance data
- // in Log_Message_Receiver.
+ // in Log_Message_Receiver.
//
// Comment:
// The practical usage of this is limited with the current
@@ -139,19 +144,23 @@ public:
// Creates a new Log_Message_Receiver
Log_Message_Receiver(Log_Message_Receiver<ACE_SYNCH_USE> const &rhs);
~Log_Message_Receiver (void);
-
+
void log_record (const char *hostname,
- ACE_Log_Record &record);
+ ACE_Log_Record &record);
+
+ void log_output(const char *hostname,
+ ACE_Log_Record &record,
+ ostream *output);
private:
ACE_UNIMPLEMENTED_FUNC (void operator= (const Log_Message_Receiver<ACE_SYNCH_USE> &rhs))
-
+
// Attributes.
Log_Message_Receiver_Impl<ACE_SYNCH_USE> *receiver_impl_;
};
// Implementation with reference count.
-template<ACE_SYNCH_DECL>
+template<ACE_SYNCH_DECL>
class Log_Message_Receiver_Impl
{
friend class ACE_Shutup_GPlusPlus; // Turn off g++ warning
@@ -160,14 +169,18 @@ public:
static Log_Message_Receiver_Impl *create (void);
static Log_Message_Receiver_Impl *attach (Log_Message_Receiver_Impl<ACE_SYNCH_USE> *body);
static void detach (Log_Message_Receiver_Impl<ACE_SYNCH_USE> *body);
-
+
void log_record (const char *hostname,
ACE_Log_Record &record);
+ void log_output(const char *hostname,
+ ACE_Log_Record &record,
+ ostream *output);
+
private:
Log_Message_Receiver_Impl (void);
~Log_Message_Receiver_Impl (void);
-
+
typedef ACE_Guard<ACE_SYNCH_MUTEX_T> Guard;
// Attributes
int count_;