Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated Log hook #1279

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/blog/assets/version-5.0-is-here/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions docs/blog/version-5.0-release-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Version 5.0 release notes
author: Loïc Poullain
author_title: Creator of FoalTS. Software engineer.
author_url: https://loicpoullain.com
author_image_url: https://avatars1.githubusercontent.com/u/13604533?v=4
image: blog/twitter-banners/version-5.0-release-notes.png
tags: [release]
---

![Banner](./assets/version-5.0-is-here/banner.png)

Version 5.0 of [Foal](https://foalts.org/) is out!

<!--truncate-->

## Removal of depreacted components

- The deprecated hook `@Log` has been removed. To replace it, you can use the `Logger` service in a custom `@Hook`.
6 changes: 4 additions & 2 deletions docs/docs/architecture/architecture-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Controllers may have sub-controllers. Hooks can be attached to the controllers o
Here's an example of what a FoalTS application may look like.

```typescript
import { Context, controller, Get, HttpResponseNotFound, HttpResponseOK, Log } from '@foal/core';
import { Context, controller, Get, Hook, HttpResponseNotFound, HttpResponseOK } from '@foal/core';
import { JWTRequired } from '@foal/jwt';

@JWTRequired()
Expand Down Expand Up @@ -105,7 +105,9 @@ class ApiController {
}
}

@Log('Receiving a request...')
@Hook(() => {
console.log('Receiving a request...')
})
class AppController {
subControllers = [
controller('/api', ApiController)
Expand Down
3 changes: 1 addition & 2 deletions docs/docs/architecture/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ They improve code readability and make unit testing easier.
Foal provides a number of hooks to handle the most common scenarios.

- `ValidateBody`, `ValidateHeader`, `ValidatePathParam`, `ValidateCookie` and `ValidateQueryParam` validate the format of the incoming HTTP requests (see [Validation](../common/validation-and-sanitization.md)).
- `Log` displays information on the request (see [Logging](../common/logging.md)).
- `JWTRequired`, `JWTOptional`, `UseSessions` authenticate the user by filling the `ctx.user` property.
- `PermissionRequired` restricts the route access to certain users.

Expand Down Expand Up @@ -73,7 +72,7 @@ If the user makes a POST request to `/products` whereas she/he is not authentica
> If you need to apply a hook globally, you just have to make it decorate the root controller: `AppController`.
>
> ```typescript
> @Log('Request body:', { body: true })
> @UseSessions()
> export class AppController {
> // ...
> }
Expand Down
33 changes: 0 additions & 33 deletions docs/docs/common/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,36 +274,3 @@ logger.addTransport((level: 'debug'|'warn'|'info'|'error', log: string) => {
// Do something
})
```

## Logging Hook (deprecated)

> This hook is deprecated and will be removed in a next release. Use the `Logger` service in a custom hook instead.

FoalTS provides a convenient hook for logging debug messages: `Log(message: string, options: LogOptions = {})`.

```typescript
interface LogOptions {
body?: boolean;
params?: boolean;
headers?: string[]|boolean;
query?: boolean;
}
```

*Example:*
```typescript
import { Get, HttpResponseOK, Log } from '@foal/core';

@Log('AppController', {
body: true,
headers: [ 'X-CSRF-Token' ],
params: true,
query: true
})
export class AppController {
@Get()
index() {
return new HttpResponseOK();
}
}
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
controller,
createApp,
Get,
// Hook,
HttpResponseNotFound,
HttpResponseOK,
// Log,
} from '@foal/core';
import { getSecretOrPrivateKey, JWTRequired } from '@foal/jwt';

Expand Down Expand Up @@ -58,7 +58,9 @@ describe('Feature: Setting up a simple application', () => {
}

// Commented in this test to avoid noise in the terminal.
// @Log('Receiving a request...')
// @Hook(() => {
// console.log('Receiving a request...')
// })
class AppController {
subControllers = [
controller('/api', ApiController)
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/common/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { controller } from './controller.util';
export { displayServerURL } from './display-server-url.util';
export { isInFile } from './is-in-file.util';
export { Log, LogOptions } from './log.hook';
export { streamToBuffer } from './stream-to-buffer';
123 changes: 0 additions & 123 deletions packages/core/src/common/utils/log.hook.spec.ts

This file was deleted.

60 changes: 0 additions & 60 deletions packages/core/src/common/utils/log.hook.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export {
AsyncService,
File,
FileList,
Log,
LogOptions,
UserRequired,
ValidateBody,
ValidateCookie,
Expand Down
Loading