blob: 91e2935d1b52a0523d8b3c36998ad92b155c985c [file] [log] [blame]
Ed Tanous5f34a9c2017-02-28 12:35:13 -08001#pragma once
2
Ed Tanousdc7b6792017-05-12 15:55:51 -07003/*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
5 correctly but deletes the ILogHandler interface, as usage of that would be
6 counter to the g3 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 Tanous9140a672017-04-24 17:01:32 -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}
Ed Tanous9140a672017-04-24 17:01:32 -070064#ifndef CROW_DISABLE_LOGGING
65#define CROW_DISABLE_LOGGING false
66#endif
Ed Tanous5f34a9c2017-02-28 12:35:13 -080067
Ed Tanous9140a672017-04-24 17:01:32 -070068#define CROW_LOG_CRITICAL \
69 if (!CROW_DISABLE_LOGGING) LOG(FATAL)
70#define CROW_LOG_ERROR \
71 if (!CROW_DISABLE_LOGGING) LOG(WARNING)
72#define CROW_LOG_WARNING \
73 if (!CROW_DISABLE_LOGGING) LOG(WARNING)
74#define CROW_LOG_INFO \
75 if (!CROW_DISABLE_LOGGING) LOG(INFO)
76#define CROW_LOG_DEBUG \
77 if (!CROW_DISABLE_LOGGING) LOG(DEBUG)