blob: 748328e2efbe046a891101eb07e980af46a033ef [file] [log] [blame]
Ed Tanous5f34a9c2017-02-28 12:35:13 -08001#pragma once
2
3// This file overrides the default crow logging framework to use g3 instead.
Ed Tanous9140a672017-04-24 17:01:32 -07004// It implements enough of the interfaces of the crow logging framework to work
5// correctly
6// but deletes the ILogHandler interface, as usage of that would be counter to
7// the g3
Ed Tanous5f34a9c2017-02-28 12:35:13 -08008// handler management, and would cause performance issues.
9
Ed Tanous5f34a9c2017-02-28 12:35:13 -080010#include <cstdio>
11#include <cstdlib>
12#include <ctime>
13#include <iostream>
14#include <sstream>
Ed Tanous99923322017-03-03 14:21:24 -080015#include <string>
Ed Tanous5f34a9c2017-02-28 12:35:13 -080016
17#include <g3log/g3log.hpp>
18#include <g3log/logworker.hpp>
19
Ed Tanous99923322017-03-03 14:21:24 -080020namespace crow {
21enum class LogLevel {
Ed Tanous5f34a9c2017-02-28 12:35:13 -080022#ifndef ERROR
Ed Tanous99923322017-03-03 14:21:24 -080023 DEBUG = 0,
24 INFO,
25 WARNING,
26 ERROR,
27 CRITICAL,
Ed Tanous5f34a9c2017-02-28 12:35:13 -080028#endif
29
Ed Tanous99923322017-03-03 14:21:24 -080030 Debug = 0,
31 Info,
32 Warning,
33 Error,
34 Critical,
35};
Ed Tanous5f34a9c2017-02-28 12:35:13 -080036
Ed Tanous99923322017-03-03 14:21:24 -080037class logger {
38 public:
Ed Tanous8041f312017-04-03 09:47:01 -070039 logger(std::string prefix, LogLevel level) {
Ed Tanous99923322017-03-03 14:21:24 -080040 // no op, let g3 handle th log levels
41 }
Ed Tanous5f34a9c2017-02-28 12:35:13 -080042
Ed Tanous99923322017-03-03 14:21:24 -080043 //
44 template <typename T>
45 logger& operator<<(T const& value) {
Ed Tanous99923322017-03-03 14:21:24 -080046 return *this;
47 }
Ed Tanous5f34a9c2017-02-28 12:35:13 -080048
Ed Tanous99923322017-03-03 14:21:24 -080049 //
Ed Tanous9140a672017-04-24 17:01:32 -070050 static void setLogLevel(LogLevel level) {}
Ed Tanous5f34a9c2017-02-28 12:35:13 -080051
Ed Tanous99923322017-03-03 14:21:24 -080052 static LogLevel get_current_log_level() { return get_log_level_ref(); }
Ed Tanous5f34a9c2017-02-28 12:35:13 -080053
Ed Tanous99923322017-03-03 14:21:24 -080054 private:
55 //
56 static LogLevel& get_log_level_ref() {
Ed Tanous8041f312017-04-03 09:47:01 -070057 static LogLevel current_level = LogLevel::DEBUG;
Ed Tanous99923322017-03-03 14:21:24 -080058 return current_level;
59 }
Ed Tanous5f34a9c2017-02-28 12:35:13 -080060
Ed Tanous99923322017-03-03 14:21:24 -080061 //
62 std::ostringstream stringstream_;
63 LogLevel level_;
64};
Ed Tanous5f34a9c2017-02-28 12:35:13 -080065}
Ed Tanous9140a672017-04-24 17:01:32 -070066#ifndef CROW_DISABLE_LOGGING
67#define CROW_DISABLE_LOGGING false
68#endif
Ed Tanous5f34a9c2017-02-28 12:35:13 -080069
Ed Tanous9140a672017-04-24 17:01:32 -070070#define CROW_LOG_CRITICAL \
71 if (!CROW_DISABLE_LOGGING) LOG(FATAL)
72#define CROW_LOG_ERROR \
73 if (!CROW_DISABLE_LOGGING) LOG(WARNING)
74#define CROW_LOG_WARNING \
75 if (!CROW_DISABLE_LOGGING) LOG(WARNING)
76#define CROW_LOG_INFO \
77 if (!CROW_DISABLE_LOGGING) LOG(INFO)
78#define CROW_LOG_DEBUG \
79 if (!CROW_DISABLE_LOGGING) LOG(DEBUG)