#ifndef LOG_SPKA2JY7
|
#define LOG_SPKA2JY7
|
|
#include "macro.h"
|
#include <boost/log/trivial.hpp>
|
#include <string>
|
|
namespace ns_log
|
{
|
|
void GetTrace();
|
typedef boost::log::trivial::severity_level LogLevel;
|
inline std::string &MsgPrefix()
|
{
|
thread_local std::string prefix;
|
return prefix;
|
}
|
inline int MsgIndent(int offset)
|
{
|
thread_local int indent = 0;
|
indent += offset;
|
if (indent > 0) {
|
MsgPrefix() = std::string(indent, ' ');
|
} else {
|
MsgPrefix().clear();
|
}
|
return indent;
|
}
|
std::string TimeStamp();
|
std::string LogPrefix(LogLevel level);
|
void AddLogRaw(const std::string &file_ptn, bool flush = true, bool with_console = false);
|
void AddLog(const std::string &file_ptn, bool flush = true, bool with_console = false);
|
LogLevel ResetLogLevel(LogLevel level, bool log_this = true);
|
LogLevel GetLogLevel();
|
|
} // namespace ns_log
|
|
#define LOG_WITH_PREFIX(severity) BOOST_LOG_TRIVIAL(severity) << ns_log::LogPrefix(boost::log::trivial::severity)
|
|
#define LOG__TRACE() LOG_WITH_PREFIX(trace)
|
#define LOG__DEBUG() LOG_WITH_PREFIX(debug)
|
#define LOG__INFO() LOG_WITH_PREFIX(info)
|
#define LOG__WARNING() LOG_WITH_PREFIX(warning)
|
#define LOG__ERROR() LOG_WITH_PREFIX(error)
|
#define LOG__FATAL() LOG_WITH_PREFIX(fatal)
|
|
#ifndef LOG_TRACE
|
#define LOG_TRACE() LOG__TRACE()
|
#endif
|
|
#ifndef LOG_DEBUG
|
#define LOG_DEBUG() LOG__DEBUG()
|
#endif
|
|
#ifndef LOG_INFO
|
#define LOG_INFO() LOG__INFO()
|
#endif
|
|
#ifndef LOG_WARNING
|
#define LOG_WARNING() LOG__WARNING()
|
#endif
|
|
#ifndef LOG_ERROR
|
#define LOG_ERROR() LOG__ERROR()
|
#endif
|
|
#ifndef LOG_FATAL
|
#define LOG_FATAL() LOG__FATAL()
|
#endif
|
|
#define LOG_POS() LOG__DEBUG() << __FILE__ << " +" << __LINE__ << ": "
|
|
// usage:
|
// LOG__WARNING() << "warning msg ...";
|
// LOG__ERROR() << "error msg ...";
|
|
namespace ns_log
|
{
|
namespace impl
|
{
|
using namespace boost::log::trivial;
|
class FuncLog
|
{
|
const char *name_;
|
|
public:
|
FuncLog(const char *name) :
|
name_(name)
|
{
|
LOG__DEBUG() << ">>> " << name_;
|
if (GetLogLevel() <= debug) {
|
MsgIndent(2);
|
}
|
}
|
~FuncLog()
|
{
|
if (GetLogLevel() <= debug) {
|
MsgIndent(-2);
|
}
|
LOG__DEBUG() << "<// " << name_;
|
}
|
};
|
} // namespace impl
|
} // namespace ns_log
|
|
#if defined(__GNUG__)
|
#define LOG_FUNCTION ns_log::impl::FuncLog JOIN(log_func_, JOIN(__LINE__, _))(__PRETTY_FUNCTION__)
|
#else
|
#define LOG_FUNCTION ns_log::impl::FuncLog JOIN(log_func_, JOIN(__LINE__, _))(__FUNCTION__)
|
#endif
|
|
#endif // end of include guard: LOG_SPKA2JY7
|