@tramvai/module-log 1.53.2 → 1.54.0
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/README.md +76 -70
- package/lib/browser.js +2 -0
- package/lib/constants.d.ts +1 -0
- package/lib/server.es.js +2 -0
- package/lib/server.js +2 -0
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,117 +1,123 @@
|
|
|
1
1
|
# Log
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Module adds `LOGGER_TOKEN` token implementation using library [@tinkoff/logger](references/libs/logger.md).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Module is automatically installs and adds with module `@tramvai/module-common`
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Explanation
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
import { Module, commandLineListToken, provide } from '@tramvai/core';
|
|
13
|
-
import { LOGGER_TOKEN } from '@tramvai/module-common';
|
|
14
|
-
|
|
15
|
-
@Module({
|
|
16
|
-
providers: [
|
|
17
|
-
provide({
|
|
18
|
-
provide: commandLineListToken.customerStart,
|
|
19
|
-
useFactory: ({ logger }) => {
|
|
20
|
-
logger.debug('customer start'); // логгирование в глобальном пространстве логов
|
|
21
|
-
|
|
22
|
-
const myLogger = logger({
|
|
23
|
-
name: 'test',
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
myLogger.warn('warning'); // логгирование в пространстве test
|
|
27
|
-
myLogger.error('error!');
|
|
28
|
-
},
|
|
29
|
-
deps: {
|
|
30
|
-
logger: LOGGER_TOKEN,
|
|
31
|
-
},
|
|
32
|
-
}),
|
|
33
|
-
],
|
|
34
|
-
})
|
|
35
|
-
export class MyModule {}
|
|
36
|
-
```
|
|
11
|
+
### Display logs
|
|
37
12
|
|
|
38
|
-
|
|
13
|
+
see [@tinkoff/logger](../libs/logger#display-logs).
|
|
39
14
|
|
|
40
|
-
|
|
15
|
+
> By default, on server all of the logs of level warn and above are enabled. On the client in dev-mode all the logs of level error and above are enabled while in prod-mode all of the logs on client are disabled.
|
|
41
16
|
|
|
42
|
-
|
|
17
|
+
### Send logs to the API
|
|
43
18
|
|
|
44
|
-
|
|
19
|
+
It is implied that logs from the server are collected by the external tool that has access to the server console output and because of this logging to the external API from the server is not needed.
|
|
45
20
|
|
|
46
|
-
|
|
21
|
+
In browser logs to the API are send with [RemoteReporter](../libs/logger.md#remotereporter). By default, all of the logs with levels `error` and `fatal` are send. The url for the API is specified by environment variable `FRONT_LOG_API`. For the customization see docs for the [RemoteReporter](../libs/logger.md#remotereporter).
|
|
47
22
|
|
|
48
|
-
|
|
23
|
+
### See logs from the server in browser
|
|
49
24
|
|
|
50
|
-
|
|
25
|
+
This functionality is available only in dev-mode and can make development a little easier.
|
|
51
26
|
|
|
52
|
-
|
|
27
|
+
In browser console when loading page of the app the special log group with name `Tramvai SSR Logs` will be showed. If you open this group you will see logs from the server that was logged to this particular request. Herewith will be displayed only logs that are enabled for the [displaying on the server](#display-logs). If you want to see all of the logs in browser with settings for [displaying in browser](#display-logs) you can specify env `DEBUG_FULL_SSR` when running app.
|
|
53
28
|
|
|
54
|
-
|
|
29
|
+
### See logs for the requests
|
|
55
30
|
|
|
56
|
-
|
|
31
|
+
> Works only with [@tinkoff/request](https://tinkoff.github.io/tinkoff-request/)
|
|
57
32
|
|
|
58
|
-
|
|
33
|
+
[http-client](references/modules/http-client.md) is already passes logger and its settings to the [log plugin](https://tinkoff.github.io/tinkoff-request/docs/plugins/log.html).
|
|
59
34
|
|
|
60
|
-
|
|
35
|
+
Plugin automatically generates names for loggers using template `request.${name}` that might be used to setting up [displaying of logs](#display-logs):
|
|
61
36
|
|
|
62
37
|
```tsx
|
|
63
38
|
const logger = di.get(LOGGER_TOKEN);
|
|
64
39
|
const makeRequest = request([...otherPlugins, logger({ name: 'my-api-name', logger })]);
|
|
65
40
|
```
|
|
66
41
|
|
|
67
|
-
|
|
42
|
+
As name of the logger equals to `my-api-name` to show logs:
|
|
68
43
|
|
|
69
|
-
-
|
|
70
|
-
-
|
|
44
|
+
- on server extend env `LOG_ENABLE: 'request.my-api-name'`
|
|
45
|
+
- on client call `logger.enable('request.my-api-name')`
|
|
71
46
|
|
|
72
|
-
|
|
47
|
+
### Change logger settings on server
|
|
73
48
|
|
|
74
|
-
|
|
49
|
+
By default, settings for the logger on server are specified by envs `LOG_ENABLE` and `LOG_LEVEL`.
|
|
75
50
|
|
|
76
|
-
|
|
51
|
+
You can change this settings in runtime using papi-route `{app}/private/papi/logger`
|
|
77
52
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
Сущность логгера. Заменяет стандартную реализацию `LOGGER_TOKEN` из [@tramvai/module-common](references/modules/common.md)
|
|
81
|
-
|
|
82
|
-
## Изменение серверных настроек логгера
|
|
83
|
-
|
|
84
|
-
По умолчанию, настройки отображения логгера на сервере берутся из переменной окружения `LOG_ENABLE`, а настройки уровня логирования из переменной окружения `LOG_LEVEL`
|
|
85
|
-
|
|
86
|
-
Для изменения этих настроек в рантайме существует papi роут `{app}/private/papi/logger`
|
|
87
|
-
|
|
88
|
-
Отображение логов меняется через query параметр `enable`, например:
|
|
53
|
+
Displaying of the logs is changed by query with the name `enable`, e.g.:
|
|
89
54
|
|
|
90
55
|
```
|
|
91
56
|
https://localhost:3000/{app}/private/papi/logger?enable=request.tinkoff
|
|
92
57
|
```
|
|
93
58
|
|
|
94
|
-
|
|
59
|
+
Level of the logs is change by query with the name `level`, e.g.:
|
|
95
60
|
|
|
96
61
|
```
|
|
97
62
|
https://localhost:3000/{app}/private/papi/logger?level=warn
|
|
98
63
|
```
|
|
99
64
|
|
|
100
|
-
|
|
65
|
+
To reset settings to default, based on env, use `mode=default`:
|
|
101
66
|
|
|
102
67
|
```
|
|
103
68
|
https://localhost:3000/{app}/private/papi/logger?mode=default
|
|
104
69
|
```
|
|
105
70
|
|
|
106
|
-
|
|
71
|
+
### Env
|
|
72
|
+
|
|
73
|
+
- `LOG_LEVEL` = trace | debug | info | warn | error | fatal - show logs with specified level and higher. E.g.:
|
|
74
|
+
- if `LOG_LEVEL=info` then logs with levels `info`, `warn`, `error`, `fatal` will be showed
|
|
75
|
+
- `LOG_ENABLE` = `${name}` | `${level}:${name}` - show logs with specified name of the logger or name + level. Several entries are passed with comma as delimiter. E.g.:
|
|
76
|
+
- if `LOG_ENABLE=server` then show logs with the name `server`
|
|
77
|
+
- if `LOG_ENABLE=trace:server*` then show logs with the name `server` and level `trace`
|
|
78
|
+
- if `LOG_ENABLE=info:server,client,trace:shared` then show all of the specified logs using rules from above
|
|
79
|
+
|
|
80
|
+
### Debug
|
|
107
81
|
|
|
108
|
-
|
|
109
|
-
- если `LOG_LEVEL=info`, то будут отображаться все логи уровней info, warn, error, fatal
|
|
110
|
-
- `LOG_ENABLE` = `${name}` | `${level}:${name}` - позволяет включить отображение всех логов по определенному имени логгера или по определенному имени и уровню. Несколько вхождений передаются через запятую. Примеры:
|
|
111
|
-
- если `LOG_ENABLE=server`, то будут отображены логи всех уровней с именем `server`
|
|
112
|
-
- если `LOG_ENABLE=trace:server*`, то будут отображены только логи для `server` с уровнем `trace`
|
|
113
|
-
- если `LOG_ENABLE=info:server,client,trace:shared`, то будут включены логи для заданных логгеров по правилам выше
|
|
82
|
+
Module uses logger with the id `ssr-logger`
|
|
114
83
|
|
|
115
|
-
##
|
|
84
|
+
## How to
|
|
85
|
+
|
|
86
|
+
### Example of base usage
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import { Module, commandLineListToken, provide } from '@tramvai/core';
|
|
90
|
+
import { LOGGER_TOKEN } from '@tramvai/module-common';
|
|
91
|
+
|
|
92
|
+
@Module({
|
|
93
|
+
providers: [
|
|
94
|
+
provide({
|
|
95
|
+
provide: commandLineListToken.customerStart,
|
|
96
|
+
useFactory: ({ logger }) => {
|
|
97
|
+
logger.debug('customer start'); // logging in the global namespace
|
|
98
|
+
|
|
99
|
+
const myLogger = logger({
|
|
100
|
+
name: 'test',
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
myLogger.warn('warning'); // logging in the namespace test
|
|
104
|
+
myLogger.error('error!');
|
|
105
|
+
},
|
|
106
|
+
deps: {
|
|
107
|
+
logger: LOGGER_TOKEN,
|
|
108
|
+
},
|
|
109
|
+
}),
|
|
110
|
+
],
|
|
111
|
+
})
|
|
112
|
+
export class MyModule {}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### How to properly format logs
|
|
116
|
+
|
|
117
|
+
See [@tinkoff/logger](../libs/logger.md#how-to-log-properly)
|
|
118
|
+
|
|
119
|
+
## Exported tokens
|
|
120
|
+
|
|
121
|
+
### LOGGER_TOKEN
|
|
116
122
|
|
|
117
|
-
|
|
123
|
+
Instance of the logger. Replaces base implementation for the `LOGGER_TOKEN` from the [@tramvai/module-common](references/modules/common.md)
|
package/lib/browser.js
CHANGED
|
@@ -12,6 +12,7 @@ import { createEvent, createReducer } from '@tramvai/state';
|
|
|
12
12
|
|
|
13
13
|
const LOGGER_NAME = '';
|
|
14
14
|
const LOGGER_KEY = 'tramvai';
|
|
15
|
+
const LOGGER_DEPTH_LIMIT = 20;
|
|
15
16
|
|
|
16
17
|
const setLogs = createEvent('setLogs');
|
|
17
18
|
const LogStore = createReducer('devLogs', []).on(setLogs, (_, logs) => logs);
|
|
@@ -180,6 +181,7 @@ const logger = createLoggerFactory({
|
|
|
180
181
|
name: LOGGER_NAME,
|
|
181
182
|
key: LOGGER_KEY,
|
|
182
183
|
reporters: [new BrowserReporter()],
|
|
184
|
+
depthLimit: LOGGER_DEPTH_LIMIT,
|
|
183
185
|
});
|
|
184
186
|
let LogModule = class LogModule {
|
|
185
187
|
};
|
package/lib/constants.d.ts
CHANGED
package/lib/server.es.js
CHANGED
|
@@ -177,6 +177,7 @@ const flushLogs = (ssrLogger, logs) => {
|
|
|
177
177
|
|
|
178
178
|
const LOGGER_NAME = '';
|
|
179
179
|
const LOGGER_KEY = 'tramvai';
|
|
180
|
+
const LOGGER_DEPTH_LIMIT = 20;
|
|
180
181
|
|
|
181
182
|
const DefaultReporter = env.ci || env.test ? NodeBasicReporter : NodeDevReporter;
|
|
182
183
|
const reporter = process.env.DEBUG_PLAIN || process.env.NODE_ENV !== 'production'
|
|
@@ -190,6 +191,7 @@ const logger = createLoggerFactory({
|
|
|
190
191
|
pid: process.pid,
|
|
191
192
|
hostname: hostname(),
|
|
192
193
|
},
|
|
194
|
+
depthLimit: LOGGER_DEPTH_LIMIT,
|
|
193
195
|
});
|
|
194
196
|
function factory({ environmentManager, loggerInitHooks }) {
|
|
195
197
|
var _a, _b;
|
package/lib/server.js
CHANGED
|
@@ -186,6 +186,7 @@ const flushLogs = (ssrLogger, logs) => {
|
|
|
186
186
|
|
|
187
187
|
const LOGGER_NAME = '';
|
|
188
188
|
const LOGGER_KEY = 'tramvai';
|
|
189
|
+
const LOGGER_DEPTH_LIMIT = 20;
|
|
189
190
|
|
|
190
191
|
const DefaultReporter = env__default["default"].ci || env__default["default"].test ? logger$1.NodeBasicReporter : logger$1.NodeDevReporter;
|
|
191
192
|
const reporter = process.env.DEBUG_PLAIN || process.env.NODE_ENV !== 'production'
|
|
@@ -199,6 +200,7 @@ const logger = logger$1.createLoggerFactory({
|
|
|
199
200
|
pid: process.pid,
|
|
200
201
|
hostname: os.hostname(),
|
|
201
202
|
},
|
|
203
|
+
depthLimit: LOGGER_DEPTH_LIMIT,
|
|
202
204
|
});
|
|
203
205
|
function factory({ environmentManager, loggerInitHooks }) {
|
|
204
206
|
var _a, _b;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-log",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.54.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"browser": "lib/browser.js",
|
|
6
6
|
"main": "lib/server.js",
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
"build-for-publish": "true"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@tinkoff/logger": "0.10.
|
|
22
|
+
"@tinkoff/logger": "0.10.13"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@tinkoff/utils": "^2.1.2",
|
|
26
|
-
"@tramvai/core": "1.
|
|
27
|
-
"@tramvai/module-environment": "1.
|
|
28
|
-
"@tramvai/papi": "1.
|
|
29
|
-
"@tramvai/state": "1.
|
|
30
|
-
"@tramvai/tokens-common": "1.
|
|
31
|
-
"@tramvai/tokens-server": "1.
|
|
26
|
+
"@tramvai/core": "1.54.0",
|
|
27
|
+
"@tramvai/module-environment": "1.54.0",
|
|
28
|
+
"@tramvai/papi": "1.54.0",
|
|
29
|
+
"@tramvai/state": "1.54.0",
|
|
30
|
+
"@tramvai/tokens-common": "1.54.0",
|
|
31
|
+
"@tramvai/tokens-server": "1.54.0",
|
|
32
32
|
"std-env": "^2.2.1",
|
|
33
33
|
"tslib": "^2.0.3"
|
|
34
34
|
},
|