C++ Distributed Hash Table
log.h
1 /*
2  * Copyright (C) 2014-2022 Savoir-faire Linux Inc.
3  *
4  * Author: Adrien BĂ©raud <adrien.beraud@savoirfairelinux.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #pragma once
21 
22 #include "def.h"
23 #include "log_enable.h"
24 
25 #include <iostream>
26 #include <memory>
27 
28 namespace dht {
29 
30 class DhtRunner;
31 
35 namespace log {
36 
40 namespace Color {
41  enum Code {
42  FG_RED = 31,
43  FG_GREEN = 32,
44  FG_YELLOW = 33,
45  FG_BLUE = 34,
46  FG_DEFAULT = 39,
47  BG_RED = 41,
48  BG_GREEN = 42,
49  BG_BLUE = 44,
50  BG_DEFAULT = 49
51  };
52  class Modifier {
53  const Code code;
54  public:
55  constexpr Modifier(Code pCode) : code(pCode) {}
56  friend std::ostream&
57  operator<<(std::ostream& os, const Modifier& mod) {
58  return os << "\033[" << mod.code << 'm';
59  }
60  };
61 }
62 
63 constexpr const Color::Modifier def(Color::FG_DEFAULT);
64 constexpr const Color::Modifier red(Color::FG_RED);
65 constexpr const Color::Modifier yellow(Color::FG_YELLOW);
66 
70 OPENDHT_PUBLIC void
71 printLog(std::ostream &s, char const *m, va_list args);
72 
73 OPENDHT_PUBLIC
74 std::shared_ptr<Logger> getStdLogger();
75 
76 OPENDHT_PUBLIC
77 std::shared_ptr<Logger> getFileLogger(const std::string &path);
78 
79 OPENDHT_PUBLIC
80 std::shared_ptr<Logger> getSyslogLogger(const char* name);
81 
82 OPENDHT_PUBLIC void
83 enableLogging(dht::DhtRunner &dht);
84 
85 OPENDHT_PUBLIC void
86 enableFileLogging(dht::DhtRunner &dht, const std::string &path);
87 
88 OPENDHT_PUBLIC void
89 disableLogging(dht::DhtRunner &dht);
90 
91 OPENDHT_PUBLIC void
92 enableSyslog(dht::DhtRunner &dht, const char* name);
93 
94 } /* log */
95 } /* dht */
OPENDHT_PUBLIC void printLog(std::ostream &s, char const *m, va_list args)
Definition: callbacks.h:35