@rockster/logger 0.0.3 → 0.1.1
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/config/remote-persist.config.d.ts +14 -0
- package/config/remote-persist.config.js +55 -0
- package/config/remote-persist.config.js.map +1 -0
- package/env.js +16 -6
- package/env.js.map +1 -1
- package/functions/dispatch-log.d.ts +2 -0
- package/functions/dispatch-log.js +17 -0
- package/functions/dispatch-log.js.map +1 -0
- package/functions/enable-console.js +0 -4
- package/functions/enable-console.js.map +1 -1
- package/functions/get-error-infos.d.ts +2 -2
- package/functions/get-error-infos.js +40 -13
- package/functions/get-error-infos.js.map +1 -1
- package/functions/index.d.ts +3 -0
- package/functions/index.js +3 -0
- package/functions/index.js.map +1 -1
- package/functions/log-level.d.ts +7 -0
- package/functions/log-level.js +42 -0
- package/functions/log-level.js.map +1 -0
- package/functions/merge-log-extras.d.ts +3 -0
- package/functions/merge-log-extras.js +31 -0
- package/functions/merge-log-extras.js.map +1 -0
- package/functions/parse-bulk-index-response.d.ts +4 -0
- package/functions/parse-bulk-index-response.js +40 -0
- package/functions/parse-bulk-index-response.js.map +1 -0
- package/functions/probe-log-store.d.ts +12 -0
- package/functions/probe-log-store.js +182 -0
- package/functions/probe-log-store.js.map +1 -0
- package/functions/serialize-log-for-persist.d.ts +4 -0
- package/functions/serialize-log-for-persist.js +54 -0
- package/functions/serialize-log-for-persist.js.map +1 -0
- package/functions/write-log-store-status.d.ts +5 -0
- package/functions/write-log-store-status.js +50 -0
- package/functions/write-log-store-status.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/index.js.map +1 -1
- package/interfaces/log.d.ts +16 -0
- package/interfaces/log.js.map +1 -1
- package/logger.d.ts +9 -4
- package/logger.js +22 -9
- package/logger.js.map +1 -1
- package/package.json +33 -33
- package/services/log-runtime.service.d.ts +65 -0
- package/services/log-runtime.service.js +397 -0
- package/services/log-runtime.service.js.map +1 -0
- package/services/opensearch-client.d.ts +14 -0
- package/services/opensearch-client.js +113 -0
- package/services/opensearch-client.js.map +1 -0
- package/services/remote-persist.service.d.ts +31 -0
- package/services/remote-persist.service.js +261 -0
- package/services/remote-persist.service.js.map +1 -0
- package/stdout-writer.d.ts +6 -5
- package/stdout-writer.js +49 -46
- package/stdout-writer.js.map +1 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.probeLogStore = void 0;
|
|
4
|
+
const CONNECT_TIMEOUT_MS = 5000;
|
|
5
|
+
const getAuthHeader = (config) => {
|
|
6
|
+
return `Basic ${Buffer.from(`${config.username}:${config.password}`).toString('base64')}`;
|
|
7
|
+
};
|
|
8
|
+
const fetchWithTimeout = (url, options = {}) => {
|
|
9
|
+
var _a;
|
|
10
|
+
return fetch(url, Object.assign(Object.assign({}, options), { signal: (_a = options.signal) !== null && _a !== void 0 ? _a : AbortSignal.timeout(CONNECT_TIMEOUT_MS) }));
|
|
11
|
+
};
|
|
12
|
+
const formatFetchError = (error) => {
|
|
13
|
+
if (error instanceof Error) {
|
|
14
|
+
if (error.name === 'TimeoutError' || error.message.includes('timeout')) {
|
|
15
|
+
return `Request timed out after ${CONNECT_TIMEOUT_MS}ms`;
|
|
16
|
+
}
|
|
17
|
+
if (error.message.includes('certificate') || error.message.includes('SSL')) {
|
|
18
|
+
return `TLS/SSL error: ${error.message}`;
|
|
19
|
+
}
|
|
20
|
+
if (error.message.includes('ECONNREFUSED')) {
|
|
21
|
+
return `Connection refused — is the log store URL correct and reachable?`;
|
|
22
|
+
}
|
|
23
|
+
if (error.message.includes('ENOTFOUND') || error.message.includes('getaddrinfo')) {
|
|
24
|
+
return `Host not found — check LOGGER_STORE_URL`;
|
|
25
|
+
}
|
|
26
|
+
return error.message;
|
|
27
|
+
}
|
|
28
|
+
return String(error);
|
|
29
|
+
};
|
|
30
|
+
const readErrorBody = async (response) => {
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
try {
|
|
33
|
+
const text = await response.text();
|
|
34
|
+
if (!text) {
|
|
35
|
+
return response.statusText || 'Unknown error';
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const json = JSON.parse(text);
|
|
39
|
+
const reason = (_b = (_a = json.error) === null || _a === void 0 ? void 0 : _a.reason) !== null && _b !== void 0 ? _b : (_c = json.error) === null || _c === void 0 ? void 0 : _c.type;
|
|
40
|
+
if (reason) {
|
|
41
|
+
return reason;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (_d) {
|
|
45
|
+
}
|
|
46
|
+
return text.length > 200 ? `${text.slice(0, 200)}…` : text;
|
|
47
|
+
}
|
|
48
|
+
catch (_e) {
|
|
49
|
+
return response.statusText || 'Unknown error';
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const mainIndexMappings = {
|
|
53
|
+
mappings: {
|
|
54
|
+
dynamic_templates: [
|
|
55
|
+
{
|
|
56
|
+
log_extras: {
|
|
57
|
+
match_mapping_type: 'string',
|
|
58
|
+
mapping: {
|
|
59
|
+
type: 'keyword',
|
|
60
|
+
ignore_above: 256,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
properties: {
|
|
66
|
+
type: { type: 'keyword' },
|
|
67
|
+
date: { type: 'date' },
|
|
68
|
+
context: { type: 'keyword' },
|
|
69
|
+
message: { type: 'text' },
|
|
70
|
+
appId: { type: 'keyword' },
|
|
71
|
+
hostname: { type: 'keyword' },
|
|
72
|
+
pid: { type: 'integer' },
|
|
73
|
+
stdout: { type: 'text' },
|
|
74
|
+
name: { type: 'keyword' },
|
|
75
|
+
workspaceId: { type: 'keyword' },
|
|
76
|
+
instanceId: { type: 'keyword' },
|
|
77
|
+
invoiceId: { type: 'keyword' },
|
|
78
|
+
accountId: { type: 'keyword' },
|
|
79
|
+
taskId: { type: 'keyword' },
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
const probeLogStore = async (config) => {
|
|
84
|
+
const auth = getAuthHeader(config);
|
|
85
|
+
const steps = [];
|
|
86
|
+
let clusterOk = false;
|
|
87
|
+
let clusterDetail = '';
|
|
88
|
+
for (const path of ['/', '/_cluster/health']) {
|
|
89
|
+
try {
|
|
90
|
+
const response = await fetchWithTimeout(`${config.url}${path}`, {
|
|
91
|
+
headers: { Authorization: auth },
|
|
92
|
+
});
|
|
93
|
+
if (response.ok) {
|
|
94
|
+
clusterOk = true;
|
|
95
|
+
clusterDetail = `HTTP ${response.status} on ${path}`;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
const body = await readErrorBody(response);
|
|
99
|
+
clusterDetail = `HTTP ${response.status} on ${path}: ${body}`;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
clusterDetail = formatFetchError(error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
steps.push({
|
|
106
|
+
name: 'cluster',
|
|
107
|
+
ok: clusterOk,
|
|
108
|
+
detail: clusterOk
|
|
109
|
+
? clusterDetail
|
|
110
|
+
: `Cluster unreachable at ${config.url} — ${clusterDetail}`,
|
|
111
|
+
});
|
|
112
|
+
if (!clusterOk) {
|
|
113
|
+
return { ok: false, steps };
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
const response = await fetchWithTimeout(`${config.url}/${config.index}`, {
|
|
117
|
+
method: 'HEAD',
|
|
118
|
+
headers: { Authorization: auth },
|
|
119
|
+
});
|
|
120
|
+
if (response.ok) {
|
|
121
|
+
steps.push({
|
|
122
|
+
name: 'index',
|
|
123
|
+
ok: true,
|
|
124
|
+
detail: `Index "${config.index}" is reachable`,
|
|
125
|
+
});
|
|
126
|
+
return { ok: true, steps };
|
|
127
|
+
}
|
|
128
|
+
if (response.status === 404) {
|
|
129
|
+
const createResponse = await fetchWithTimeout(`${config.url}/${config.index}`, {
|
|
130
|
+
method: 'PUT',
|
|
131
|
+
headers: {
|
|
132
|
+
Authorization: auth,
|
|
133
|
+
'Content-Type': 'application/json',
|
|
134
|
+
},
|
|
135
|
+
body: JSON.stringify(mainIndexMappings),
|
|
136
|
+
});
|
|
137
|
+
if (createResponse.ok) {
|
|
138
|
+
steps.push({
|
|
139
|
+
name: 'index',
|
|
140
|
+
ok: true,
|
|
141
|
+
detail: `Index "${config.index}" did not exist and was created`,
|
|
142
|
+
});
|
|
143
|
+
return { ok: true, steps };
|
|
144
|
+
}
|
|
145
|
+
const body = await readErrorBody(createResponse);
|
|
146
|
+
steps.push({
|
|
147
|
+
name: 'index',
|
|
148
|
+
ok: false,
|
|
149
|
+
detail: `Index "${config.index}" not found (HTTP 404) and auto-create failed `
|
|
150
|
+
+ `(HTTP ${createResponse.status}): ${body}`,
|
|
151
|
+
});
|
|
152
|
+
return { ok: false, steps };
|
|
153
|
+
}
|
|
154
|
+
if (response.status === 401 || response.status === 403) {
|
|
155
|
+
steps.push({
|
|
156
|
+
name: 'index',
|
|
157
|
+
ok: true,
|
|
158
|
+
warning: true,
|
|
159
|
+
detail: `Cannot verify index "${config.index}" (HTTP ${response.status} `
|
|
160
|
+
+ `${response.statusText}) — cluster is up; bulk writes may still work`,
|
|
161
|
+
});
|
|
162
|
+
return { ok: true, steps };
|
|
163
|
+
}
|
|
164
|
+
const body = await readErrorBody(response);
|
|
165
|
+
steps.push({
|
|
166
|
+
name: 'index',
|
|
167
|
+
ok: false,
|
|
168
|
+
detail: `Index "${config.index}" check failed (HTTP ${response.status}): ${body}`,
|
|
169
|
+
});
|
|
170
|
+
return { ok: false, steps };
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
steps.push({
|
|
174
|
+
name: 'index',
|
|
175
|
+
ok: false,
|
|
176
|
+
detail: `Index "${config.index}" check failed — ${formatFetchError(error)}`,
|
|
177
|
+
});
|
|
178
|
+
return { ok: false, steps };
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
exports.probeLogStore = probeLogStore;
|
|
182
|
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I,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC3C,KAAK,CAAC,IAAI,CAAC;YACR,IAAI,EAAE,OAAO;YACb,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,UAAU,MAAM,CAAC,KAAK,wBAAwB,QAAQ,CAAC,MAAM,MAAM,IAAI,EAAE;SACnF,CAAC,CAAC;QACH,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACd,KAAK,CAAC,IAAI,CAAC;YACR,IAAI,EAAE,OAAO;YACb,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,UAAU,MAAM,CAAC,KAAK,oBAAoB,gBAAgB,CAAC,KAAK,CAAC,EAAE;SAC7E,CAAC,CAAC;QACH,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC/B,CAAC;AACJ,CAAC,CAAC;AA9GW,QAAA,aAAa,iBA8GxB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ILogPersisted, Log } from '../interfaces';
|
|
2
|
+
import { RemotePersistConfig } from '../config/remote-persist.config';
|
|
3
|
+
import { StdoutWriter } from '../stdout-writer';
|
|
4
|
+
export declare const serializeLogForPersist: (log: Log, config: Pick<RemotePersistConfig, "appId">, writer?: StdoutWriter) => ILogPersisted;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.serializeLogForPersist = void 0;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
const get_error_infos_1 = require("./get-error-infos");
|
|
9
|
+
const interfaces_1 = require("../interfaces");
|
|
10
|
+
const stdout_writer_1 = require("../stdout-writer");
|
|
11
|
+
const os_1 = __importDefault(require("os"));
|
|
12
|
+
const merge_log_extras_1 = require("./merge-log-extras");
|
|
13
|
+
const formatDate = (date) => {
|
|
14
|
+
if (typeof date === 'string') {
|
|
15
|
+
return (0, moment_1.default)(date).toISOString();
|
|
16
|
+
}
|
|
17
|
+
return date.toISOString();
|
|
18
|
+
};
|
|
19
|
+
const getStdoutWriter = () => {
|
|
20
|
+
var _a, _b, _c;
|
|
21
|
+
return (_c = (_b = (_a = global.logger) === null || _a === void 0 ? void 0 : _a.stdout) === null || _b === void 0 ? void 0 : _b.writer) !== null && _c !== void 0 ? _c : new stdout_writer_1.StdoutWriter();
|
|
22
|
+
};
|
|
23
|
+
const serializeLogForPersist = (log, config, writer = getStdoutWriter()) => {
|
|
24
|
+
var _a;
|
|
25
|
+
const base = {
|
|
26
|
+
type: log.type,
|
|
27
|
+
date: formatDate(log.date),
|
|
28
|
+
context: log.context,
|
|
29
|
+
message: log.message,
|
|
30
|
+
duration: log.duration,
|
|
31
|
+
stdout: writer.formatStdout(log),
|
|
32
|
+
pid: process.pid,
|
|
33
|
+
hostname: os_1.default.hostname(),
|
|
34
|
+
appId: config.appId,
|
|
35
|
+
};
|
|
36
|
+
let document = (0, merge_log_extras_1.mergeLogExtras)(base, log.extras);
|
|
37
|
+
if (log.type !== interfaces_1.LogType.error) {
|
|
38
|
+
return document;
|
|
39
|
+
}
|
|
40
|
+
const errorLog = log;
|
|
41
|
+
if (errorLog.error) {
|
|
42
|
+
const errorInfos = (0, get_error_infos_1.getErrorInfos)(errorLog.error);
|
|
43
|
+
document.error = errorInfos.values;
|
|
44
|
+
const stackFromError = errorInfos.values.stack;
|
|
45
|
+
document.stack =
|
|
46
|
+
(_a = errorLog.stack) !== null && _a !== void 0 ? _a : (typeof stackFromError === 'string' ? stackFromError : undefined);
|
|
47
|
+
}
|
|
48
|
+
else if (errorLog.stack) {
|
|
49
|
+
document.stack = errorLog.stack;
|
|
50
|
+
}
|
|
51
|
+
return document;
|
|
52
|
+
};
|
|
53
|
+
exports.serializeLogForPersist = serializeLogForPersist;
|
|
54
|
+
//# sourceMappingURL=serialize-log-for-persist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize-log-for-persist.js","sourceRoot":"","sources":["../../functions/serialize-log-for-persist.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAwC;AACxC,uDAAkD;AAClD,8CAKuB;AAEvB,oDAAgD;AAChD,4CAAoB;AACpB,yDAAoD;AAEpD,MAAM,UAAU,GAAG,CAAC,IAAqB,EAAU,EAAE;IAClD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,IAAA,gBAAM,EAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IACrC,CAAC;IACD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;AAC7B,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,GAAiB,EAAE;;IACxC,OAAO,MAAA,MAAA,MAAA,MAAM,CAAC,MAAM,0CAAE,MAAM,0CAAE,MAAM,mCAAI,IAAI,4BAAY,EAAE,CAAC;AAC9D,CAAC,CAAC;AAEK,MAAM,sBAAsB,GAAG,CACnC,GAAQ,EACR,MAA0C,EAC1C,SAAuB,eAAe,EAAE,EAC1B,EAAE;;IAChB,MAAM,IAAI,GAAkB;QACzB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC;QAC1B,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC;QAChC,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,QAAQ,EAAE,YAAE,CAAC,QAAQ,EAAE;QACvB,KAAK,EAAE,MAAM,CAAC,KAAK;KACrB,CAAC;IAEF,IAAI,QAAQ,GAAG,IAAA,iCAAc,EAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAEhD,IAAI,GAAG,CAAC,IAAI,KAAK,oBAAO,CAAC,KAAK,EAAE,CAAC;QAC9B,OAAO,QAAQ,CAAC;IACnB,CAAC;IAED,MAAM,QAAQ,GAAG,GAAgB,CAAC;IAElC,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,UAAU,GAAG,IAAA,+BAAa,EAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACjD,QAAQ,CAAC,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC;QACnC,MAAM,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC;QAC/C,QAAQ,CAAC,KAAK;YACX,MAAA,QAAQ,CAAC,KAAK,mCACd,CAAC,OAAO,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACxE,CAAC;SAAM,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;QACzB,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IACnC,CAAC;IAED,OAAO,QAAQ,CAAC;AACnB,CAAC,CAAC;AArCW,QAAA,sBAAsB,0BAqCjC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import 'colors';
|
|
2
|
+
import type { RemotePersistConfig } from '../config/remote-persist.config';
|
|
3
|
+
import { LogStoreProbeReport } from './probe-log-store';
|
|
4
|
+
export declare const writeLogStoreStartupReport: (config: RemotePersistConfig, report: LogStoreProbeReport) => void;
|
|
5
|
+
export declare const writeLogStoreConfigError: (message: string) => void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeLogStoreConfigError = exports.writeLogStoreStartupReport = void 0;
|
|
4
|
+
require("colors");
|
|
5
|
+
const prefix = () => '[RocksterLogger]'.cyan;
|
|
6
|
+
const writeLine = (stream, line) => {
|
|
7
|
+
stream.write(`${line}\n`);
|
|
8
|
+
};
|
|
9
|
+
const writeLogStoreStartupReport = (config, report) => {
|
|
10
|
+
const stream = report.ok ? process.stdout : process.stderr;
|
|
11
|
+
const warnings = report.steps.filter((step) => step.warning);
|
|
12
|
+
if (report.ok && warnings.length === 0) {
|
|
13
|
+
writeLine(stream, `${prefix()} ${'Log store connected'.green.bold}`);
|
|
14
|
+
writeLine(stream, ` ${'url'.gray}: ${config.url}`);
|
|
15
|
+
writeLine(stream, ` ${'index'.gray}: ${config.index.yellow}`);
|
|
16
|
+
writeLine(stream, ` ${'appId'.gray}: ${config.appId.yellow}`);
|
|
17
|
+
for (const step of report.steps) {
|
|
18
|
+
writeLine(stream, ` ${step.name.gray}: ${step.detail.green}`);
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (report.ok && warnings.length > 0) {
|
|
23
|
+
writeLine(stream, `${prefix()} ${'Log store connected with warnings'.yellow.bold}`);
|
|
24
|
+
writeLine(stream, ` ${'url'.gray}: ${config.url}`);
|
|
25
|
+
writeLine(stream, ` ${'index'.gray}: ${config.index.yellow}`);
|
|
26
|
+
writeLine(stream, ` ${'appId'.gray}: ${config.appId.yellow}`);
|
|
27
|
+
for (const step of report.steps) {
|
|
28
|
+
const detail = step.warning ? step.detail.yellow : step.detail.green;
|
|
29
|
+
writeLine(stream, ` ${step.name.gray}: ${detail}`);
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
writeLine(stream, `${prefix()} ${'Log store connection failed'.red.bold}`);
|
|
34
|
+
writeLine(stream, ` ${'url'.gray}: ${config.url}`);
|
|
35
|
+
writeLine(stream, ` ${'index'.gray}: ${config.index.yellow}`);
|
|
36
|
+
writeLine(stream, ` ${'appId'.gray}: ${config.appId.yellow}`);
|
|
37
|
+
for (const step of report.steps) {
|
|
38
|
+
const detail = step.ok ? step.detail.green : step.detail.red;
|
|
39
|
+
writeLine(stream, ` ${step.name.gray}: ${detail}`);
|
|
40
|
+
}
|
|
41
|
+
writeLine(stream, ` ${'hint'.gray}: ${'Check LOGGER_STORE_URL, LOGGER_STORE_USERNAME, '
|
|
42
|
+
+ 'LOGGER_STORE_PASSWORD, and LOGGER_STORE_INDEX in your environment'.italic}`);
|
|
43
|
+
};
|
|
44
|
+
exports.writeLogStoreStartupReport = writeLogStoreStartupReport;
|
|
45
|
+
const writeLogStoreConfigError = (message) => {
|
|
46
|
+
writeLine(process.stderr, `${prefix()} ${'Log store misconfigured'.red.bold}`);
|
|
47
|
+
writeLine(process.stderr, ` ${message.red}`);
|
|
48
|
+
};
|
|
49
|
+
exports.writeLogStoreConfigError = writeLogStoreConfigError;
|
|
50
|
+
//# sourceMappingURL=write-log-store-status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-log-store-status.js","sourceRoot":"","sources":["../../functions/write-log-store-status.ts"],"names":[],"mappings":";;;AAAA,kBAAgB;AAIhB,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC;AAE7C,MAAM,SAAS,GAAG,CAAC,MAA0B,EAAE,IAAY,EAAE,EAAE;IAC5D,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;AAC7B,CAAC,CAAC;AAEK,MAAM,0BAA0B,GAAG,CACvC,MAA2B,EAC3B,MAA2B,EACtB,EAAE;IACP,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IAC3D,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAE7D,IAAI,MAAM,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AQ,EAAE;IAC/D,SAAS,CACN,OAAO,CAAC,MAAM,EACd,GAAG,MAAM,EAAE,IAAI,yBAAyB,CAAC,GAAG,CAAC,IAAI,EAAE,CACrD,CAAC;IACF,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AACjD,CAAC,CAAC;AANW,QAAA,wBAAwB,4BAMnC"}
|
package/index.d.ts
CHANGED
|
@@ -6,3 +6,7 @@ export * from './logger-subscribe';
|
|
|
6
6
|
export * from './interfaces/log';
|
|
7
7
|
export * from './functions/emit-log';
|
|
8
8
|
export * from './interfaces';
|
|
9
|
+
export * from './config/remote-persist.config';
|
|
10
|
+
export * from './services/remote-persist.service';
|
|
11
|
+
export * from './services/log-runtime.service';
|
|
12
|
+
export * from './functions/serialize-log-for-persist';
|
package/index.js
CHANGED
|
@@ -22,4 +22,8 @@ __exportStar(require("./logger-subscribe"), exports);
|
|
|
22
22
|
__exportStar(require("./interfaces/log"), exports);
|
|
23
23
|
__exportStar(require("./functions/emit-log"), exports);
|
|
24
24
|
__exportStar(require("./interfaces"), exports);
|
|
25
|
+
__exportStar(require("./config/remote-persist.config"), exports);
|
|
26
|
+
__exportStar(require("./services/remote-persist.service"), exports);
|
|
27
|
+
__exportStar(require("./services/log-runtime.service"), exports);
|
|
28
|
+
__exportStar(require("./functions/serialize-log-for-persist"), exports);
|
|
25
29
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,6DAA2C;AAC3C,6DAA2C;AAC3C,qDAAmC;AACnC,qDAAmC;AACnC,mDAAiC;AACjC,uDAAqC;AACrC,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,6DAA2C;AAC3C,6DAA2C;AAC3C,qDAAmC;AACnC,qDAAmC;AACnC,mDAAiC;AACjC,uDAAqC;AACrC,+CAA6B;AAC7B,iEAA+C;AAC/C,oEAAkD;AAClD,iEAA+C;AAC/C,wEAAsD"}
|
package/interfaces/log.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Moment } from "moment";
|
|
2
2
|
import { LogType } from "./enums";
|
|
3
|
+
import type { LogExtras } from "@rockster/common/logs";
|
|
3
4
|
export interface ILog {
|
|
4
5
|
date: Moment;
|
|
5
6
|
context: string;
|
|
6
7
|
message: string;
|
|
7
8
|
duration?: number;
|
|
9
|
+
extras?: LogExtras;
|
|
8
10
|
}
|
|
9
11
|
export interface ILogError extends ILog {
|
|
10
12
|
readonly type: LogType.error;
|
|
@@ -29,3 +31,17 @@ export declare class LogError extends Error implements ILogError {
|
|
|
29
31
|
constructor(message: string, date: Moment, context: string, duration?: number);
|
|
30
32
|
}
|
|
31
33
|
export type Log = ILogInfo | ILogWarn | ILogError | ILogDebug;
|
|
34
|
+
export interface ILogPersisted {
|
|
35
|
+
type: LogType;
|
|
36
|
+
date: string;
|
|
37
|
+
context: string;
|
|
38
|
+
message: string;
|
|
39
|
+
duration?: number;
|
|
40
|
+
stack?: string;
|
|
41
|
+
error?: Record<string, unknown>;
|
|
42
|
+
stdout: string[];
|
|
43
|
+
pid: number;
|
|
44
|
+
hostname: string;
|
|
45
|
+
appId: string;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
package/interfaces/log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../interfaces/log.ts"],"names":[],"mappings":";;;AACA,mCAAkC;
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../interfaces/log.ts"],"names":[],"mappings":";;;AACA,mCAAkC;AAqClC,MAAa,QACV,SAAQ,KAAK;IAKb,YACU,OAAe,EACf,IAAY,EACZ,OAAe,EACf,QAAiB;QAExB,KAAK,CAAC,OAAO,CAAC,CAAC;QALR,YAAO,GAAP,OAAO,CAAQ;QACf,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAQ;QACf,aAAQ,GAAR,QAAQ,CAAS;QAN3B,SAAI,GAAkB,eAAO,CAAC,KAAK,CAAC;IASpC,CAAC;CACH;AAdD,4BAcC;AAOE,QAAQ,CAAC"}
|
package/logger.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { Log } from "./interfaces";
|
|
2
|
+
import type { LogExtras } from "@rockster/common/logs";
|
|
3
|
+
export type LogEmitOptions = {
|
|
4
|
+
extras?: LogExtras;
|
|
5
|
+
stack?: string;
|
|
6
|
+
};
|
|
2
7
|
type Dispatcher = {
|
|
3
8
|
(logEvent: string, data: Log): void;
|
|
4
9
|
};
|
|
@@ -12,10 +17,10 @@ export declare class Logger {
|
|
|
12
17
|
protected dispatcher: Dispatcher;
|
|
13
18
|
constructor(context: string);
|
|
14
19
|
debug(_: Object): void;
|
|
15
|
-
log(message: string): void;
|
|
16
|
-
error(error: Error): any;
|
|
17
|
-
error(message: string,
|
|
18
|
-
warn(message: string): void;
|
|
20
|
+
log(message: string, options?: LogEmitOptions): void;
|
|
21
|
+
error(error: Error, options?: LogEmitOptions): any;
|
|
22
|
+
error(message: string, stackOrOptions?: string | LogEmitOptions): any;
|
|
23
|
+
warn(message: string, options?: LogEmitOptions): void;
|
|
19
24
|
throw(error: Error): void;
|
|
20
25
|
}
|
|
21
26
|
export {};
|
package/logger.js
CHANGED
|
@@ -2,11 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Logger = void 0;
|
|
4
4
|
const env_1 = require("./env");
|
|
5
|
+
const log_level_1 = require("./functions/log-level");
|
|
5
6
|
const interfaces_1 = require("./interfaces");
|
|
6
7
|
const worker_threads_1 = require("worker_threads");
|
|
8
|
+
const resolveErrorArgs = (stackOrOptions) => {
|
|
9
|
+
if (typeof stackOrOptions === 'string') {
|
|
10
|
+
return { stack: stackOrOptions, extras: undefined };
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
stack: stackOrOptions === null || stackOrOptions === void 0 ? void 0 : stackOrOptions.stack,
|
|
14
|
+
extras: stackOrOptions === null || stackOrOptions === void 0 ? void 0 : stackOrOptions.extras,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
7
17
|
class Logger {
|
|
8
18
|
constructor(context) {
|
|
9
|
-
var _a;
|
|
10
19
|
this.context = context;
|
|
11
20
|
this.timer = getTimer();
|
|
12
21
|
this.timer.start();
|
|
@@ -24,7 +33,7 @@ class Logger {
|
|
|
24
33
|
}));
|
|
25
34
|
};
|
|
26
35
|
}
|
|
27
|
-
if ((
|
|
36
|
+
if ((0, log_level_1.getLogLevel)() === log_level_1.LogLevel.debug) {
|
|
28
37
|
this.debug = (message) => {
|
|
29
38
|
const content = typeof message === 'string'
|
|
30
39
|
? message
|
|
@@ -42,42 +51,46 @@ class Logger {
|
|
|
42
51
|
}
|
|
43
52
|
}
|
|
44
53
|
debug(_) { }
|
|
45
|
-
log(message) {
|
|
54
|
+
log(message, options) {
|
|
46
55
|
const data = {
|
|
47
56
|
type: interfaces_1.LogType.info,
|
|
48
57
|
message,
|
|
49
58
|
context: this.context,
|
|
50
59
|
date: getNow(),
|
|
51
|
-
duration: this.timer.stop()
|
|
60
|
+
duration: this.timer.stop(),
|
|
61
|
+
extras: options === null || options === void 0 ? void 0 : options.extras,
|
|
52
62
|
};
|
|
53
63
|
this.dispatcher(env_1.logEvent, data);
|
|
54
64
|
this.timer.start();
|
|
55
65
|
}
|
|
56
|
-
error(errorOrMessage,
|
|
66
|
+
error(errorOrMessage, stackOrOptions) {
|
|
57
67
|
const isMessage = typeof (errorOrMessage) === 'string';
|
|
68
|
+
const { stack, extras } = resolveErrorArgs(stackOrOptions);
|
|
58
69
|
const data = {
|
|
59
70
|
type: interfaces_1.LogType.error,
|
|
60
71
|
message: isMessage
|
|
61
72
|
? errorOrMessage
|
|
62
73
|
: errorOrMessage.message,
|
|
63
|
-
stack: stack,
|
|
74
|
+
stack: isMessage ? stack : (stack !== null && stack !== void 0 ? stack : errorOrMessage.stack),
|
|
64
75
|
error: !isMessage
|
|
65
76
|
? errorOrMessage
|
|
66
77
|
: undefined,
|
|
67
78
|
context: this.context,
|
|
68
79
|
date: getNow(),
|
|
69
|
-
duration: this.timer.stop()
|
|
80
|
+
duration: this.timer.stop(),
|
|
81
|
+
extras,
|
|
70
82
|
};
|
|
71
83
|
this.dispatcher(env_1.logEvent, data);
|
|
72
84
|
this.timer.start();
|
|
73
85
|
}
|
|
74
|
-
warn(message) {
|
|
86
|
+
warn(message, options) {
|
|
75
87
|
const data = {
|
|
76
88
|
type: interfaces_1.LogType.warn,
|
|
77
89
|
message,
|
|
78
90
|
context: this.context,
|
|
79
91
|
date: getNow(),
|
|
80
|
-
duration: this.timer.stop()
|
|
92
|
+
duration: this.timer.stop(),
|
|
93
|
+
extras: options === null || options === void 0 ? void 0 : options.extras,
|
|
81
94
|
};
|
|
82
95
|
this.dispatcher(env_1.logEvent, data);
|
|
83
96
|
this.timer.start();
|
package/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../logger.ts"],"names":[],"mappings":";;;AAAA,+BAAiC;AACjC,6CAIsB;
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../logger.ts"],"names":[],"mappings":";;;AAAA,+BAAiC;AACjC,qDAA8D;AAC9D,6CAIsB;AAEtB,mDAGwB;AAcxB,MAAM,gBAAgB,GAAG,CAAC,cAAwC,EAAE,EAAE;IACnE,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE,CAAC;QACtC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IACvD,CAAC;IACD,OAA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|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
2
|
+
"name": "@rockster/logger",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"main": "index",
|
|
5
|
+
"types": "index.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"pre:build": "rm -rf ./dist && mkdir ./dist && cp package.json ./dist",
|
|
8
|
+
"build:prod": "npm run pre:build && tsc -p tsconfig.prod.json",
|
|
9
|
+
"build:dev": "npm run pre:build && tsc -p tsconfig.prod.json -w",
|
|
10
|
+
"post:publish": "cd ./dist && npm publish"
|
|
11
|
+
},
|
|
12
|
+
"author": "Hubseat",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://git.hubseat.io/rockster/rockster-logger"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@rockster/common": "0.1.1",
|
|
23
|
+
"colors": "^1.4.0",
|
|
24
|
+
"intercept-stdout": "^0.1.2",
|
|
25
|
+
"moment": "^2.29.4",
|
|
26
|
+
"reflect-metadata": "^0.1.13",
|
|
27
|
+
"uuid": "^9.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/intercept-stdout": "^0.1.0",
|
|
31
|
+
"@types/node": "^20.1.3",
|
|
32
|
+
"@types/uuid": "^9.0.1",
|
|
33
|
+
"typescript": "^5.0.4"
|
|
34
|
+
}
|
|
35
35
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import 'colors';
|
|
2
|
+
import { ILogHook, ILogSettings } from '@rockster/common/logs';
|
|
3
|
+
import { RemotePersistConfig } from '../config/remote-persist.config';
|
|
4
|
+
import { ILogPersisted } from '../interfaces';
|
|
5
|
+
import { OpenSearchClient } from './opensearch-client';
|
|
6
|
+
type HookBuffer = {
|
|
7
|
+
logs: ILogPersisted[];
|
|
8
|
+
startedAt: number;
|
|
9
|
+
};
|
|
10
|
+
type CompiledHook = ILogHook & {
|
|
11
|
+
matchCondition: (log: ILogPersisted) => boolean;
|
|
12
|
+
shouldDispatch: (state: {
|
|
13
|
+
count: number;
|
|
14
|
+
windowMinutes: number;
|
|
15
|
+
}) => boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare class SettingsJob {
|
|
18
|
+
protected config: RemotePersistConfig;
|
|
19
|
+
protected client: OpenSearchClient;
|
|
20
|
+
settings: ILogSettings;
|
|
21
|
+
protected lastLoggedSignature: string | null;
|
|
22
|
+
constructor(config: RemotePersistConfig);
|
|
23
|
+
load(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare class HookEngine {
|
|
26
|
+
protected config: RemotePersistConfig;
|
|
27
|
+
protected client: OpenSearchClient;
|
|
28
|
+
protected hooks: CompiledHook[];
|
|
29
|
+
protected buffers: Map<string, Map<string, HookBuffer>>;
|
|
30
|
+
protected ready: Promise<void>;
|
|
31
|
+
protected lastLoggedSignature: string | null;
|
|
32
|
+
constructor(config: RemotePersistConfig);
|
|
33
|
+
start(): void;
|
|
34
|
+
reload(): Promise<void>;
|
|
35
|
+
protected compileHook(id: string, source?: ILogHook): CompiledHook | null;
|
|
36
|
+
onLog(log: ILogPersisted): void;
|
|
37
|
+
protected processLog(log: ILogPersisted): void;
|
|
38
|
+
protected dispatch(hook: CompiledHook, logs: ILogPersisted[], aggregationKey?: string): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
export declare class RetentionJob {
|
|
41
|
+
protected config: RemotePersistConfig;
|
|
42
|
+
protected settingsJob: SettingsJob;
|
|
43
|
+
protected client: OpenSearchClient;
|
|
44
|
+
protected dailyTimer: ReturnType<typeof setInterval> | null;
|
|
45
|
+
constructor(config: RemotePersistConfig, settingsJob: SettingsJob);
|
|
46
|
+
start(): void;
|
|
47
|
+
stop(): void;
|
|
48
|
+
run(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export declare class LogRuntimeService {
|
|
51
|
+
protected config: RemotePersistConfig;
|
|
52
|
+
protected client: OpenSearchClient;
|
|
53
|
+
protected hookEngine: HookEngine;
|
|
54
|
+
protected settingsJob: SettingsJob;
|
|
55
|
+
protected retentionJob: RetentionJob;
|
|
56
|
+
protected reloadTimer: ReturnType<typeof setInterval> | null;
|
|
57
|
+
constructor(config: RemotePersistConfig);
|
|
58
|
+
start(): void;
|
|
59
|
+
registerApp(): Promise<void>;
|
|
60
|
+
protected reloadAll(): Promise<void>;
|
|
61
|
+
onLog(log: ILogPersisted): void;
|
|
62
|
+
}
|
|
63
|
+
export declare const initLogRuntime: (config: RemotePersistConfig) => LogRuntimeService;
|
|
64
|
+
export declare const getLogRuntime: () => LogRuntimeService | null;
|
|
65
|
+
export {};
|