1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/*
*
* Copyright (c) 2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "SinkOptions.h"
#include "qpid/log/SinkOptions.h"
#include "qpid/log/Logger.h"
#include "qpid/log/OstreamOutput.h"
#include "qpid/memory.h"
#include "qpid/Exception.h"
#include <iostream>
#include <map>
#include <string>
using std::string;
using qpid::Exception;
namespace qpid {
namespace log {
namespace windows {
class EventLogOutput : public qpid::log::Logger::Output {
public:
EventLogOutput(const std::string& logName)
{
}
virtual ~EventLogOutput() {
}
virtual void log(const Statement& s, const std::string& m)
{
}
private:
};
SinkOptions::SinkOptions(const std::string& argv0)
: qpid::log::SinkOptions(),
logToStderr(true),
logToStdout(false),
logToEventLog(false)
{
addOptions()
("log-to-stderr", optValue(logToStderr, "yes|no"), "Send logging output to stderr")
("log-to-stdout", optValue(logToStdout, "yes|no"), "Send logging output to stdout")
("log-to-file", optValue(logFile, "FILE"), "Send log output to FILE.")
("log-to-eventlog", optValue(logToEventLog, "yes|no"), "Send logging output to event log;\n\tcustomize using --syslog-name and --syslog-facility")
("syslog-name", optValue(syslogName, "NAME"), "Name to use in syslog messages")
("syslog-facility", optValue(syslogFacility,"LOG_XXX"), "Facility to use in syslog messages")
;
}
qpid::log::SinkOptions& SinkOptions::operator=(const qpid::log::SinkOptions& rhs) {
const SinkOptions *prhs = dynamic_cast<const SinkOptions*>(&rhs);
if (this != prhs) {
logToStderr = prhs->logToStderr;
logToStdout = prhs->logToStdout;
logToEventLog = prhs->logToEventLog;
logFile = prhs->logFile;
syslogName = prhs->syslogName;
syslogFacility.value = prhs->syslogFacility.value;
}
return *this;
}
void SinkOptions::detached(void) {
if (logToStderr && !logToStdout && !logToEventLog) {
logToStderr = false;
logToEventLog = true;
}
}
// The Logger acting on these options calls setup() to request any
// Sinks be set up and fed back to the logger.
void SinkOptions::setup(qpid::log::Logger *logger) {
if (logToStderr)
logger->output(make_auto_ptr<qpid::log::Logger::Output>
(new qpid::log::OstreamOutput(std::clog)));
if (logToStdout)
logger->output(make_auto_ptr<qpid::log::Logger::Output>
(new qpid::log::OstreamOutput(std::cout)));
if (logFile.length() > 0)
logger->output(make_auto_ptr<qpid::log::Logger::Output>
(new qpid::log::OstreamOutput(logFile)));
if (logToEventLog)
logger->output(make_auto_ptr<qpid::log::Logger::Output>
(new EventLogOutput(syslogName, syslogFacility)));
}
} // namespace windows
SinkOptions* SinkOptions::create(const std::string& argv0) {
return new qpid::log::windows::SinkOptions (argv0);
}
}} // namespace qpid::log
|