MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
log_domain.h
1/* Copyright 2013 10gen Inc.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#pragma once
17
18#include <boost/scoped_ptr.hpp>
19#include <memory>
20#include <string>
21#include <vector>
22
23#include "mongo/base/disallow_copying.h"
24#include "mongo/logger/appender.h"
25#include "mongo/logger/log_severity.h"
26
27namespace mongo {
28namespace logger {
29
49template <typename E>
50class MONGO_CLIENT_API LogDomain {
51 MONGO_DISALLOW_COPYING(LogDomain);
52
53public:
54 typedef E Event;
56
62 friend class LogDomain;
63
64 public:
66
67 private:
68 explicit AppenderHandle(size_t index) : _index(index) {}
69
70 size_t _index;
71 };
72
73 // TODO(schwerin): Replace with unique_ptr in C++11.
74 typedef std::auto_ptr<EventAppender> AppenderAutoPtr;
75
76 LogDomain();
77 ~LogDomain();
78
86 Status append(const Event& event);
87
91 bool getAbortOnFailure() const {
92 return _abortOnFailure;
93 }
94
98 void setAbortOnFailure(bool abortOnFailure) {
99 _abortOnFailure = abortOnFailure;
100 }
101
102 //
103 // Configuration methods. Must be synchronized with each other and calls to "append" by the
104 // caller.
105 //
106
111 AppenderHandle attachAppender(AppenderAutoPtr appender);
112
118 AppenderAutoPtr detachAppender(AppenderHandle handle);
119
123 void clearAppenders();
124
125private:
126 typedef std::vector<EventAppender*> AppenderVector;
127
128 AppenderVector _appenders;
129 bool _abortOnFailure;
130};
131
132} // namespace logger
133} // namespace mongo
Status represents an error state or the absence thereof.
Definition status.h:50
Interface for sinks in a logging system.
Definition appender.h:31
Opaque handle returned by attachAppender(), which can be subsequently passed to detachAppender() to d...
Definition log_domain.h:61
Logging domain for events of type E.
Definition log_domain.h:50
bool getAbortOnFailure() const
Gets the state of the abortOnFailure flag.
Definition log_domain.h:91
void setAbortOnFailure(bool abortOnFailure)
Sets the state of the abortOnFailure flag.
Definition log_domain.h:98
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20