blob: 8980207b05c100d57bbcb8a69e58b2db2a1e8936 [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.
4// It implements enough of the interfaces of the crow logging framework to work correctly
5// but deletes the ILogHandler interface, as usage of that would be counter to the g3
6// handler management, and would cause performance issues.
7
Ed Tanous5f34a9c2017-02-28 12:35:13 -08008#include <cstdio>
9#include <cstdlib>
10#include <ctime>
11#include <iostream>
12#include <sstream>
Ed Tanous99923322017-03-03 14:21:24 -080013#include <string>
Ed Tanous5f34a9c2017-02-28 12:35:13 -080014
15#include <g3log/g3log.hpp>
16#include <g3log/logworker.hpp>
17
Ed Tanous99923322017-03-03 14:21:24 -080018namespace crow {
19enum class LogLevel {
Ed Tanous5f34a9c2017-02-28 12:35:13 -080020#ifndef ERROR
Ed Tanous99923322017-03-03 14:21:24 -080021 DEBUG = 0,
22 INFO,
23 WARNING,
24 ERROR,
25 CRITICAL,
Ed Tanous5f34a9c2017-02-28 12:35:13 -080026#endif
27
Ed Tanous99923322017-03-03 14:21:24 -080028 Debug = 0,
29 Info,
30 Warning,
31 Error,
32 Critical,
33};
Ed Tanous5f34a9c2017-02-28 12:35:13 -080034
Ed Tanous99923322017-03-03 14:21:24 -080035class logger {
36 public:
Ed Tanous8041f312017-04-03 09:47:01 -070037 logger(std::string prefix, LogLevel level) {
Ed Tanous99923322017-03-03 14:21:24 -080038 // no op, let g3 handle th log levels
39 }
Ed Tanous5f34a9c2017-02-28 12:35:13 -080040
Ed Tanous99923322017-03-03 14:21:24 -080041 //
42 template <typename T>
43 logger& operator<<(T const& value) {
Ed Tanous99923322017-03-03 14:21:24 -080044 return *this;
45 }
Ed Tanous5f34a9c2017-02-28 12:35:13 -080046
Ed Tanous99923322017-03-03 14:21:24 -080047 //
Ed Tanous8041f312017-04-03 09:47:01 -070048 static void setLogLevel(LogLevel level) { }
Ed Tanous5f34a9c2017-02-28 12:35:13 -080049
Ed Tanous99923322017-03-03 14:21:24 -080050 static LogLevel get_current_log_level() { return get_log_level_ref(); }
Ed Tanous5f34a9c2017-02-28 12:35:13 -080051
Ed Tanous99923322017-03-03 14:21:24 -080052 private:
53 //
54 static LogLevel& get_log_level_ref() {
Ed Tanous8041f312017-04-03 09:47:01 -070055 static LogLevel current_level = LogLevel::DEBUG;
Ed Tanous99923322017-03-03 14:21:24 -080056 return current_level;
57 }
Ed Tanous5f34a9c2017-02-28 12:35:13 -080058
Ed Tanous99923322017-03-03 14:21:24 -080059 //
60 std::ostringstream stringstream_;
61 LogLevel level_;
62};
Ed Tanous5f34a9c2017-02-28 12:35:13 -080063}
64
Ed Tanous99923322017-03-03 14:21:24 -080065#define CROW_LOG_CRITICAL LOG(FATAL)
66#define CROW_LOG_ERROR LOG(WARNING)
67#define CROW_LOG_WARNING LOG(WARNING)
68#define CROW_LOG_INFO LOG(INFO)
69#define CROW_LOG_DEBUG LOG(DEBUG)
Ed Tanousc4771fb2017-03-13 13:39:49 -070070
71
72
73/*
74#define CROW_LOG_CRITICAL \
75 if (false) \
76 crow::logger("CRITICAL", crow::LogLevel::Critical)
77#define CROW_LOG_ERROR \
78 if (false) \
79 crow::logger("ERROR ", crow::LogLevel::Error)
80#define CROW_LOG_WARNING \
81 if (false) \
82 crow::logger("WARNING ", crow::LogLevel::Warning)
83#define CROW_LOG_INFO \
84 if (false) \
85 crow::logger("INFO ", crow::LogLevel::Info)
86#define CROW_LOG_DEBUG \
87 if (false) \
88 crow::logger("DEBUG ", crow::LogLevel::Debug)
89*/