-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
executable file
·69 lines (59 loc) · 1.46 KB
/
demo.js
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
#!/usr/bin/env node
/**
* Demo script for [hiplog]
* ========================
*
* Usage:
*
* ```sh
* LOG=debug ./demo.js
* LOG=debug LOG_TIME=true ./demo.js
* ```
*
* [hiplog]: https://www.npmjs.com/package/hiplog
*/
const { fromEnv } = require('.'); // eslint-disable-line import/no-unresolved
const log = fromEnv();
process.stdout.write('\n');
// Log levels
log.debug('messages to debug an application');
log.info('a purely informational message');
log.notice('a normal but significant condition');
log.warning('warning condition');
log.error('error condition');
log.critical('the system is in critical condition');
log.alert('action must be taken immediately');
log.emergency('system is unusable');
process.stdout.write('\n');
// Values
[
['boolean:', true, false],
['null:', null],
['undefined:', undefined],
['number:', 1, 2, 3],
['regexp:', /foo/],
['array:', ['foo', 'bar']],
['object:', { foo: 'bar' }],
].forEach(parts => log.info(...parts));
process.stdout.write('\n');
// Objects
log.info('a small object:', { int: 123, bool: true, str: 'Hello' });
process.stdout.write('\n');
const circular = {};
circular.inner = circular;
log.info('a bigger object', {
null: null,
undefined,
integer: 123,
boolean: true,
string: 'Hello',
funtion: function myFunction() {}, // eslint-disable-line require-jsdoc
circular,
array: ['one', 'two', 'three', 'four'],
});
// Error
try {
throw new Error('Error example');
} catch (e) {
log.error(e);
}