@rxap/nest-logger 10.3.0-dev.0 → 10.3.0-dev.2
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
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [10.3.0-dev.2](https://gitlab.com/rxap/packages/compare/@rxap/nest-logger@10.3.0-dev.1...@rxap/nest-logger@10.3.0-dev.2) (2025-01-21)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @rxap/nest-logger
|
|
9
|
+
|
|
10
|
+
# [10.3.0-dev.1](https://gitlab.com/rxap/packages/compare/@rxap/nest-logger@10.3.0-dev.0...@rxap/nest-logger@10.3.0-dev.1) (2025-01-16)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- add google logging print messages function ([8bcf9ad](https://gitlab.com/rxap/packages/commit/8bcf9ad442259cc958878ef276582c3421d1b901))
|
|
15
|
+
|
|
6
16
|
# [10.3.0-dev.0](https://gitlab.com/rxap/packages/compare/@rxap/nest-logger@10.2.11-dev.0...@rxap/nest-logger@10.3.0-dev.0) (2025-01-16)
|
|
7
17
|
|
|
8
18
|
### Features
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "10.3.0-dev.
|
|
2
|
+
"version": "10.3.0-dev.2",
|
|
3
3
|
"name": "@rxap/nest-logger",
|
|
4
4
|
"license": "GPL-3.0-or-later",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@nx/devkit": "20.3.1",
|
|
7
|
-
"@rxap/ts-morph": "^1.5.3-dev.
|
|
7
|
+
"@rxap/ts-morph": "^1.5.3-dev.1",
|
|
8
8
|
"@rxap/workspace-utilities": "^19.6.1-dev.0",
|
|
9
9
|
"tslib": "2.6.2"
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"@nestjs/common": "^10.3.8"
|
|
12
|
+
"@nestjs/common": "^10.3.8",
|
|
13
|
+
"@rxap/nest-utilities": "^10.3.9-dev.1",
|
|
14
|
+
"@rxap/utilities": "^16.4.2-dev.0"
|
|
13
15
|
},
|
|
14
16
|
"author": {
|
|
15
17
|
"name": "Merzough Münker",
|
|
@@ -34,9 +36,33 @@
|
|
|
34
36
|
},
|
|
35
37
|
"nx-migrations": {
|
|
36
38
|
"packageGroup": [
|
|
39
|
+
{
|
|
40
|
+
"package": "@nestjs/cache-manager",
|
|
41
|
+
"version": "2.2.2"
|
|
42
|
+
},
|
|
37
43
|
{
|
|
38
44
|
"package": "@nestjs/common",
|
|
39
45
|
"version": "10.3.8"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"package": "@nestjs/config",
|
|
49
|
+
"version": "3.2.2"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"package": "@nestjs/core",
|
|
53
|
+
"version": "10.3.8"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"package": "@nestjs/throttler",
|
|
57
|
+
"version": "5.1.2"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"package": "@rxap/nest-utilities",
|
|
61
|
+
"version": "10.3.9-dev.1"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"package": "@rxap/utilities",
|
|
65
|
+
"version": "16.4.2-dev.0"
|
|
40
66
|
}
|
|
41
67
|
]
|
|
42
68
|
},
|
|
@@ -50,7 +76,7 @@
|
|
|
50
76
|
"directory": "packages/nest/logger"
|
|
51
77
|
},
|
|
52
78
|
"type": "commonjs",
|
|
53
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "af3f3615668e796c28bf20b9bc94b929e7a1e9b5",
|
|
54
80
|
"types": "./src/index.d.ts",
|
|
55
81
|
"main": "./src/index.js"
|
|
56
82
|
}
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
// region
|
|
5
|
+
tslib_1.__exportStar(require("./lib/google-logging-print-messages-factory"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./lib/logger.module"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./lib/logger"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./lib/tokens"), exports);
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.googleLoggingPrintMessagesFactory = void 0;
|
|
4
|
+
const utilities_1 = require("@rxap/utilities");
|
|
5
|
+
/**
|
|
6
|
+
* Sources
|
|
7
|
+
* https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry
|
|
8
|
+
* https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity
|
|
9
|
+
* https://cloud.google.com/run/docs/logging#container-logs
|
|
10
|
+
*
|
|
11
|
+
* When you provide a structured log as a JSON dictionary, some special fields are stripped from the
|
|
12
|
+
* jsonPayload and are written to the corresponding field in the generated LogEntry as described in the
|
|
13
|
+
* documentation for special fields.
|
|
14
|
+
* https://cloud.google.com/logging/docs/agent/logging/configuration#special-fields
|
|
15
|
+
* @param level
|
|
16
|
+
*/
|
|
17
|
+
function logLevelToSeverity(level) {
|
|
18
|
+
switch (level) {
|
|
19
|
+
case 'log':
|
|
20
|
+
return 'INFO';
|
|
21
|
+
case 'debug':
|
|
22
|
+
return 'DEBUG';
|
|
23
|
+
case 'warn':
|
|
24
|
+
return 'WARNING';
|
|
25
|
+
case 'error':
|
|
26
|
+
return 'ERROR';
|
|
27
|
+
case 'fatal':
|
|
28
|
+
return 'CRITICAL';
|
|
29
|
+
}
|
|
30
|
+
return 'DEFAULT';
|
|
31
|
+
}
|
|
32
|
+
function countOccurrences(mainStr, subStr) {
|
|
33
|
+
let count = 0;
|
|
34
|
+
let position = mainStr.indexOf(subStr);
|
|
35
|
+
while (position !== -1) {
|
|
36
|
+
count++;
|
|
37
|
+
position = mainStr.indexOf(subStr, position + subStr.length);
|
|
38
|
+
}
|
|
39
|
+
return count;
|
|
40
|
+
}
|
|
41
|
+
const googleLoggingPrintMessagesFactory = (environment) => (messages, context, logLevel, writeStreamType) => {
|
|
42
|
+
if (!messages.length) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
const firstMessage = messages.shift();
|
|
46
|
+
let message = undefined;
|
|
47
|
+
let jsonPayload = undefined;
|
|
48
|
+
if (typeof firstMessage === 'string') {
|
|
49
|
+
if (context) {
|
|
50
|
+
message = `[${context}] ${firstMessage}`;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
message = firstMessage;
|
|
54
|
+
}
|
|
55
|
+
if (messages.length) {
|
|
56
|
+
jsonPayload = {};
|
|
57
|
+
if (firstMessage.includes('%JSON')) {
|
|
58
|
+
const interpolateCount = countOccurrences(firstMessage, '%JSON');
|
|
59
|
+
jsonPayload['interpolates'] = messages.splice(0, interpolateCount);
|
|
60
|
+
}
|
|
61
|
+
if (messages.length) {
|
|
62
|
+
jsonPayload['args'] = messages;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
if (messages.length === 1) {
|
|
68
|
+
if (typeof messages[0] === 'object' && messages[0]) {
|
|
69
|
+
if (!Array.isArray(messages[0])) {
|
|
70
|
+
jsonPayload = messages[0];
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
jsonPayload = { items: messages[0] };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
message = JSON.stringify(messages[0]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
jsonPayload = { messages };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const payload = {
|
|
85
|
+
message,
|
|
86
|
+
...jsonPayload,
|
|
87
|
+
severity: logLevelToSeverity(logLevel),
|
|
88
|
+
};
|
|
89
|
+
const labels = (0, utilities_1.DeleteEmptyProperties)({
|
|
90
|
+
app: environment.app,
|
|
91
|
+
production: environment.production ? 'true' : 'false',
|
|
92
|
+
release: environment.release,
|
|
93
|
+
gitCommit: environment.commit,
|
|
94
|
+
gitBranch: environment.branch,
|
|
95
|
+
gitTag: environment.tag,
|
|
96
|
+
buildTimestamp: environment.timestamp,
|
|
97
|
+
environmentTier: environment.tier,
|
|
98
|
+
environmentName: environment.name,
|
|
99
|
+
});
|
|
100
|
+
if (context) {
|
|
101
|
+
labels['context'] = context;
|
|
102
|
+
}
|
|
103
|
+
if (Object.keys(labels).length) {
|
|
104
|
+
payload["logging.googleapis.com/labels"] = labels;
|
|
105
|
+
}
|
|
106
|
+
console.log(JSON.stringify(payload));
|
|
107
|
+
return false;
|
|
108
|
+
};
|
|
109
|
+
exports.googleLoggingPrintMessagesFactory = googleLoggingPrintMessagesFactory;
|