@bigid/apps-infrastructure-node-js 1.191.1 → 1.194.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/lib/abstractProviders/logsProvider.js +3 -1
- package/lib/utils/appLogger.js +2 -1
- package/lib/utils/constants.d.ts +1 -0
- package/lib/utils/constants.js +2 -1
- package/package.json +1 -1
- package/src/abstractProviders/logsProvider.ts +6 -2
- package/src/utils/appLogger.ts +7 -5
- package/src/utils/constants.ts +2 -1
|
@@ -3,9 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.fetchLogs = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const constants_1 = require("../utils/constants");
|
|
6
|
+
const READONLY_MODE_ENABLED = process.env.READONLY_MODE_ENABLED === "true";
|
|
7
|
+
const logFolder = READONLY_MODE_ENABLED ? constants_1.TMP_LOGS_PATH : constants_1.LOGS_PATH;
|
|
6
8
|
const fetchLogs = (req, res) => {
|
|
7
9
|
const tenantId = req.headers.tenantid;
|
|
8
|
-
const data = (0, fs_1.readFileSync)(
|
|
10
|
+
const data = (0, fs_1.readFileSync)(logFolder, { encoding: 'utf8' });
|
|
9
11
|
const lines = data.split('\n');
|
|
10
12
|
const tenantLogLines = lines
|
|
11
13
|
.filter(line => line.includes(`[tenantId: ${tenantId}`) || !line.includes('[tenantId: '))
|
package/lib/utils/appLogger.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.logDebug = exports.logWarn = exports.logError = exports.logInfo = void 0
|
|
|
4
4
|
const log4js_1 = require("log4js");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const USER_LOG_BACKUPS = parseInt(process.env.LOG_BACKUPS + "") || 3;
|
|
7
|
+
const READONLY_MODE_ENABLED = process.env.READONLY_MODE_ENABLED === "true";
|
|
7
8
|
const MAX_BACKUPS = 10;
|
|
8
9
|
(0, log4js_1.configure)({
|
|
9
10
|
appenders: {
|
|
@@ -11,7 +12,7 @@ const MAX_BACKUPS = 10;
|
|
|
11
12
|
dateFile: {
|
|
12
13
|
type: 'dateFile',
|
|
13
14
|
layout: { type: 'basic' },
|
|
14
|
-
filename: constants_1.LOGS_PATH,
|
|
15
|
+
filename: READONLY_MODE_ENABLED ? constants_1.TMP_LOGS_PATH : constants_1.LOGS_PATH,
|
|
15
16
|
compress: true,
|
|
16
17
|
numBackups: USER_LOG_BACKUPS > MAX_BACKUPS ? MAX_BACKUPS : USER_LOG_BACKUPS,
|
|
17
18
|
keepFileExt: true,
|
package/lib/utils/constants.d.ts
CHANGED
package/lib/utils/constants.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
|
-
import {
|
|
3
|
+
import {LOGS_PATH, TMP_LOGS_PATH} from '../utils/constants';
|
|
4
|
+
|
|
5
|
+
const READONLY_MODE_ENABLED = process.env.READONLY_MODE_ENABLED === "true";
|
|
6
|
+
|
|
7
|
+
const logFolder = READONLY_MODE_ENABLED ? TMP_LOGS_PATH : LOGS_PATH
|
|
4
8
|
|
|
5
9
|
export const fetchLogs = (req: Request, res: Response) => {
|
|
6
10
|
const tenantId = req.headers.tenantid;
|
|
7
|
-
const data = readFileSync(
|
|
11
|
+
const data = readFileSync(logFolder, { encoding: 'utf8' });
|
|
8
12
|
const lines = data.split('\n');
|
|
9
13
|
const tenantLogLines = lines
|
|
10
14
|
.filter(line => line.includes(`[tenantId: ${tenantId}`) || !line.includes('[tenantId: '))
|
package/src/utils/appLogger.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { configure, getLogger } from 'log4js';
|
|
2
|
-
import { LOGS_PATH } from './constants';
|
|
2
|
+
import { LOGS_PATH, TMP_LOGS_PATH } from './constants';
|
|
3
3
|
|
|
4
4
|
type LogMetadata = {
|
|
5
5
|
tenantId: string;
|
|
@@ -7,6 +7,8 @@ type LogMetadata = {
|
|
|
7
7
|
scriptName: string;
|
|
8
8
|
};
|
|
9
9
|
const USER_LOG_BACKUPS = parseInt(process.env.LOG_BACKUPS + "") || 3;
|
|
10
|
+
|
|
11
|
+
const READONLY_MODE_ENABLED = process.env.READONLY_MODE_ENABLED === "true";
|
|
10
12
|
const MAX_BACKUPS = 10;
|
|
11
13
|
|
|
12
14
|
configure({
|
|
@@ -15,7 +17,7 @@ configure({
|
|
|
15
17
|
dateFile: {
|
|
16
18
|
type: 'dateFile',
|
|
17
19
|
layout: { type: 'basic' },
|
|
18
|
-
filename: LOGS_PATH,
|
|
20
|
+
filename: READONLY_MODE_ENABLED ? TMP_LOGS_PATH : LOGS_PATH,
|
|
19
21
|
compress: true,
|
|
20
22
|
numBackups: USER_LOG_BACKUPS > MAX_BACKUPS ? MAX_BACKUPS : USER_LOG_BACKUPS,
|
|
21
23
|
keepFileExt: true,
|
|
@@ -32,9 +34,9 @@ const formatLog = (message: string, logMetadata?: LogMetadata): string => {
|
|
|
32
34
|
if (!logMetadata) return message;
|
|
33
35
|
|
|
34
36
|
const params = Object.entries(logMetadata)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
.filter(([value]) => value)
|
|
38
|
+
.map(([key, value]) => `[${key}: ${value}]`)
|
|
39
|
+
.join(' ');
|
|
38
40
|
return `${params} ${message}`;
|
|
39
41
|
};
|
|
40
42
|
|
package/src/utils/constants.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export const LOGS_PATH = 'log/app.log';
|
|
1
|
+
export const LOGS_PATH = 'log/app.log';
|
|
2
|
+
export const TMP_LOGS_PATH = '/tmp/log/app.log';
|