hermodlog 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/Logger.spec.js +23 -23
package/package.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "hermodlog",
|
3
|
-
"version": "1.8.
|
3
|
+
"version": "1.8.1",
|
4
4
|
"description": "Simple contextual logger to simplify log display in heavy load context and provide easy parsing",
|
5
5
|
"main": "src/Logger.js",
|
6
6
|
"type": "module",
|
7
7
|
"scripts": {
|
8
|
-
"test": "
|
8
|
+
"test": "litest .",
|
9
9
|
"test:dev": "vitest --dir . --watch"
|
10
10
|
},
|
11
11
|
"repository": {
|
@@ -19,6 +19,6 @@
|
|
19
19
|
},
|
20
20
|
"homepage": "https://github.com/Alex-Werner/hermodlog#readme",
|
21
21
|
"devDependencies": {
|
22
|
-
"
|
22
|
+
"@scintilla-network/litest": "1.3.1"
|
23
23
|
}
|
24
24
|
}
|
package/src/Logger.spec.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import {describe, expect, it} from '@scintilla-network/litest'
|
2
2
|
import Logger from "./Logger.js";
|
3
3
|
|
4
4
|
describe('Logger', () => {
|
@@ -7,51 +7,51 @@ describe('Logger', () => {
|
|
7
7
|
it('should create an logger', () => {
|
8
8
|
silentLogger = new Logger({date:new Date('2023-07-29T01:38:00.482Z')});
|
9
9
|
silentLogger._log = () => {}
|
10
|
-
|
10
|
+
expect(silentLogger.history.length).toBe(0)
|
11
11
|
silentLogger.log('Hello');
|
12
|
-
|
13
|
-
const expected = '[\u001b[90m2023-07-29T01:38:00.482Z\u001b[0m] \u001b[32mHello\u001b[0m'
|
14
|
-
|
12
|
+
expect(silentLogger.history.length).toBe(1)
|
13
|
+
const expected = '[\u001b[90m2023-07-29T01:38:00.482Z\u001b[0m] - \u001b[32mHello\u001b[0m'
|
14
|
+
expect(silentLogger.history[0]).toBe(expected)
|
15
15
|
})
|
16
16
|
it('should create an logger with module', () => {
|
17
17
|
silentModuleLogger = silentLogger.module('test-module')
|
18
18
|
silentModuleLogger.log('Hello');
|
19
|
-
|
20
|
-
const expected = '[\u001b[90m2023-07-29T01:38:00.482Z\u001b[0m] module:\u001b[90mtest-module\u001b[0m \u001b[32mHello\u001b[0m'
|
21
|
-
|
19
|
+
expect(silentModuleLogger.history.length).toBe(1)
|
20
|
+
const expected = '[\u001b[90m2023-07-29T01:38:00.482Z\u001b[0m] module:\u001b[90mtest-module\u001b[0m - \u001b[32mHello\u001b[0m'
|
21
|
+
expect(silentModuleLogger.history[0]).toBe(expected)
|
22
22
|
})
|
23
23
|
it('should create an logger with context', () => {
|
24
24
|
const silentContextLogger = silentModuleLogger.context('test-context')
|
25
25
|
silentContextLogger.log('Hello');
|
26
|
-
|
27
|
-
const expected = '[\u001b[90m2023-07-29T01:38:00.482Z\u001b[0m] context: \u001b[94mtest-context\u001b[0m | module:\u001b[90mtest-module\u001b[0m \u001b[32mHello\u001b[0m'
|
28
|
-
|
26
|
+
expect(silentContextLogger.history.length).toBe(1)
|
27
|
+
const expected = '[\u001b[90m2023-07-29T01:38:00.482Z\u001b[0m] context: \u001b[94mtest-context\u001b[0m | module:\u001b[90mtest-module\u001b[0m - \u001b[32mHello\u001b[0m'
|
28
|
+
expect(silentContextLogger.history[0]).toBe(expected)
|
29
29
|
})
|
30
30
|
it('should create an logger with listener', () => {
|
31
31
|
const silentListenerLogger = silentModuleLogger.listener('onTest')
|
32
32
|
silentListenerLogger.log('Hello');
|
33
|
-
|
34
|
-
const expected = '[\u001b[90m2023-07-29T01:38:00.482Z\u001b[0m] module:\u001b[90mtest-module\u001b[0m | listener: \u001b[36monTest\u001b[0m \u001b[32mHello\u001b[0m'
|
35
|
-
|
33
|
+
expect(silentListenerLogger.history.length).toBe(1)
|
34
|
+
const expected = '[\u001b[90m2023-07-29T01:38:00.482Z\u001b[0m] module:\u001b[90mtest-module\u001b[0m | listener: \u001b[36monTest\u001b[0m - \u001b[32mHello\u001b[0m'
|
35
|
+
expect(silentListenerLogger.history[0]).toBe(expected)
|
36
36
|
})
|
37
37
|
it('should create an logger with method', () => {
|
38
38
|
const silentMethodLogger = silentModuleLogger.method('test-method')
|
39
39
|
silentMethodLogger.log('Hello');
|
40
|
-
|
41
|
-
const expected = '[\u001b[90m2023-07-29T01:38:00.482Z\u001b[0m] module:\u001b[90mtest-module\u001b[0m | method: \u001b[33mtest-method\u001b[0m \u001b[32mHello\u001b[0m'
|
42
|
-
|
40
|
+
expect(silentMethodLogger.history.length).toBe(1)
|
41
|
+
const expected = '[\u001b[90m2023-07-29T01:38:00.482Z\u001b[0m] module:\u001b[90mtest-module\u001b[0m | method: \u001b[33mtest-method\u001b[0m - \u001b[32mHello\u001b[0m'
|
42
|
+
expect(silentMethodLogger.history[0]).toBe(expected)
|
43
43
|
})
|
44
44
|
it('should handle level', function () {
|
45
45
|
const levelLogger = new Logger({level: 'error'})
|
46
46
|
levelLogger._log = () => {}
|
47
47
|
levelLogger.error('Hello');
|
48
|
-
|
48
|
+
expect(levelLogger.history.length).toBe(1)
|
49
49
|
levelLogger.warn('Hello');
|
50
|
-
|
50
|
+
expect(levelLogger.history.length).toBe(1)
|
51
51
|
|
52
52
|
levelLogger.level = 'info'
|
53
53
|
levelLogger.trace('Hello');
|
54
|
-
|
54
|
+
expect(levelLogger.history.length).toBe(1)
|
55
55
|
});
|
56
56
|
|
57
57
|
it('should automatically beautify instead of [Object Object]', () => {
|
@@ -63,8 +63,8 @@ describe('Logger', () => {
|
|
63
63
|
req: 'getCar'
|
64
64
|
}
|
65
65
|
silentModuleLogger.log('Received from ws client', object)
|
66
|
-
|
67
|
-
const expected = `[\u001b[90m2023-07-29T01:38:00.482Z\u001b[0m] module:\u001b[90mtest-module\u001b[0m \u001b[32mReceived from ws client\u001b[0m \u001b[32mObject(\u001b[0m\u001b[32m{\n \"x\": 42,\n \"y\": {\n \"b\": [\n 1,\n 2,\n 3\n ]\n },\n \"req\": \"getCar\"\n}\u001b[0m\u001b[32m)\u001b[0m`;
|
68
|
-
|
66
|
+
expect(silentModuleLogger.history.length).toBe(2)
|
67
|
+
const expected = `[\u001b[90m2023-07-29T01:38:00.482Z\u001b[0m] module:\u001b[90mtest-module\u001b[0m - \u001b[32mReceived from ws client\u001b[0m \u001b[32mObject(\u001b[0m\u001b[32m{\n \"x\": 42,\n \"y\": {\n \"b\": [\n 1,\n 2,\n 3\n ]\n },\n \"req\": \"getCar\"\n}\u001b[0m\u001b[32m)\u001b[0m`;
|
68
|
+
expect(silentModuleLogger.history[1]).toBe(expected)
|
69
69
|
});
|
70
70
|
})
|