@tramvai/module-log 1.53.4 → 1.53.5
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/package.json +7 -7
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-log",
|
|
3
|
-
"version": "1.53.
|
|
3
|
+
"version": "1.53.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"browser": "lib/browser.js",
|
|
6
6
|
"main": "lib/server.js",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@tinkoff/utils": "^2.1.2",
|
|
26
|
-
"@tramvai/core": "1.53.
|
|
27
|
-
"@tramvai/module-environment": "1.53.
|
|
28
|
-
"@tramvai/papi": "1.53.
|
|
29
|
-
"@tramvai/state": "1.53.
|
|
30
|
-
"@tramvai/tokens-common": "1.53.
|
|
31
|
-
"@tramvai/tokens-server": "1.53.
|
|
26
|
+
"@tramvai/core": "1.53.5",
|
|
27
|
+
"@tramvai/module-environment": "1.53.5",
|
|
28
|
+
"@tramvai/papi": "1.53.5",
|
|
29
|
+
"@tramvai/state": "1.53.5",
|
|
30
|
+
"@tramvai/tokens-common": "1.53.5",
|
|
31
|
+
"@tramvai/tokens-server": "1.53.5",
|
|
32
32
|
"std-env": "^2.2.1",
|
|
33
33
|
"tslib": "^2.0.3"
|
|
34
34
|
},
|