source: pacpusframework/branches/2.0-beta1/3rd/apache-log4cxx/include/log4cxx/net/smtpappender.h@ 89

Last change on this file since 89 was 89, checked in by morasjul, 11 years ago

PACPUS 2.0 Beta deployed in new branch

Major changes:
-Add communication interface between components
-Add examples for communications interface (TestComponents)
-Move to Qt5 support

  • Property svn:executable set to *
File size: 11.8 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _LOG4CXX_NET_SMTP_H
19#define _LOG4CXX_NET_SMTP_H
20
21
22#include <log4cxx/appenderskeleton.h>
23#include <log4cxx/helpers/cyclicbuffer.h>
24#include <log4cxx/spi/triggeringeventevaluator.h>
25
26namespace log4cxx
27{
28 namespace net
29 {
30 /**
31 Send an e-mail when a specific logging event occurs, typically on
32 errors or fatal errors.
33 <p>The number of logging events delivered in this e-mail depend on
34 the value of <b>BufferSize</b> option. The
35 <code>SMTPAppender</code> keeps only the last
36 <code>BufferSize</code> logging events in its cyclic buffer. This
37 keeps memory requirements at a reasonable level while still
38 delivering useful application context.
39 */
40 class LOG4CXX_EXPORT SMTPAppender : public AppenderSkeleton
41 {
42 private:
43
44 private:
45 SMTPAppender(const SMTPAppender&);
46 SMTPAppender& operator=(const SMTPAppender&);
47 static bool asciiCheck(const LogString& value, const LogString& label);
48 /**
49 This method determines if there is a sense in attempting to append.
50 <p>It checks whether there is a set output target and also if
51 there is a set layout. If these checks fail, then the boolean
52 value <code>false</code> is returned. */
53 bool checkEntryConditions();
54
55 LogString to;
56 LogString cc;
57 LogString bcc;
58 LogString from;
59 LogString subject;
60 LogString smtpHost;
61 LogString smtpUsername;
62 LogString smtpPassword;
63 int smtpPort;
64 int bufferSize; // 512
65 bool locationInfo;
66 helpers::CyclicBuffer cb;
67 spi::TriggeringEventEvaluatorPtr evaluator;
68
69 public:
70 DECLARE_LOG4CXX_OBJECT(SMTPAppender)
71 BEGIN_LOG4CXX_CAST_MAP()
72 LOG4CXX_CAST_ENTRY(SMTPAppender)
73 LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
74 END_LOG4CXX_CAST_MAP()
75
76 SMTPAppender();
77 /**
78 The default constructor will instantiate the appender with a
79 spi::TriggeringEventEvaluator that will trigger on events with
80 level ERROR or higher.*/
81 SMTPAppender(log4cxx::helpers::Pool& p);
82
83 /**
84 Use <code>evaluator</code> passed as parameter as the
85 spi::TriggeringEventEvaluator for this net::SMTPAppender.
86 */
87 SMTPAppender(spi::TriggeringEventEvaluatorPtr evaluator);
88
89 ~SMTPAppender();
90
91 /**
92 Set options
93 */
94 virtual void setOption(const LogString& option, const LogString& value);
95
96 /**
97 Activate the specified options, such as the smtp host, the
98 recipient, from, etc.
99 */
100 virtual void activateOptions(log4cxx::helpers::Pool& p);
101
102 /**
103 Perform SMTPAppender specific appending actions, mainly adding
104 the event to a cyclic buffer and checking if the event triggers
105 an e-mail to be sent. */
106 virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p);
107
108
109 virtual void close();
110
111 /**
112 Returns value of the <b>To</b> option.
113 */
114 LogString getTo() const;
115
116 /**
117 Returns value of the <b>cc</b> option.
118 */
119 LogString getCc() const;
120
121 /**
122 Returns value of the <b>bcc</b> option.
123 */
124 LogString getBcc() const;
125
126
127 /**
128 The <code>SMTPAppender</code> requires a {@link
129 Layout layout}. */
130 virtual bool requiresLayout() const;
131
132 /**
133 Send the contents of the cyclic buffer as an e-mail message.
134 */
135 void sendBuffer(log4cxx::helpers::Pool& p);
136
137
138 /**
139 Returns value of the <b>EvaluatorClass</b> option.
140 */
141 LogString getEvaluatorClass();
142
143 /**
144 Returns value of the <b>From</b> option.
145 */
146 LogString getFrom() const;
147
148 /**
149 Returns value of the <b>Subject</b> option.
150 */
151 LogString getSubject() const;
152
153
154 /**
155 The <b>From</b> option takes a string value which should be a
156 e-mail address of the sender.
157 */
158 void setFrom(const LogString& from);
159
160 /**
161 The <b>Subject</b> option takes a string value which should be a
162 the subject of the e-mail message.
163 */
164 void setSubject(const LogString& subject);
165
166 /**
167 The <b>BufferSize</b> option takes a positive integer
168 representing the maximum number of logging events to collect in a
169 cyclic buffer. When the <code>BufferSize</code> is reached,
170 oldest events are deleted as new events are added to the
171 buffer. By default the size of the cyclic buffer is 512 events.
172 */
173 void setBufferSize(int bufferSize);
174
175 /**
176 The <b>SMTPHost</b> option takes a string value which should be a
177 the host name of the SMTP server that will send the e-mail message.
178 */
179 void setSMTPHost(const LogString& smtpHost);
180
181 /**
182 Returns value of the <b>SMTPHost</b> option.
183 */
184 LogString getSMTPHost() const;
185
186 /**
187 The <b>SMTPPort</b> option takes a string value which should be a
188 the port of the SMTP server that will send the e-mail message.
189 */
190 void setSMTPPort(int port);
191
192 /**
193 Returns value of the <b>SMTPHost</b> option.
194 */
195 int getSMTPPort() const;
196
197 /**
198 The <b>To</b> option takes a string value which should be a
199 comma separated list of e-mail address of the recipients.
200 */
201 void setTo(const LogString& to);
202
203 /**
204 The <b>Cc</b> option takes a string value which should be a
205 comma separated list of e-mail address of the cc'd recipients.
206 */
207 void setCc(const LogString& to);
208
209 /**
210 The <b>Bcc</b> option takes a string value which should be a
211 comma separated list of e-mail address of the bcc'd recipients.
212 */
213 void setBcc(const LogString& to);
214
215
216 /**
217 The <b>SMTPUsername</b> option takes a string value which should be a
218 the user name for the SMTP server.
219 */
220 void setSMTPUsername(const LogString& newVal);
221
222 /**
223 Returns value of the <b>SMTPUsername</b> option.
224 */
225 LogString getSMTPUsername() const;
226
227 /**
228 The <b>SMTPPassword</b> option takes a string value which should be a
229 the password for the SMTP server.
230 */
231 void setSMTPPassword(const LogString& newVal);
232
233 /**
234 Returns value of the <b>SMTPPassword</b> option.
235 */
236 LogString getSMTPPassword() const;
237
238 /**
239 Returns value of the <b>BufferSize</b> option.
240 */
241 inline int getBufferSize() const
242 { return bufferSize; }
243
244
245 /**
246 * Gets the current triggering evaluator.
247 * @return triggering evaluator.
248 */
249 log4cxx::spi::TriggeringEventEvaluatorPtr getEvaluator() const;
250
251 /**
252 * Sets the triggering evaluator.
253 * @param trigger triggering evaluator.
254 */
255 void setEvaluator(log4cxx::spi::TriggeringEventEvaluatorPtr& trigger);
256
257 /**
258 The <b>EvaluatorClass</b> option takes a string value
259 representing the name of the class implementing the
260 spi::TriggeringEventEvaluator interface. A corresponding object will
261 be instantiated and assigned as the triggering event evaluator
262 for the SMTPAppender.
263 */
264 void setEvaluatorClass(const LogString& value);
265
266 /**
267 The <b>LocationInfo</b> option is provided for compatibility with log4j
268 and has no effect in log4cxx.
269 */
270 void setLocationInfo(bool locationInfo);
271
272 /**
273 Returns value of the <b>LocationInfo</b> option.
274 */
275 bool getLocationInfo() const;
276 }; // class SMTPAppender
277
278 LOG4CXX_PTR_DEF(SMTPAppender);
279
280 } // namespace net
281} // namespace log4cxx
282
283#endif // _LOG4CXX_NET_SMTP_H
Note: See TracBrowser for help on using the repository browser.