Skip to content

Commit

Permalink
fix(platform-log-middleware): deprecate platform-log-middleware module
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Oct 2, 2024
1 parent 9dc4abb commit c74e252
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 25 deletions.
5 changes: 4 additions & 1 deletion packages/platform/platform-log-middleware/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tsed/platform-log-middleware",
"description": "Log request middleware module for Ts.ED Framework",
"description": "Log request middleware module for Ts.ED Framework (deprecated)",
"type": "module",
"version": "8.0.0-alpha.7",
"source": "./src/index.ts",
Expand Down Expand Up @@ -49,5 +49,8 @@
"@tsed/platform-params": {
"optional": false
}
},
"publishConfig": {
"distTag": "deprecated"
}
}
55 changes: 53 additions & 2 deletions packages/platform/platform-log-middleware/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</p>

<div align="center">
<h1>@tsed/platform-log-request</h1>
<h1>@tsed/platform-log-middleware</h1>

[![Build & Release](https://github.com/tsedio/tsed/workflows/Build%20&%20Release/badge.svg)](https://github.com/tsedio/tsed/actions?query=workflow%3A%22Build+%26+Release%22)
[![PR Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/tsedio/tsed/blob/master/CONTRIBUTING.md)
Expand All @@ -29,10 +29,61 @@

A package of Ts.ED framework. See website: https://tsed.io/

# Important

This module is deprecated. Please use @tsed/platform-log-request instead.

# Installation

```bash
npm install --save @tsed/platform-params
npm install --save @tsed/platform-log-middleware
```

## Configuration (Ts.ED v8 only)

```ts
import {Configuration} from "@tsed/di";
import {PlatformLogMiddleware} from "@tsed/platform-log-middleware";

@Configuration({
logger: {
/**
* Fields displayed when a request is logged. Possible values: `reqId`, `method`, `url`, `headers`, `body`, `query`,`params`, `duration`.
*/
requestFields: ["reqId", "method", "url", "duration", "route"],
/**
* Log all incoming request. By default, is true and print the configured `logger.requestFields`.
*/
logRequest: true,
/**
* Log start of all incoming request. By default, is false
*/
logStart: false,
/**
* Log end of all incoming request. By default, is true
*/
logEnd: true
},
middlewares: [
"cors",
"cookie-parser",
{
use: "compression",
options: {
brotli: {
enabled: true,
zlib: {}
}
}
},
"method-override",
"json-parser",
{use: "urlencoded-parser", options: {extended: true}},
/// add the platform log middleware here
PlatformLogMiddleware
]
})
class Server {}
```

## Contributors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,28 +285,6 @@ describe("PlatformLogMiddleware", () => {
})
);
});
it("should log debug without request", async () => {
// GIVEN
const {request, ctx, middleware} = await createMiddlewareFixture();
request.originalUrl = "originalUrl";
// WHEN
middleware.use(ctx);

// THEN
ctx.logger.debug(
{
event: "event"
},
false
);
// THEN
expect(PlatformTest.injector.logger.debug).toHaveBeenCalledWith(
expect.objectContaining({
event: "event",
reqId: "id"
})
);
});
});
});
});

0 comments on commit c74e252

Please sign in to comment.