27 #if defined(MONGO_UTIL_LOG_H_)
29 "mongo/util/log.h cannot be included multiple times. " \
30 "This may occur when log.h is included in a header. " \
31 "Please check your #include's."
32 #else // MONGO_UTIL_LOG_H_
33 #define MONGO_UTIL_LOG_H_
35 #include "mongo/base/status.h"
36 #include "mongo/bson/util/builder.h"
37 #include "mongo/logger/log_component.h"
38 #include "mongo/logger/logger.h"
39 #include "mongo/logger/logstream_builder.h"
40 #include "mongo/logger/tee.h"
44 #if defined(MONGO_LOG_DEFAULT_COMPONENT)
45 const ::mongo::logger::LogComponent MongoLogDefaultComponent_component =
46 MONGO_LOG_DEFAULT_COMPONENT;
49 "mongo/util/log.h requires MONGO_LOG_DEFAULT_COMPONENT to be defined. " \
50 "Please see http://www.mongodb.org/about/contributors/reference/server-logging-rules/ "
51 #endif // MONGO_LOG_DEFAULT_COMPONENT
56 typedef void (*ExtraLogContextFn)(BufBuilder& builder);
57 Status registerExtraLogContextFn(ExtraLogContextFn contextFn);
63 using logger::LogstreamBuilder;
64 using logger::LabeledLevel;
70 inline LogstreamBuilder severe() {
71 return LogstreamBuilder(logger::globalLogDomain(),
73 logger::LogSeverity::Severe(),
74 ::MongoLogDefaultComponent_component);
77 inline LogstreamBuilder severe(logger::LogComponent component) {
78 return LogstreamBuilder(
79 logger::globalLogDomain(), std::string(), logger::LogSeverity::Severe(), component);
85 inline LogstreamBuilder error() {
86 return LogstreamBuilder(logger::globalLogDomain(),
88 logger::LogSeverity::Error(),
89 ::MongoLogDefaultComponent_component);
92 inline LogstreamBuilder error(logger::LogComponent component) {
93 return LogstreamBuilder(
94 logger::globalLogDomain(), std::string(), logger::LogSeverity::Error(), component);
100 inline LogstreamBuilder warning() {
101 return LogstreamBuilder(logger::globalLogDomain(),
103 logger::LogSeverity::Warning(),
104 ::MongoLogDefaultComponent_component);
107 inline LogstreamBuilder warning(logger::LogComponent component) {
108 return LogstreamBuilder(
109 logger::globalLogDomain(), std::string(), logger::LogSeverity::Warning(), component);
115 inline LogstreamBuilder log() {
116 return LogstreamBuilder(logger::globalLogDomain(),
118 logger::LogSeverity::Log(),
119 ::MongoLogDefaultComponent_component);
122 inline LogstreamBuilder log(logger::LogComponent component) {
123 return LogstreamBuilder(
124 logger::globalLogDomain(), std::string(), logger::LogSeverity::Log(), component);
127 inline LogstreamBuilder log(logger::LogComponent::Value componentValue) {
128 return LogstreamBuilder(
129 logger::globalLogDomain(), std::string(), logger::LogSeverity::Log(), componentValue);
135 inline bool shouldLog(logger::LogSeverity severity) {
136 return logger::globalLogDomain()->shouldLog(::MongoLogDefaultComponent_component, severity);
142 #define MONGO_LOG(DLEVEL) \
143 if (!(::mongo::logger::globalLogDomain()) \
144 ->shouldLog(MongoLogDefaultComponent_component, \
145 ::mongo::LogstreamBuilder::severityCast(DLEVEL))) { \
147 ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
149 ::mongo::LogstreamBuilder::severityCast(DLEVEL), \
150 MongoLogDefaultComponent_component)
152 #define LOG MONGO_LOG
154 #define MONGO_LOG_COMPONENT(DLEVEL, COMPONENT1) \
155 if (!(::mongo::logger::globalLogDomain()) \
156 ->shouldLog((COMPONENT1), ::mongo::LogstreamBuilder::severityCast(DLEVEL))) { \
158 ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
160 ::mongo::LogstreamBuilder::severityCast(DLEVEL), \
163 #define MONGO_LOG_COMPONENT2(DLEVEL, COMPONENT1, COMPONENT2) \
164 if (!(::mongo::logger::globalLogDomain()) \
166 (COMPONENT1), (COMPONENT2), ::mongo::LogstreamBuilder::severityCast(DLEVEL))) { \
168 ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
170 ::mongo::LogstreamBuilder::severityCast(DLEVEL), \
173 #define MONGO_LOG_COMPONENT3(DLEVEL, COMPONENT1, COMPONENT2, COMPONENT3) \
174 if (!(::mongo::logger::globalLogDomain()) \
175 ->shouldLog((COMPONENT1), \
178 ::mongo::LogstreamBuilder::severityCast(DLEVEL))) { \
180 ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
182 ::mongo::LogstreamBuilder::severityCast(DLEVEL), \
191 std::string errnoWithDescription(
int errorcode = -1);
200 #endif // MONGO_UTIL_LOG_H_
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
std::string errnoWithPrefix(const char *prefix)
output the error # and error message with prefix.
void logContext(const char *msg=NULL)
Write the optional "msg".
MONGO_CLIENT_API Status(MONGO_CLIENT_FUNC *saslClientAuthenticate)(DBClientWithCommands *client
Attempts to authenticate "client" using the SASL protocol.