C++ Distributed Hash Table
log.h
1 /*
2  * Copyright (C) 2014-2017 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 "dhtrunner.h"
23 
24 #include <iostream>
25 
26 namespace dht {
27 
31 namespace log {
32 
36 namespace Color {
37  enum Code {
38  FG_RED = 31,
39  FG_GREEN = 32,
40  FG_YELLOW = 33,
41  FG_BLUE = 34,
42  FG_DEFAULT = 39,
43  BG_RED = 41,
44  BG_GREEN = 42,
45  BG_BLUE = 44,
46  BG_DEFAULT = 49
47  };
48  class Modifier {
49  const Code code;
50  public:
51  constexpr Modifier(Code pCode) : code(pCode) {}
52  friend std::ostream&
53  operator<<(std::ostream& os, const Modifier& mod) {
54  return os << "\033[" << mod.code << 'm';
55  }
56  };
57 }
58 
59 constexpr const Color::Modifier def(Color::FG_DEFAULT);
60 constexpr const Color::Modifier red(Color::FG_RED);
61 constexpr const Color::Modifier yellow(Color::FG_YELLOW);
62 
66 OPENDHT_PUBLIC void
67 printLog(std::ostream &s, char const *m, va_list args);
68 
69 OPENDHT_PUBLIC void
70 enableLogging(dht::DhtRunner &dht);
71 
72 OPENDHT_PUBLIC void
73 enableFileLogging(dht::DhtRunner &dht, const std::string &path);
74 
75 OPENDHT_PUBLIC void
76 disableLogging(dht::DhtRunner &dht);
77 
78 OPENDHT_PUBLIC void
79 enableSyslog(dht::DhtRunner &dht, const char* name);
80 
81 } /* log */
82 } /* dht */
OPENDHT_PUBLIC void printLog(std::ostream &s, char const *m, va_list args)
Definition: callbacks.h:34