My Project 2.4.4
C++ Distributed Hash Table
Loading...
Searching...
No Matches
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
28namespace dht {
29
30class DhtRunner;
31
35namespace log {
36
40namespace 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
63constexpr const Color::Modifier def(Color::FG_DEFAULT);
64constexpr const Color::Modifier red(Color::FG_RED);
65constexpr const Color::Modifier yellow(Color::FG_YELLOW);
66
70OPENDHT_PUBLIC void
71printLog(std::ostream &s, char const *m, va_list args);
72
73OPENDHT_PUBLIC
74std::shared_ptr<Logger> getStdLogger();
75
76OPENDHT_PUBLIC
77std::shared_ptr<Logger> getFileLogger(const std::string &path);
78
79OPENDHT_PUBLIC
80std::shared_ptr<Logger> getSyslogLogger(const char* name);
81
82OPENDHT_PUBLIC void
83enableLogging(dht::DhtRunner &dht);
84
85OPENDHT_PUBLIC void
86enableFileLogging(dht::DhtRunner &dht, const std::string &path);
87
88OPENDHT_PUBLIC void
89disableLogging(dht::DhtRunner &dht);
90
91OPENDHT_PUBLIC void
92enableSyslog(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