summaryrefslogtreecommitdiffstats
path: root/common/log.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/log.h')
-rw-r--r--common/log.h75
1 files changed, 66 insertions, 9 deletions
diff --git a/common/log.h b/common/log.h
index 483f16f..415c7f7 100644
--- a/common/log.h
+++ b/common/log.h
@@ -1,5 +1,6 @@
1#pragma once 1#pragma once
2 2
3#include "sink_export.h"
3#include <QDebug> 4#include <QDebug>
4 5
5namespace Sink { 6namespace Sink {
@@ -12,19 +13,75 @@ enum DebugLevel {
12 Error 13 Error
13}; 14};
14 15
15QByteArray debugLevelName(DebugLevel debugLevel); 16QByteArray SINK_EXPORT debugLevelName(DebugLevel debugLevel);
16DebugLevel debugLevelFromName(const QByteArray &name); 17DebugLevel SINK_EXPORT debugLevelFromName(const QByteArray &name);
17 18
18void setDebugOutputLevel(DebugLevel); 19/**
19DebugLevel debugOutputLevel(); 20 * Sets the debug output level.
21 *
22 * Everything below is ignored.
23 */
24void SINK_EXPORT setDebugOutputLevel(DebugLevel);
25DebugLevel SINK_EXPORT debugOutputLevel();
20 26
21QDebug debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea = 0); 27enum FilterType {
28 Area,
29 ApplicationName
30};
31
32/**
33 * Sets a debug output filter.
34 *
35 * Everything that is not matching the filter is ignored.
36 * An empty filter matches everything.
37 *
38 * Note: In case of resources the application name is the identifier.
39 */
40void SINK_EXPORT setDebugOutputFilter(FilterType, const QByteArrayList &filter);
41QByteArrayList SINK_EXPORT debugOutputFilter(FilterType type);
42
43/**
44 * Set the debug output fields.
45 *
46 * Currently supported are:
47 * * Name: Application name used for filter.
48 * * Function: The function name:
49 * * Location: The source code location.
50 *
51 * These are additional items to the default ones (level, area, message).
52 */
53void SINK_EXPORT setDebugOutputFields(const QByteArrayList &filter);
54QByteArrayList SINK_EXPORT debugOutputFields();
55
56QDebug SINK_EXPORT debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea = 0);
57
58struct SINK_EXPORT TraceTime
59{
60 TraceTime(int i) : time(i){};
61 const int time;
62};
63
64inline QDebug SINK_EXPORT operator<<(QDebug d, const TraceTime &time)
65{
66 d << time.time << "[ms]";
67 return d;
68}
22 69
23} 70}
24} 71}
25 72
26#define Trace() Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO) 73#define DEBUG_AREA nullptr
27#define Log() Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO) 74
28#define Warning() Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO) 75#define Trace_() Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO)
76#define Log_() Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO)
77
78#define Trace_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, AREA)
79#define Log_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, AREA)
80#define Warning_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, AREA)
81#define Error_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, AREA)
82
83#define Trace() Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, DEBUG_AREA)
84#define Log() Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, DEBUG_AREA)
85#define Warning() Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, DEBUG_AREA)
29//FIXME Error clashes with Storage::Error and MessageQueue::Error 86//FIXME Error clashes with Storage::Error and MessageQueue::Error
30#define ErrorMsg() Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO) 87#define ErrorMsg() Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, DEBUG_AREA)