blob: 748328e2efbe046a891101eb07e980af46a033ef [file] [log] [blame]
#pragma once
// This file overrides the default crow logging framework to use g3 instead.
// It implements enough of the interfaces of the crow logging framework to work
// correctly
// but deletes the ILogHandler interface, as usage of that would be counter to
// the g3
// handler management, and would cause performance issues.
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <g3log/g3log.hpp>
#include <g3log/logworker.hpp>
namespace crow {
enum class LogLevel {
#ifndef ERROR
DEBUG = 0,
INFO,
WARNING,
ERROR,
CRITICAL,
#endif
Debug = 0,
Info,
Warning,
Error,
Critical,
};
class logger {
public:
logger(std::string prefix, LogLevel level) {
// no op, let g3 handle th log levels
}
//
template <typename T>
logger& operator<<(T const& value) {
return *this;
}
//
static void setLogLevel(LogLevel level) {}
static LogLevel get_current_log_level() { return get_log_level_ref(); }
private:
//
static LogLevel& get_log_level_ref() {
static LogLevel current_level = LogLevel::DEBUG;
return current_level;
}
//
std::ostringstream stringstream_;
LogLevel level_;
};
}
#ifndef CROW_DISABLE_LOGGING
#define CROW_DISABLE_LOGGING false
#endif
#define CROW_LOG_CRITICAL \
if (!CROW_DISABLE_LOGGING) LOG(FATAL)
#define CROW_LOG_ERROR \
if (!CROW_DISABLE_LOGGING) LOG(WARNING)
#define CROW_LOG_WARNING \
if (!CROW_DISABLE_LOGGING) LOG(WARNING)
#define CROW_LOG_INFO \
if (!CROW_DISABLE_LOGGING) LOG(INFO)
#define CROW_LOG_DEBUG \
if (!CROW_DISABLE_LOGGING) LOG(DEBUG)