@apolitical/logger 2.0.0-beta.4 → 2.0.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/CHANGELOG.md +8 -5
- package/README.md +10 -0
- package/package.json +3 -3
- package/src/config.js +0 -1
- package/src/services/logger.service.js +7 -14
package/CHANGELOG.md
CHANGED
|
@@ -5,14 +5,17 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
## [2.0.0] - 2022-01-18
|
|
10
9
|
### Changed
|
|
11
|
-
-
|
|
12
|
-
- Node version
|
|
13
|
-
-
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
- Upgraded Node.js version
|
|
12
|
+
- Revamped GitLab pipelines
|
|
13
|
+
- Renamed `metadata` to `labels` to allow consistency with logger middleware
|
|
14
14
|
### Added
|
|
15
|
-
-
|
|
15
|
+
- Exposed logger middleware
|
|
16
|
+
### Removed
|
|
17
|
+
- Filtered winston logger functionality
|
|
18
|
+
- Restricted metadata
|
|
16
19
|
|
|
17
20
|
## [1.0.2] - 2021-07-08
|
|
18
21
|
### Updated
|
package/README.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Node.js module to expose Apolitical's logger service
|
|
4
4
|
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
Requires the following to run:
|
|
8
|
+
|
|
9
|
+
- [node.js][node] 16.13.2+
|
|
10
|
+
- [yarn][yarn]
|
|
11
|
+
|
|
12
|
+
[node]: https://nodejs.org/en/download/
|
|
13
|
+
[yarn]: https://classic.yarnpkg.com/en/docs/install
|
|
14
|
+
|
|
5
15
|
## Installation
|
|
6
16
|
|
|
7
17
|
Install with `yarn`:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apolitical/logger",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Node.js module to expose Apolitical's logger service",
|
|
5
5
|
"author": "Apolitical Group Limited <engineering@apolitical.co>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"winston": "3.4.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@apolitical/eslint-config": "1.0.
|
|
32
|
+
"@apolitical/eslint-config": "1.0.1",
|
|
33
33
|
"audit-ci": "5.1.2",
|
|
34
34
|
"husky": "7.0.4",
|
|
35
35
|
"jest": "27.4.7",
|
|
36
36
|
"jest-junit": "13.0.0",
|
|
37
|
-
"lint-staged": "12.1
|
|
37
|
+
"lint-staged": "12.2.1"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=16.13.2"
|
package/src/config.js
CHANGED
|
@@ -2,20 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module.exports =
|
|
4
4
|
({ path, winston, winstonGoogle, config }) =>
|
|
5
|
-
({
|
|
6
|
-
const { LOGGING_LEVELS
|
|
5
|
+
({ labels = {}, logLevel = 'info' }) => {
|
|
6
|
+
const { LOGGING_LEVELS } = config.LOGGER;
|
|
7
7
|
const { ERROR_OPTIONS, COMBINED_OPTIONS } = config.LOGGER.TRANSPORTS.FILE;
|
|
8
8
|
const { CLOUD_FUNCTION, CREDENTIALS } = config.GOOGLE;
|
|
9
9
|
|
|
10
|
-
function allowedLabels() {
|
|
11
|
-
return ALLOWED_LABELS.reduce((acc, cv) => {
|
|
12
|
-
if (labels[cv]) {
|
|
13
|
-
acc[cv] = labels[cv];
|
|
14
|
-
}
|
|
15
|
-
return acc;
|
|
16
|
-
}, {});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
10
|
function loggingLevels() {
|
|
20
11
|
return LOGGING_LEVELS.reduce((acc, cv, idx) => {
|
|
21
12
|
acc[cv] = idx;
|
|
@@ -52,9 +43,11 @@ module.exports =
|
|
|
52
43
|
}
|
|
53
44
|
|
|
54
45
|
function createWrapper(logger) {
|
|
55
|
-
function where(filePath, method) {
|
|
46
|
+
function where(filePath, method, otherLabels = {}) {
|
|
56
47
|
const file = path.basename(filePath);
|
|
57
|
-
const childLogger = logger.child({
|
|
48
|
+
const childLogger = logger.child({
|
|
49
|
+
labels: Object.assign({ file, method }, labels, otherLabels),
|
|
50
|
+
});
|
|
58
51
|
return createWrapper(childLogger);
|
|
59
52
|
}
|
|
60
53
|
function write(message) {
|
|
@@ -64,7 +57,7 @@ module.exports =
|
|
|
64
57
|
}
|
|
65
58
|
|
|
66
59
|
const loggerInstance = winston.createLogger({
|
|
67
|
-
labels
|
|
60
|
+
labels,
|
|
68
61
|
level: logLevel,
|
|
69
62
|
levels: loggingLevels(),
|
|
70
63
|
format: loggerFormat(),
|