forked from cordjs/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsole.coffee
80 lines (54 loc) · 1.94 KB
/
Console.coffee
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
define [
'postal'
], (postal) ->
class Console
###
Обертка для консоли, служит для того, чтобы включать/выключать вывод в конфиге
###
@getConfig: ->
@config = global.config if @config == undefined
@config
@stringify: (args) ->
result = ''
for arg in args
if arg instanceof Object
try
# TypeError: Converting circular structure to JSON
result += JSON.stringify(arg) + ', '
result += JSON.stringify(arg[3].stack) if arg[3] != undefined and arg[3].stack != ''
catch
result += arg + ', '
else
result += arg + ', '
return result
@log: ->
config = @getConfig()
console.log.apply console, arguments if config?.console.log or not config
postal?.publish 'log', JSON.stringify(arguments)
return
@warn: ->
config = @getConfig()
console.warn.apply console, arguments if config?.console.warn or not config
message = Console.stringify arguments
postal.publish 'logger.log.publish', { tags: ['warning'], params: {warning: message} }
postal?.publish 'log', JSON.stringify(arguments)
return
@error: ->
Console.taggedError ['error'], arguments
args =
try
JSON.stringify(arguments)
catch
# TypeError: Converting circular structure to JSON
arguments
postal?.publish 'log', args
@taggedError: (tags, args...) ->
config = @getConfig()
console.error.apply console, arguments if config?.console.error or not config
message = Console.stringify args
postal.publish 'error.notify.publish', { message: 'Произошла ошибка', link: '', details: message }
postal.publish 'logger.log.publish', { tags: tags, params: {error: message} }
return
@clear: ->
console.clear?()
return