From 5d797ca19744590401007c061c5dc9077a9f67df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Poullain?= Date: Wed, 18 Oct 2023 13:18:50 +0200 Subject: [PATCH] Use Foal logger in examples --- packages/examples/config/default.yml | 2 -- packages/examples/config/development.yml | 5 +++++ .../examples/src/app/controllers/profile.controller.ts | 7 +++++-- 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 packages/examples/config/development.yml diff --git a/packages/examples/config/default.yml b/packages/examples/config/default.yml index 304432adae..ee139f9d52 100644 --- a/packages/examples/config/default.yml +++ b/packages/examples/config/default.yml @@ -3,8 +3,6 @@ port: 3001 settings: openapi: useHooks: true - debug: true - loggerFormat: dev session: secret: 'my secret' staticPath: 'public/' diff --git a/packages/examples/config/development.yml b/packages/examples/config/development.yml new file mode 100644 index 0000000000..c4ec70c649 --- /dev/null +++ b/packages/examples/config/development.yml @@ -0,0 +1,5 @@ +settings: + debug: true + loggerFormat: dev + logger: + format: dev \ No newline at end of file diff --git a/packages/examples/src/app/controllers/profile.controller.ts b/packages/examples/src/app/controllers/profile.controller.ts index e8e9a34034..21e21eeb98 100644 --- a/packages/examples/src/app/controllers/profile.controller.ts +++ b/packages/examples/src/app/controllers/profile.controller.ts @@ -1,5 +1,5 @@ import { - ApiInfo, ApiServer, Context, dependency, Get, Hook, HttpResponseNotFound, HttpResponseRedirect, Post, render, UserRequired + ApiInfo, ApiServer, Context, dependency, Get, Hook, HttpResponseNotFound, HttpResponseRedirect, Logger, Post, render, UserRequired } from '@foal/core'; import { Disk, ParseAndValidateFiles } from '@foal/storage'; @@ -16,6 +16,9 @@ export class ProfileController { @dependency disk: Disk; + @dependency + logger: Logger; + @Post('/image') @Hook(async ctx => { ctx.user = await User.findOneBy({ email: 'john@foalts.org' }); }) @UserRequired() @@ -28,7 +31,7 @@ export class ProfileController { try { await this.disk.delete(user.profile); } catch (error: any) { - console.log(error.message); + this.logger.error(error.message, { err: error }); } }