@x1-labs/logging-express 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/express.d.ts +8 -0
- package/dist/express.js +38 -0
- package/dist/express.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Options as PinoHttpOptions, HttpLogger } from 'pino-http';
|
|
2
|
+
import type { CreateLoggerOptions } from '@x1-labs/logging';
|
|
3
|
+
export interface CreateExpressLoggerOptions extends CreateLoggerOptions {
|
|
4
|
+
autoLogging?: boolean;
|
|
5
|
+
forwardedIp?: boolean;
|
|
6
|
+
pinoHttpOptions?: Partial<PinoHttpOptions>;
|
|
7
|
+
}
|
|
8
|
+
export declare function createExpressLogger(options?: CreateExpressLoggerOptions): HttpLogger;
|
package/dist/express.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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.createExpressLogger = createExpressLogger;
|
|
7
|
+
const pino_http_1 = __importDefault(require("pino-http"));
|
|
8
|
+
const logging_1 = require("@x1-labs/logging");
|
|
9
|
+
function createExpressLogger(options = {}) {
|
|
10
|
+
const level = (0, logging_1.resolveLogLevel)(options.level);
|
|
11
|
+
const json = options.json ?? process.env.LOG_FORMAT === 'json';
|
|
12
|
+
const autoLogging = options.autoLogging ?? true;
|
|
13
|
+
const forwardedIp = options.forwardedIp ?? true;
|
|
14
|
+
const httpOptions = {
|
|
15
|
+
level,
|
|
16
|
+
autoLogging,
|
|
17
|
+
formatters: {
|
|
18
|
+
level: (label) => ({ level: label.toUpperCase() }),
|
|
19
|
+
},
|
|
20
|
+
...(options.name ? { name: options.name } : {}),
|
|
21
|
+
...(!json
|
|
22
|
+
? { transport: { target: 'pino-pretty', options: { singleLine: true } } }
|
|
23
|
+
: {}),
|
|
24
|
+
...(forwardedIp
|
|
25
|
+
? {
|
|
26
|
+
customProps: (req) => ({
|
|
27
|
+
ip: req.headers['x-forwarded-for']
|
|
28
|
+
?.split(',')[0]
|
|
29
|
+
?.trim() ?? req.socket?.remoteAddress,
|
|
30
|
+
}),
|
|
31
|
+
}
|
|
32
|
+
: {}),
|
|
33
|
+
...options.pinoOptions,
|
|
34
|
+
...options.pinoHttpOptions,
|
|
35
|
+
};
|
|
36
|
+
return (0, pino_http_1.default)(httpOptions);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":";;;;;AAeA,kDAiCC;AA/CD,0DAAiC;AAEjC,8CAAmD;AAYnD,SAAgB,mBAAmB,CACjC,UAAsC,EAAE;IAExC,MAAM,KAAK,GAAG,IAAA,yBAAe,EAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,KAAK,MAAM,CAAC;IAC/D,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC;IAChD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC;IAEhD,MAAM,WAAW,GAAoB;QACnC,KAAK;QACL,WAAW;QACX,UAAU,EAAE;YACV,KAAK,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;SAC3D;QACD,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,GAAG,CAAC,CAAC,IAAI;YACP,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE;YACzE,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,WAAW;YACb,CAAC,CAAC;gBACE,WAAW,EAAE,CAAC,GAAoB,EAAE,EAAE,CAAC,CAAC;oBACtC,EAAE,EACC,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAwB;wBACpD,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;wBACf,EAAE,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,aAAa;iBAC1C,CAAC;aACH;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,OAAO,CAAC,WAAW;QACtB,GAAG,OAAO,CAAC,eAAe;KAC3B,CAAC;IAEF,OAAO,IAAA,mBAAQ,EAAC,WAAW,CAAC,CAAC;AAC/B,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createExpressLogger = void 0;
|
|
4
|
+
var express_1 = require("./express");
|
|
5
|
+
Object.defineProperty(exports, "createExpressLogger", { enumerable: true, get: function () { return express_1.createExpressLogger; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAgD;AAAvC,8GAAA,mBAAmB,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@x1-labs/logging-express",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Express pino-http logging middleware",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"default": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/x1-labs/ts-logging-common.git",
|
|
16
|
+
"directory": "packages/logging-express"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.build.json",
|
|
20
|
+
"prepublishOnly": "bun run build",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"lint": "eslint \"src/**/*.ts\" --fix",
|
|
23
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
24
|
+
"check": "bun run lint && bun run typecheck && bun run format --check"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@x1-labs/logging": "workspace:*"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"express": "^4.0.0 || ^5.0.0",
|
|
31
|
+
"pino-http": "^10.0.0",
|
|
32
|
+
"pino-pretty": "^13.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"pino-pretty": {
|
|
36
|
+
"optional": true
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist"
|
|
41
|
+
],
|
|
42
|
+
"license": "MIT"
|
|
43
|
+
}
|