Deskflow 1.22.0.197
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
Log.h
Go to the documentation of this file.
1/*
2 * Deskflow -- mouse and keyboard sharing utility
3 * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
4 * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
5 * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
6 */
7
8#pragma once
9
10#include "arch/Arch.h"
12#include "common/Common.h"
13
14#include <mutex>
15
16#define CLOG (Log::getInstance())
17#define BYE "\nTry `%s --help' for more information."
18
19class ILogOutputter;
20class Thread;
21
23
29class Log
30{
31public:
32 explicit Log(bool singleton = true);
33 explicit Log(Log *src);
34 Log(Log const &) = delete;
35 Log(Log &&) = delete;
36 ~Log();
37
38 Log &operator=(Log const &) = delete;
39 Log &operator=(Log &&) = delete;
40
42
43
45
61 void insert(ILogOutputter *adoptedOutputter, bool alwaysAtHead = false);
62
64
69 void remove(ILogOutputter *orphaned);
70
72
77 void pop_front(bool alwaysAtHead = false);
78
80
87 bool setFilter(const char *name);
88
90 void setFilter(LogLevel);
91
93
95
97
102 void print(const char *file, int line, const char *format, ...);
103
105 LogLevel getFilter() const;
106
108 const char *getFilterName() const;
109
111 const char *getFilterName(LogLevel level) const;
112
114 static Log *getInstance();
115
119 {
120 return LogLevel::Debug2;
121 }
122
124
125private:
126 void output(LogLevel priority, const char *msg);
127
128private:
129 using OutputterList = std::list<ILogOutputter *>;
130
131 static Log *s_log;
132
133 mutable std::mutex m_mutex;
134 OutputterList m_outputters;
135 OutputterList m_alwaysOutputters;
136 LogLevel m_maxPriority;
137};
138
157
177
178#if defined(NOLOGGING)
179#define LOG(_a1)
180#define LOGC(_a1, _a2)
181#define CLOG_TRACE
182#elif defined(NDEBUG)
183#define LOG(_a1) CLOG->print _a1
184#define LOGC(_a1, _a2) \
185 if (_a1) \
186 CLOG->print _a2
187#define CLOG_TRACE nullptr, 0,
188#else
189#define LOG(_a1) CLOG->print _a1
190#define LOGC(_a1, _a2) \
191 if (_a1) \
192 CLOG->print _a2
193#define CLOG_TRACE __FILE__, __LINE__,
194#endif
195
196// the CLOG_* defines are line and file plus %z and an octal number (060=0,
197// 071=9), but the limitation is that once we run out of numbers at either
198// end, then we resort to using non-numerical chars. this still works (since
199// to deduce the number we subtract octal \060, so '/' is -1, and ':' is 10
200
201#define CLOG_PRINT CLOG_TRACE "%z\057" // char is '/'
202#define CLOG_CRIT CLOG_TRACE "%z\060" // char is '0'
203#define CLOG_ERR CLOG_TRACE "%z\061"
204#define CLOG_WARN CLOG_TRACE "%z\062"
205#define CLOG_NOTE CLOG_TRACE "%z\063"
206#define CLOG_INFO CLOG_TRACE "%z\064"
207#define CLOG_DEBUG CLOG_TRACE "%z\065"
208#define CLOG_DEBUG1 CLOG_TRACE "%z\066"
209#define CLOG_DEBUG2 CLOG_TRACE "%z\067"
210#define CLOG_DEBUG3 CLOG_TRACE "%z\070"
211#define CLOG_DEBUG4 CLOG_TRACE "%z\071" // char is '9'
212#define CLOG_DEBUG5 CLOG_TRACE "%z\072" // char is ':'
213
214#define LOG_PRINT(...) LOG((CLOG_PRINT __VA_ARGS__))
215#define LOG_CRIT(...) LOG((CLOG_CRIT __VA_ARGS__))
216#define LOG_ERR(...) LOG((CLOG_ERR __VA_ARGS__))
217#define LOG_WARN(...) LOG((CLOG_WARN __VA_ARGS__))
218#define LOG_NOTE(...) LOG((CLOG_NOTE __VA_ARGS__))
219#define LOG_INFO(...) LOG((CLOG_INFO __VA_ARGS__))
220#define LOG_DEBUG(...) LOG((CLOG_DEBUG __VA_ARGS__))
221#define LOG_DEBUG1(...) LOG((CLOG_DEBUG1 __VA_ARGS__))
222#define LOG_DEBUG2(...) LOG((CLOG_DEBUG2 __VA_ARGS__))
223#define LOG_DEBUG3(...) LOG((CLOG_DEBUG3 __VA_ARGS__))
224#define LOG_DEBUG4(...) LOG((CLOG_DEBUG4 __VA_ARGS__))
225#define LOG_DEBUG5(...) LOG((CLOG_DEBUG5 __VA_ARGS__))
static const struct sockaddr FAR * name
Definition ArchNetworkWinsock.cpp:27
static int level
Definition ArchNetworkWinsock.cpp:30
LogLevel
Log levels.
Definition LogLevel.h:15
@ Debug2
For verbosity +2 debugging messages.
Definition LogLevel.h:24
Outputter interface.
Definition ILogOutputter.h:21
Logging facility.
Definition Log.h:30
~Log()
Definition Log.cpp:142
bool setFilter(const char *name)
Set the minimum priority filter.
Definition Log.cpp:241
void print(const char *file, int line, const char *format,...)
Print a log message.
Definition Log.cpp:173
LogLevel getConsoleMaxLevel() const
Definition Log.h:118
LogLevel getFilter() const
Get the minimum priority level.
Definition Log.cpp:261
void insert(ILogOutputter *adoptedOutputter, bool alwaysAtHead=false)
Add an outputter to the head of the list and adopts it.
Definition Log.cpp:210
Log(Log &&)=delete
static Log * getInstance()
Get the singleton instance of the log.
Definition Log.cpp:153
Log & operator=(Log const &)=delete
Log & operator=(Log &&)=delete
Log(bool singleton=true)
Definition Log.cpp:122
void pop_front(bool alwaysAtHead=false)
Remove the outputter from the head of the list.
Definition Log.cpp:231
Log(Log const &)=delete
const char * getFilterName() const
Get the filter name of the current filter level.
Definition Log.cpp:159
void remove(ILogOutputter *orphaned)
Remove an outputter from the list.
Definition Log.cpp:224
Thread handle.
Definition Thread.h:33