Dekko
Loading...
Searching...
No Matches
Logger.qml
1/* Copyright (C) 2016 - 2017 Dan Chapman <dpniel@ubuntu.com>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18import QtQuick 2.4
19import QuickFlux 1.0
20import Dekko.Components 1.0
21import Dekko.Mail.API 1.0
22
23AppListener {
24 id: logListener
25 property bool devLoggingEnabled: true
26
27 Filter {
28 type: LogKeys.logInfo
29 onDispatched: {
30 if (verboseLogging) {
31 logMessage(message.location, "INFO", message.message)
32 }
33 }
34 }
35 Filter {
36 type: LogKeys.logStatus
37 onDispatched: {
38 if (verboseLogging) {
39 logMessage(message.location, "STATUS", message.message)
40 }
41 }
42 }
43 Filter {
44 type: LogKeys.logWarning
45 onDispatched: {
46 logMessage(message.location, "WARNING", message.message)
47 }
48 }
49 Filter {
50 type: LogKeys.logError
51 onDispatched: {
52 logMessage(message.location, "ERROR", message.message)
53 }
54 }
55
56 function logMessage(location, type, message) {
57 if (devLoggingEnabled) {
58 switch (type) {
59 case "INFO":
60 LogRecorder.logMessage(location, LogRecorder.INFO, message)
61 break
62 case "ERROR":
63 LogRecorder.logMessage(location, LogRecorder.ERROR, message)
64 break
65 case "WARNING":
66 LogRecorder.logMessage(location, LogRecorder.WARNING, message)
67 break
68 case "STATUS":
69 LogRecorder.logMessage(location, LogRecorder.STATUS, message)
70 break
71 }
72 }
73 console.log("[%1] [%2] %3".arg(location).arg(type).arg(message))
74 }
75}
76