Update NEWS
[ACE_TAO.git] / ACE / netsvcs / lib / Log_Message_Receiver.h
blob2315741ae7e0293702ef6813a9feab885e02f750
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Log_Message_Receiver.h
7 * @author Per Andersson
8 */
9 //=============================================================================
11 #ifndef LOG_MESSAGE_RECEIVER_H
12 #define LOG_MESSAGE_RECEIVER_H
14 #include "ace/Log_Record.h"
16 #if !defined (ACE_LACKS_PRAGMA_ONCE)
17 # pragma once
18 #endif /* ACE_LACKS_PRAGMA_ONCE */
20 #include "ace/Synch_Traits.h"
21 #include "ace/Guard_T.h"
22 #if defined (ACE_HAS_THREADS)
23 # include "ace/Thread_Mutex.h"
24 #else
25 # include "ace/Null_Mutex.h"
26 #endif /* ACE_HAS_THREADS */
28 // ==========================================================================//
29 //------------- General Requirements on a Log Message Receiver --------------//
30 // ==========================================================================//
31 // The requirements on a log manager receiver, T, are quite simple.
32 // 1: There must exist one "log_record" member function with the following
33 // prototype:
34 // void log_record(const ACE_TCHAR *hostname,
35 // ACE_Log_Record &record);
37 // 2: There must exist a public destructor.
38 // 3: There must exist a public copy constructor.
39 // 4: There must exist a default constructor. (for now)
41 // The semantics are also simple. A log message receiver should
42 // behave as an accessor object (smart pointer or envelope class).
43 // It should be very cheap to copy and the should be no noticeable
44 // difference when using either the new copy or the old log message
45 // receiver.
47 // Methods:
48 // void log_record(const ACE_TCHAR* hostname,
49 // ACE_Log_Record& record)
50 // Description:
51 // Processes the log record "record" from the host "hostname"
52 // Precondition:
53 // hostname != 0;
54 // Requirements:
55 // Record must be a valid ACE_Log_Record.
57 // ==========================================================================//
59 // ==========================================================================//
60 // ------------ General Description of a Log Message Receiver -------------- //
61 // ==========================================================================//
62 // Log Message Receivers, LRMs, are processing log records. It is the
63 // LRM that writes a log message to stderr, stdout, a log file and maybee
64 // converts some of the log messages to notifications, warnings, alarms
65 // and forwards them to some operation and maintenance system (PATROL).
67 // The client logging handler and server logging handler are responsible
68 // for forwarding, receiving, framing, processing log records.
69 // That is a very usable service, but it should also be possible to change
70 // how log records are processed without having to rewrite code in
71 // the server log handler. This code should instead be written as a
72 // separate entity, a Log Message Receiver.
74 // A simple LMR should be very easy to write but it should also
75 // be possible to write more complex LMRs, like one that creates
76 // a new log file each day or keeps a fixed size, round robin,
77 // log file. It should also be possible to have separate LMRs
78 // of the same type that uses different log files.
80 // ==========================================================================//
83 // Type based log message receiver
84 /**
85 * @class Static_Log_Message_Receiver
87 * @brief Static_Log_Message_Receiver is a simple log message receiver. It
88 * has no instance data and only static member
89 * functions. Static/typed based receivers are best when all LMR
90 * should do exactly the same thing.
92 * This class contains a static log_record member function that
93 * prints the content of log_records on stderr.
95 template<ACE_SYNCH_DECL>
96 class Static_Log_Message_Receiver
99 public:
100 /// Prints the log_record to stderr using record.print (hostname, 0, stderr).
101 /// Serializes the output by using a ACE_SYNCH_MUTEX.
102 static void log_record(const ACE_TCHAR *hostname,
103 ACE_Log_Record &record);
105 /// Prints the log_record to a user specified ostream.
106 static void log_output(const ACE_TCHAR *hostname,
107 ACE_Log_Record &record,
108 ostream *output);
111 // Instance based log message receiver
113 // ------------------------ Log_Message_Receiver --------------------------- //
114 // Log_Message_Receiver is little more complicated log message receiver.
115 // It is instance based and have a reference counted implementation.
116 // Log_Message_Receiver is the envelope class for Log_Message_Receiver_Impl.
118 // ------------------------------------------------------------------------- //
121 //Forward declaration
122 template<ACE_SYNCH_DECL> class Log_Message_Receiver_Impl;
125 * @class Log_Message_Receiver
127 * @brief Log_Message_Receiver is a little more complicated log message
128 * receiver. It is instance based and have a reference counted
129 * implementation. Log_Message_Receiver is the envelope class for
130 * Log_Message_Receiver_Impl. The difference between
131 * Static_Log_Message_Receiver and Log_Message_Receiver is that is
132 * possible to have instance data in Log_Message_Receiver.
133 * Comment:
134 * The practical usage of this is limited with the current
135 * ACE_Server_Logging_Acceptor_T design. Since
136 * ACE_Server_Logging_Acceptor_T will create the
137 * Log_Message_Receiver using the default constructor. The main
138 * reason for inclusion right now is to ensure that the code in
139 * ACE_Server_Logging_Handler_T works both with type and instance
140 * based LMRs.
142 * This class contains a log_record member function that prints the
143 * content of log_records on stderr.
145 template<ACE_SYNCH_DECL>
146 class Log_Message_Receiver
148 public:
149 /// Creates a new Log_Message_Receiver
150 Log_Message_Receiver (void);
151 Log_Message_Receiver(Log_Message_Receiver<ACE_SYNCH_USE> const &rhs);
152 ~Log_Message_Receiver (void);
154 void log_record (const ACE_TCHAR *hostname,
155 ACE_Log_Record &record);
157 void log_output(const ACE_TCHAR *hostname,
158 ACE_Log_Record &record,
159 ostream *output);
160 private:
161 ACE_UNIMPLEMENTED_FUNC (void operator= (const Log_Message_Receiver<ACE_SYNCH_USE> &rhs))
163 // Attributes.
164 Log_Message_Receiver_Impl<ACE_SYNCH_USE> *receiver_impl_;
168 * @class Log_Message_Receiver_Impl
170 * @brief Implementation with reference count.
172 template<ACE_SYNCH_DECL>
173 class Log_Message_Receiver_Impl
175 public:
176 // Methods for handling reference count and instance lifetime
177 static Log_Message_Receiver_Impl *create (void);
178 static Log_Message_Receiver_Impl *attach (Log_Message_Receiver_Impl<ACE_SYNCH_USE> *body);
179 static void detach (Log_Message_Receiver_Impl<ACE_SYNCH_USE> *body);
181 void log_record (const ACE_TCHAR *hostname, ACE_Log_Record &record);
183 void log_output(const ACE_TCHAR *hostname,
184 ACE_Log_Record &record,
185 ostream *output);
187 protected:
188 Log_Message_Receiver_Impl (void);
189 ~Log_Message_Receiver_Impl (void);
191 /// Attributes
192 int count_;
193 ACE_SYNCH_MUTEX_T print_lock_;
195 private:
196 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
197 static ACE_SYNCH_MUTEX_T copy_lock_;
198 #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
199 ACE_UNIMPLEMENTED_FUNC (void operator= (const Log_Message_Receiver_Impl<ACE_SYNCH_USE> &))
200 ACE_UNIMPLEMENTED_FUNC (Log_Message_Receiver_Impl (const Log_Message_Receiver_Impl<ACE_SYNCH_USE> &))
203 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
204 #include "Log_Message_Receiver.cpp"
205 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
207 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
208 #pragma implementation ("Log_Message_Receiver.cpp")
209 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
211 #endif /* LOG_MESSAGE_RECEIVER_H */