1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import * as env from './environment.js'
|
8 | import * as common from './logging.common.js'
|
9 |
|
10 | export { BOLD, UNBOLD, BLUE, GREY, GREEN, RED, PURPLE, ORANGE, UNCOLOR } from './logging.common.js'
|
11 |
|
12 | const _nodeStyleMap = {
|
13 | [common.BOLD]: '\u001b[1m',
|
14 | [common.UNBOLD]: '\u001b[2m',
|
15 | [common.BLUE]: '\x1b[34m',
|
16 | [common.GREEN]: '\x1b[32m',
|
17 | [common.GREY]: '\u001b[37m',
|
18 | [common.RED]: '\x1b[31m',
|
19 | [common.PURPLE]: '\x1b[35m',
|
20 | [common.ORANGE]: '\x1b[38;5;208m',
|
21 | [common.UNCOLOR]: '\x1b[0m'
|
22 | }
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | const computeNodeLoggingArgs = (args) => {
|
30 | const strBuilder = []
|
31 | const logArgs = []
|
32 |
|
33 | let i = 0
|
34 | for (; i < args.length; i++) {
|
35 | const arg = args[i]
|
36 |
|
37 | const style = _nodeStyleMap[arg]
|
38 | if (style !== undefined) {
|
39 | strBuilder.push(style)
|
40 | } else {
|
41 | if (arg.constructor === String || arg.constructor === Number) {
|
42 | strBuilder.push(arg)
|
43 | } else {
|
44 | break
|
45 | }
|
46 | }
|
47 | }
|
48 | if (i > 0) {
|
49 |
|
50 | strBuilder.push('\x1b[0m')
|
51 | logArgs.push(strBuilder.join(''))
|
52 | }
|
53 |
|
54 | for (; i < args.length; i++) {
|
55 | const arg = args[i]
|
56 | if (!(arg instanceof Symbol)) {
|
57 | logArgs.push(arg)
|
58 | }
|
59 | }
|
60 | return logArgs
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 | const computeLoggingArgs = env.supportsColor
|
66 | ? computeNodeLoggingArgs
|
67 | : common.computeNoColorLoggingArgs
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | export const print = (...args) => {
|
74 | console.log(...computeLoggingArgs(args))
|
75 | }
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | export const warn = (...args) => {
|
82 | console.warn(...computeLoggingArgs(args))
|
83 | }
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | export const printError = (err) => {
|
91 | console.error(err)
|
92 | }
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | export const printImg = (_url, _height) => {
|
101 |
|
102 | }
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | export const printImgBase64 = (base64, height) =>
|
111 | printImg(`data:image/gif;base64,${base64}`, height)
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | export const group = (...args) => {
|
118 | console.group(...computeLoggingArgs(args))
|
119 | }
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | export const groupCollapsed = (...args) => {
|
126 | console.groupCollapsed(...computeLoggingArgs(args))
|
127 | }
|
128 |
|
129 |
|
130 | export const groupEnd = () => {
|
131 | console.groupEnd()
|
132 | }
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | export const printDom = (_createNode) => {}
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | export const printCanvas = (canvas, height) =>
|
146 | printImg(canvas.toDataURL(), height)
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | export const createVConsole = (_dom) => {}
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 | export const createModuleLogger = (moduleName) => common.createModuleLogger(print, moduleName)
|