@pands/logger 0.0.0-stage → 0.1.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/dist/index.d.ts +13 -0
- package/dist/index.js +52 -0
- package/package.json +38 -3
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DestinationStream, Logger as Logger$1 } from 'pino';
|
|
2
|
+
|
|
3
|
+
type Logger = Logger$1;
|
|
4
|
+
interface CreateLoggerOptions {
|
|
5
|
+
service: string;
|
|
6
|
+
project?: string;
|
|
7
|
+
env?: string;
|
|
8
|
+
level?: string;
|
|
9
|
+
destination?: DestinationStream;
|
|
10
|
+
}
|
|
11
|
+
declare function createLogger(options: CreateLoggerOptions): Logger;
|
|
12
|
+
|
|
13
|
+
export { type CreateLoggerOptions, type Logger, createLogger };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { trace } from "@opentelemetry/api";
|
|
3
|
+
import pino from "pino";
|
|
4
|
+
function createLogger(options) {
|
|
5
|
+
const level = options.level ?? process.env.LOG_LEVEL ?? "info";
|
|
6
|
+
const project = options.project ?? process.env.PAND_PROJECT ?? "pand";
|
|
7
|
+
const env = options.env ?? process.env.PAND_ENV ?? "dev";
|
|
8
|
+
const pinoOptions = {
|
|
9
|
+
level,
|
|
10
|
+
base: {
|
|
11
|
+
service: options.service,
|
|
12
|
+
project,
|
|
13
|
+
env
|
|
14
|
+
},
|
|
15
|
+
redact: {
|
|
16
|
+
paths: [
|
|
17
|
+
"req.headers.authorization",
|
|
18
|
+
"req.headers.cookie",
|
|
19
|
+
'req.headers["x-pand-internal-token"]',
|
|
20
|
+
"password",
|
|
21
|
+
"secret"
|
|
22
|
+
],
|
|
23
|
+
censor: "[REDACTED]"
|
|
24
|
+
},
|
|
25
|
+
formatters: {
|
|
26
|
+
level(label) {
|
|
27
|
+
return { level: label };
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
mixin() {
|
|
31
|
+
const span = trace.getActiveSpan();
|
|
32
|
+
if (!span) {
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
const ctx = span.spanContext();
|
|
36
|
+
if (!ctx || !ctx.traceId || ctx.traceId === "00000000000000000000000000000000") {
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
trace_id: ctx.traceId,
|
|
41
|
+
span_id: ctx.spanId
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
if (options.destination) {
|
|
46
|
+
return pino(pinoOptions, options.destination);
|
|
47
|
+
}
|
|
48
|
+
return pino(pinoOptions);
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
createLogger
|
|
52
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pands/logger",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@opentelemetry/api": "~1.9.0",
|
|
16
|
+
"pino": "^9.6.0",
|
|
17
|
+
"pino-pretty": "^13.0.0"
|
|
18
|
+
},
|
|
19
|
+
"description": "Structured JSON logging and telemetry redaction for Pand services",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "Mehdi Nosrati",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/MehdiNosrati/pand.git"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/MehdiNosrati/pand#readme",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/MehdiNosrati/pand/issues"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"test": "vitest run"
|
|
40
|
+
}
|
|
6
41
|
}
|
package/README.md
DELETED