forked from ethereum-mining/ethminer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Log.h
130 lines (108 loc) · 3.36 KB
/
Log.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
This file is part of ethminer.
ethminer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ethminer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ethminer. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file Log.h
* @author Gav Wood <[email protected]>
* @date 2014
*
* The logging subsystem.
*/
#pragma once
#include <chrono>
#include <ctime>
#include "Common.h"
#include "CommonData.h"
#include "FixedHash.h"
#include "Terminal.h"
#include "vector_ref.h"
/// The logging system's current verbosity.
#define LOG_JSON 1
#define LOG_PER_GPU 2
#define LOG_CONNECT 32
#define LOG_SWITCH 64
#define LOG_SUBMIT 128
#define LOG_PROGRAMFLOW 256
#define LOG_NEXT 512
#if DEV_BUILD
#define DEV_BUILD_LOG_PROGRAMFLOW(_S, _V) \
if (g_logOptions & LOG_PROGRAMFLOW) \
{ \
_S << _V; \
} \
((void)(0))
#else
#define DEV_BUILD_LOG_PROGRAMFLOW(_S, _V) ((void)(0))
#endif
extern unsigned g_logOptions;
extern bool g_logNoColor;
extern bool g_logSyslog;
extern bool g_logStdout;
namespace dev
{
/// A simple log-output function that prints log messages to stdout.
void simpleDebugOut(std::string const&);
/// Set the current thread's log name.
void setThreadName(char const* _n);
/// Set the current thread's log name.
std::string getThreadName();
/// The default logging channels. Each has an associated verbosity and three-letter prefix (name()
/// ). Channels should inherit from LogChannel and define name() and verbosity.
struct LogChannel
{
static const char* name();
};
struct WarnChannel : public LogChannel
{
static const char* name();
};
struct NoteChannel : public LogChannel
{
static const char* name();
};
class LogOutputStreamBase
{
public:
LogOutputStreamBase(char const* _id);
template <class T>
void append(T const& _t)
{
m_sstr << _t;
}
protected:
std::stringstream m_sstr; ///< The accrued log entry.
};
/// Logging class, iostream-like, that can be shifted to.
template <class Id>
class LogOutputStream : LogOutputStreamBase
{
public:
/// Construct a new object.
/// If _term is true the the prefix info is terminated with a ']' character; if not it ends only
/// with a '|' character.
LogOutputStream() : LogOutputStreamBase(Id::name()) {}
/// Destructor. Posts the accrued log entry to the g_logPost function.
~LogOutputStream() { simpleDebugOut(m_sstr.str()); }
/// Shift arbitrary data to the log. Spaces will be added between items as required.
template <class T>
LogOutputStream& operator<<(T const& _t)
{
append(_t);
return *this;
}
};
#define clog(X) dev::LogOutputStream<X>()
// Simple cout-like stream objects for accessing common log channels.
// Dirties the global namespace, but oh so convenient...
#define cnote clog(dev::NoteChannel)
#define cwarn clog(dev::WarnChannel)
} // namespace dev