Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | // This file overrides the default crow logging framework to use g3 instead. |
Ed Tanous | 9140a67 | 2017-04-24 17:01:32 -0700 | [diff] [blame^] | 4 | // 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 Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 8 | // handler management, and would cause performance issues. |
| 9 | |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 10 | #include <cstdio> |
| 11 | #include <cstdlib> |
| 12 | #include <ctime> |
| 13 | #include <iostream> |
| 14 | #include <sstream> |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 15 | #include <string> |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 16 | |
| 17 | #include <g3log/g3log.hpp> |
| 18 | #include <g3log/logworker.hpp> |
| 19 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 20 | namespace crow { |
| 21 | enum class LogLevel { |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 22 | #ifndef ERROR |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 23 | DEBUG = 0, |
| 24 | INFO, |
| 25 | WARNING, |
| 26 | ERROR, |
| 27 | CRITICAL, |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 28 | #endif |
| 29 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 30 | Debug = 0, |
| 31 | Info, |
| 32 | Warning, |
| 33 | Error, |
| 34 | Critical, |
| 35 | }; |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 36 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 37 | class logger { |
| 38 | public: |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 39 | logger(std::string prefix, LogLevel level) { |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 40 | // no op, let g3 handle th log levels |
| 41 | } |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 42 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 43 | // |
| 44 | template <typename T> |
| 45 | logger& operator<<(T const& value) { |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 46 | return *this; |
| 47 | } |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 48 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 49 | // |
Ed Tanous | 9140a67 | 2017-04-24 17:01:32 -0700 | [diff] [blame^] | 50 | static void setLogLevel(LogLevel level) {} |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 51 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 52 | static LogLevel get_current_log_level() { return get_log_level_ref(); } |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 53 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 54 | private: |
| 55 | // |
| 56 | static LogLevel& get_log_level_ref() { |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 57 | static LogLevel current_level = LogLevel::DEBUG; |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 58 | return current_level; |
| 59 | } |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 60 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 61 | // |
| 62 | std::ostringstream stringstream_; |
| 63 | LogLevel level_; |
| 64 | }; |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 65 | } |
Ed Tanous | 9140a67 | 2017-04-24 17:01:32 -0700 | [diff] [blame^] | 66 | #ifndef CROW_DISABLE_LOGGING |
| 67 | #define CROW_DISABLE_LOGGING false |
| 68 | #endif |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 69 | |
Ed Tanous | 9140a67 | 2017-04-24 17:01:32 -0700 | [diff] [blame^] | 70 | #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) |