forked from tickbh/VisualUIEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.js
More file actions
145 lines (130 loc) · 3.7 KB
/
console.js
File metadata and controls
145 lines (130 loc) · 3.7 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'use strict'
let Console = {}
module.exports = Console
// requires
var Util = require('util')
// ==========================
// exports
// ==========================
/**
* @method trace
* @param {string} level - Log level
* @param {...} [args] - whatever arguments the message needs
*
* Trace the log
*/
Console.trace = function(level, text, ...args) {
if (args.length) {
text = Util.format.apply(Util, [text, ...args])
} else {
text = '' + text
}
console.trace(text)
let e = new Error('dummy')
let lines = e.stack.split('\n')
lines.shift()
lines[0] = text
text = lines.join('\n')
Ipc.sendToMainDirect('ui:renderer-console-trace', level, text)
}
/**
* @method log
* @param {...*} [arg] - whatever arguments the message needs
*
* Log the normal message and show on the console.
* The method will send ipc message `ui:renderer-console-log` to the main process.
*/
Console.log = function(text, ...args) {
if (args.length) {
text = Util.format.apply(Util, arguments)
} else {
text = '' + text
}
console.log(text)
Ipc.sendToMainDirect('ui:renderer-console-log', text)
}
/**
* @method success
* @param {...*} [arg] - whatever arguments the message needs
*
* Log the success message and show on the console.
* The method will send ipc message `ui:renderer-console-success` to the main process.
*/
Console.success = function(text, ...args) {
if (args.length) {
text = Util.format.apply(Util, arguments)
} else {
text = '' + text
}
console.log('%c' + text, 'color: green')
Ipc.sendToMainDirect('ui:renderer-console-success', text)
}
/**
* @method failed
* @param {...*} [arg] - whatever arguments the message needs
*
* Log the failed message and show on the console.
* The method will send ipc message `ui:renderer-console-failed` to the main process.
*/
Console.failed = function(text, ...args) {
if (args.length) {
text = Util.format.apply(Util, arguments)
} else {
text = '' + text
}
console.log('%c' + text, 'color: red')
Ipc.sendToMainDirect('ui:renderer-console-failed', text)
}
/**
* @method info
* @param {...*} [arg] - whatever arguments the message needs
*
* Log the info message and show on the console.
* The method will send ipc message `ui:renderer-console-info` to the main process.
*/
Console.info = function(text, ...args) {
if (args.length) {
text = Util.format.apply(Util, arguments)
} else {
text = '' + text
}
console.info(text)
Ipc.sendToMainDirect('ui:renderer-console-info', text)
}
/**
* @method warn
* @param {...*} [arg] - whatever arguments the message needs
*
* Log the warn message and show on the console.
* The method will send ipc message `ui:renderer-console-warn` to the main process.
*/
Console.warn = function(text, ...args) {
if (args.length) {
text = Util.format.apply(Util, arguments)
} else {
text = '' + text
}
console.warn(text)
Ipc.sendToMainDirect('ui:renderer-console-warn', text)
}
/**
* @method error
* @param {...*} [arg] - whatever arguments the message needs
*
* Log the error message and show on the console.
* The method will send ipc message `ui:renderer-console-error` to the main process.
*/
Console.error = function(text, ...args) {
if (args.length) {
text = Util.format.apply(Util, arguments)
} else {
text = '' + text
}
console.error(text)
let e = new Error('dummy')
let lines = e.stack.split('\n')
lines.shift()
lines[0] = text
text = lines.join('\n')
Ipc.sendToMainDirect('ui:renderer-console-error', text)
}