Deskflow 1.24.0.365
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 "LogLevel.h"
11
12#include <list>
13#include <mutex>
14
15#include <QString>
16
17#define CLOG (Log::getInstance())
18#define BYE "\nTry `%s --help' for more information."
19
20class ILogOutputter;
21class Thread;
22
24
30class Log
31{
32public:
33 explicit Log(bool singleton = true);
34 explicit Log(Log *src);
35 Log(Log const &) = delete;
36 Log(Log &&) = delete;
37 ~Log();
38
39 Log &operator=(Log const &) = delete;
40 Log &operator=(Log &&) = delete;
41
43
44
46
62 void insert(ILogOutputter *adoptedOutputter, bool alwaysAtHead = false);
63
65
70 void remove(ILogOutputter *orphaned);
71
73
78 void pop_front(bool alwaysAtHead = false);
79
81
88 bool setFilter(const QString &name);
89
91 void setFilter(LogLevel);
92
94
96
98
103 void print(const char *file, int line, const char *format, ...);
104
106 LogLevel getFilter() const;
107
109 const char *getFilterName() const;
110
112 const char *getFilterName(LogLevel level) const;
113
115 static Log *getInstance();
116
120 {
121 return LogLevel::Debug2;
122 }
123
125
126private:
127 void output(LogLevel priority, const char *msg);
128
129private:
130 using OutputterList = std::list<ILogOutputter *>;
131
132 static Log *s_log;
133
134 mutable std::mutex m_mutex;
135 OutputterList m_outputters;
136 OutputterList m_alwaysOutputters;
137 LogLevel m_maxPriority;
138};
139
158
178
179#if defined(NOLOGGING)
180#define LOG(_a1)
181#define LOGC(_a1, _a2)
182#define CLOG_TRACE
183#elif defined(NDEBUG)
184#define LOG(_a1) CLOG->print _a1
185#define LOGC(_a1, _a2) \
186 if (_a1) \
187 CLOG->print _a2
188#define CLOG_TRACE nullptr, 0,
189#else
190#define LOG(_a1) CLOG->print _a1
191#define LOGC(_a1, _a2) \
192 if (_a1) \
193 CLOG->print _a2
194#define CLOG_TRACE __FILE__, __LINE__,
195#endif
196
197// the CLOG_* defines are line and file plus %z and an octal number (060=0,
198// 071=9), but the limitation is that once we run out of numbers at either
199// end, then we resort to using non-numerical chars. this still works (since
200// to deduce the number we subtract octal \060, so '/' is -1, and ':' is 10
201
202#define CLOG_IPC CLOG_TRACE "%z\056" // char is '' ?
203#define CLOG_PRINT CLOG_TRACE "%z\057" // char is '/'
204#define CLOG_CRIT CLOG_TRACE "%z\060" // char is '0'
205#define CLOG_ERR CLOG_TRACE "%z\061"
206#define CLOG_WARN CLOG_TRACE "%z\062"
207#define CLOG_NOTE CLOG_TRACE "%z\063"
208#define CLOG_INFO CLOG_TRACE "%z\064"
209#define CLOG_DEBUG CLOG_TRACE "%z\065"
210#define CLOG_DEBUG1 CLOG_TRACE "%z\066"
211#define CLOG_DEBUG2 CLOG_TRACE "%z\067"
212#define CLOG_DEBUG3 CLOG_TRACE "%z\070"
213#define CLOG_DEBUG4 CLOG_TRACE "%z\071" // char is '9'
214#define CLOG_DEBUG5 CLOG_TRACE "%z\072" // char is ':'
215
216#define LOG_IPC(...) LOG((CLOG_IPC __VA_ARGS__))
217#define LOG_PRINT(...) LOG((CLOG_PRINT __VA_ARGS__))
218#define LOG_CRIT(...) LOG((CLOG_CRIT __VA_ARGS__))
219#define LOG_ERR(...) LOG((CLOG_ERR __VA_ARGS__))
220#define LOG_WARN(...) LOG((CLOG_WARN __VA_ARGS__))
221#define LOG_NOTE(...) LOG((CLOG_NOTE __VA_ARGS__))
222#define LOG_INFO(...) LOG((CLOG_INFO __VA_ARGS__))
223#define LOG_DEBUG(...) LOG((CLOG_DEBUG __VA_ARGS__))
224#define LOG_DEBUG1(...) LOG((CLOG_DEBUG1 __VA_ARGS__))
225#define LOG_DEBUG2(...) LOG((CLOG_DEBUG2 __VA_ARGS__))
226#define LOG_DEBUG3(...) LOG((CLOG_DEBUG3 __VA_ARGS__))
227#define LOG_DEBUG4(...) LOG((CLOG_DEBUG4 __VA_ARGS__))
228#define LOG_DEBUG5(...) LOG((CLOG_DEBUG5 __VA_ARGS__))
static const struct sockaddr FAR * name
Definition ArchNetworkWinsock.cpp:28
static int level
Definition ArchNetworkWinsock.cpp:31
LogLevel
Log levels.
Definition LogLevel.h:15
@ Debug2
For verbosity +2 debugging messages.
Definition LogLevel.h:25
Outputter interface.
Definition ILogOutputter.h:21
Logging facility.
Definition Log.h:31
~Log()
Definition Log.cpp:135
void print(const char *file, int line, const char *format,...)
Print a log message.
Definition Log.cpp:166
LogLevel getConsoleMaxLevel() const
Definition Log.h:119
LogLevel getFilter() const
Get the minimum priority level.
Definition Log.cpp:255
void insert(ILogOutputter *adoptedOutputter, bool alwaysAtHead=false)
Add an outputter to the head of the list and adopts it.
Definition Log.cpp:203
Log(Log &&)=delete
static Log * getInstance()
Get the singleton instance of the log.
Definition Log.cpp:146
Log & operator=(Log const &)=delete
Log & operator=(Log &&)=delete
Log(bool singleton=true)
Definition Log.cpp:115
void pop_front(bool alwaysAtHead=false)
Remove the outputter from the head of the list.
Definition Log.cpp:224
bool setFilter(const QString &name)
Set the minimum priority filter.
Definition Log.cpp:234
Log(Log const &)=delete
const char * getFilterName() const
Get the filter name of the current filter level.
Definition Log.cpp:152
void remove(ILogOutputter *orphaned)
Remove an outputter from the list.
Definition Log.cpp:217
Thread handle.
Definition Thread.h:33