-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
62 lines (55 loc) · 1.59 KB
/
index.ts
File metadata and controls
62 lines (55 loc) · 1.59 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
import { randomInt } from 'node:crypto';
import { styleText } from 'node:util';
import { createConsole } from 'styled-json-console';
import { mergeStyleOptions } from 'styled-json-console/mergeStyleOptions';
const myConsole = createConsole({
inspectOptions: {
depth: null,
colors: true,
numericSeparator: true,
showHidden: true,
showProxy: true,
},
eol: '\n\n',
// First entry is for stdout, second for stderr
json: [
{
space: 0,
style: {
bracket: ['white'],
quoteKey: ['cyan'],
quoteString: ['green'],
key: ['cyan'],
string: ['green'],
number: ['yellowBright'],
boolean: ['blueBright'],
null: ['redBright'],
},
replacer(key, value) {
if (key === 'level' && value === 'ERROR') {
return styleText(['bold', 'red'], value);
}
return value;
},
},
// stderr settings are merged with stdout settings so you can override only what you want
{
space: 2,
style: mergeStyleOptions(['whiteBright'], {
number: ['magentaBright'],
}),
},
],
});
const data = {
level: 'INFO',
message: 'This is an info message',
randomNumber: randomInt(0, 2 ** 32 - 1),
example: true,
json: JSON.stringify({ a: 1, b: [2], c: { d: 3, e: [4, 5] } }),
nested: { a: 1, b: [2], c: { d: 3, e: [4, 5] } },
};
myConsole.info(JSON.stringify(data));
myConsole.error(JSON.stringify({ ...data, level: 'ERROR', message: 'This is an error message' }));
// Non JSON data does not get styled, but still respects inspectOptions
myConsole.dir(data);