@mereb/shared-packages 0.0.29 → 0.0.31
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/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAsCxB,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAsCxB,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,CA4DtD"}
|
package/dist/logger.js
CHANGED
|
@@ -32,6 +32,9 @@ export function createLogger(name) {
|
|
|
32
32
|
const splunkConfig = resolveSplunkConfig(name);
|
|
33
33
|
const baseLevel = process.env.LOG_LEVEL ?? 'info';
|
|
34
34
|
const isProd = process.env.NODE_ENV === 'production';
|
|
35
|
+
if (!splunkConfig && process.env.SPLUNK_HEC_URL) {
|
|
36
|
+
console.warn('Splunk token missing; HEC logging disabled');
|
|
37
|
+
}
|
|
35
38
|
if (isProd) {
|
|
36
39
|
transports.push({ stream: process.stdout });
|
|
37
40
|
}
|
|
@@ -44,6 +47,11 @@ export function createLogger(name) {
|
|
|
44
47
|
}
|
|
45
48
|
if (splunkConfig) {
|
|
46
49
|
const transportPath = join(dirname(fileURLToPath(import.meta.url)), 'transports', 'splunk-transport.js');
|
|
50
|
+
console.info('Splunk logging enabled', {
|
|
51
|
+
url: splunkConfig.url,
|
|
52
|
+
index: splunkConfig.index,
|
|
53
|
+
source: splunkConfig.source
|
|
54
|
+
});
|
|
47
55
|
const splunkStream = pino.transport({
|
|
48
56
|
target: transportPath,
|
|
49
57
|
level: 'info',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splunk-transport.d.ts","sourceRoot":"","sources":["../../src/transports/splunk-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"splunk-transport.d.ts","sourceRoot":"","sources":["../../src/transports/splunk-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAG5C,KAAK,sBAAsB,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,wBAA8B,eAAe,CAAC,IAAI,EAAE,sBAAsB,yDAwDzE"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import build from 'pino-abstract-transport';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
2
3
|
export default async function splunkTransport(opts) {
|
|
3
4
|
const url = opts.url;
|
|
4
5
|
const token = opts.token;
|
|
@@ -19,11 +20,13 @@ export default async function splunkTransport(opts) {
|
|
|
19
20
|
continue;
|
|
20
21
|
}
|
|
21
22
|
const controller = AbortSignal.timeout(timeoutMs);
|
|
22
|
-
|
|
23
|
+
const requestId = randomUUID();
|
|
24
|
+
const response = await fetch(url, {
|
|
23
25
|
method: 'POST',
|
|
24
26
|
headers: {
|
|
25
27
|
Authorization: `Splunk ${token}`,
|
|
26
|
-
'Content-Type': 'application/json'
|
|
28
|
+
'Content-Type': 'application/json',
|
|
29
|
+
'X-Splunk-Request-Channel': requestId
|
|
27
30
|
},
|
|
28
31
|
body: JSON.stringify({
|
|
29
32
|
event: payload,
|
|
@@ -35,6 +38,17 @@ export default async function splunkTransport(opts) {
|
|
|
35
38
|
}).catch((err) => {
|
|
36
39
|
console.error('Failed to send log to Splunk HEC', err);
|
|
37
40
|
});
|
|
41
|
+
if (response == null) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
const body = await response.text().catch(() => '');
|
|
46
|
+
console.error('Splunk HEC responded with error', {
|
|
47
|
+
status: response.status,
|
|
48
|
+
statusText: response.statusText,
|
|
49
|
+
body
|
|
50
|
+
});
|
|
51
|
+
}
|
|
38
52
|
}
|
|
39
53
|
});
|
|
40
54
|
}
|