Apache Log4cxx  Version 1.8.0
Loading...
Searching...
No Matches
loglog.h
Go to the documentation of this file.
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_HELPERS_LOG_LOG_H
19#define _LOG4CXX_HELPERS_LOG_LOG_H
20
21#include <log4cxx/logstring.h>
22#include <log4cxx/logger.h>
24#include <exception>
25#include <mutex>
26
27namespace LOG4CXX_NS
28{
29namespace helpers
30{
42class LOG4CXX_EXPORT LogLog
43{
44 private:
45 LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(LogLogPrivate, m_priv)
46
47 friend WideLife<LogLog>;
48 LogLog();
49 LogLog(const LogLog&);
50 LogLog& operator=(const LogLog&);
51 static LogLog& getInstance();
52
53 public:
55
59 static bool isDebugEnabled();
60
64 static bool isDebugEnabledFor(const LoggerPtr& category);
65
69 static bool isTraceEnabledFor(const LoggerPtr& category);
70
74 static void setInternalDebugging(bool newValue);
75
79 static bool isColorEnabled();
80
84 static void setColorEnabled(bool newValue);
85
89 static void debug(const LogString& msg);
93 static void debug(const LogString& msg, const std::exception& e);
94
95
99 static void error(const LogString& msg);
103 static void error(const LogString& msg, const std::exception& ex);
104
108 static void trace(const LoggerPtr& category, const LogString& msg);
109
110#if !LOG4CXX_LOGCHAR_IS_UTF8
114 static void trace(const LoggerPtr& category, const std::string& msg);
115#endif
124 static void setQuietMode(bool newValue);
125
129 static void warn(const LogString& msg);
133 static void warn(const LogString& msg, const std::exception& ex);
134
135 private:
136 static void emit_log(const LogString& prefix, const LogString& msg, const LogString& suffix);
137 static void emit_log(const LogString& prefix, const std::exception& ex, const LogString& suffix);
138};
139} // namespace helpers
140} // namespace log4cxx
141
142#if defined(LOGLOG_THRESHOLD) && LOGLOG_THRESHOLD <= 10000
159#define LOGLOG_DEBUG(logger, message) { \
160 if (LOG4CXX_NS::helpers::LogLog::isDebugEnabledFor(logger)) { \
161 LOG4CXX_NS::helpers::MessageBuffer buf; \
162 LOG4CXX_NS::helpers::LogLog::trace(logger, buf.str(buf << message)); } }
163#else // !defined(LOGLOG_THRESHOLD) || 10000 < LOGLOG_THRESHOLD
164#define LOGLOG_DEBUG(logger, message)
165#endif
166
167#if defined(LOGLOG_THRESHOLD) && LOGLOG_THRESHOLD <= 5000
183#define LOGLOG_TRACE(logger, message) { \
184 if (LOG4CXX_NS::helpers::LogLog::isTraceEnabledFor(logger)) { \
185 LOG4CXX_NS::helpers::MessageBuffer buf; \
186 LOG4CXX_NS::helpers::LogLog::trace(logger, buf.str(buf << message)); } }
187#else // !defined(LOGLOG_THRESHOLD) || 5000 < LOGLOG_THRESHOLD
188#define LOGLOG_TRACE(logger, message)
189#endif
190
195#define LOGLOG_WARN(message) { \
196 LOG4CXX_NS::helpers::MessageBuffer buf; \
197 LOG4CXX_NS::helpers::LogLog::warn(buf.str(buf << message)); }
198
203#define LOGLOG_ERROR(message) { \
204 LOG4CXX_NS::helpers::MessageBuffer buf; \
205 LOG4CXX_NS::helpers::LogLog::error(buf.str(buf << message)); }
206
207#endif //_LOG4CXX_HELPERS_LOG_LOG_H
static void error(const LogString &msg)
Output msg to SystemErrWriter unconditionally.
static void setInternalDebugging(bool newValue)
Start/stop outputing debug messages if newValue is true/false respectively.
static void debug(const LogString &msg, const std::exception &e)
Output msg and ex.what() to SystemErrWriter if internal debug logging is enabled.
static void error(const LogString &msg, const std::exception &ex)
Output msg and ex.what() to SystemErrWriter unconditionally.
static void setColorEnabled(bool newValue)
Start/stop coloring message text if newValue is true/false respectively.
static bool isTraceEnabledFor(const LoggerPtr &category)
Are category trace messages sent to SystemErrWriter?
static void warn(const LogString &msg, const std::exception &ex)
Output msg and ex.what() to SystemErrWriter unconditionally.
static void trace(const LoggerPtr &category, const std::string &msg)
Output msg to SystemErrWriter if internal debug logging is enabled.
static bool isDebugEnabled()
Are debug messages sent to SystemErrWriter?
static void trace(const LoggerPtr &category, const LogString &msg)
Output msg to SystemErrWriter if internal debug logging is enabled.
static void warn(const LogString &msg)
Output msg to SystemErrWriter unconditionally.
static bool isDebugEnabledFor(const LoggerPtr &category)
Are category debug messages sent to SystemErrWriter?
static void debug(const LogString &msg)
Output msg to SystemErrWriter if internal debug logging is enabled.
static bool isColorEnabled()
Are messages output in color?
static void setQuietMode(bool newValue)
Change quiet mode to newValue.
The WideLife wrapper is destined to prolongate the runtime logger state lifetime from static duration...
Definition widelife.h:37
std::basic_string< logchar > LogString
Definition logstring.h:60
std::shared_ptr< Logger > LoggerPtr
Definition defaultloggerfactory.h:27