isomerpages / isomercms-backend

A static website builder and host for the Singapore Government
5 stars 1 forks source link

ref(logger): refactor logger impl to be separate from interface #784

Closed seaerchin closed 1 year ago

seaerchin commented 1 year ago

Problem

Previously, our loggers were a thin wrapper over CloudWatchLogger and adding an external logging source was difficult. This was because our loggers depended on a concrete implementation rather than an interface.

Closes IS-209

Solution

  1. separate the logging interface from the logger
    • this can be further extended when we refactor our errors, so that instead of taking string, the method takes string | InternalError
  2. add a main logger that exposes the Logger interface + allows us to inject loggers into it
    • this also exposes a useFormatter method to allow people to customise their log formats (idk if this should be on main or sub loggers ._. feel free to discuss)
    • this handles calling our sub loggers
  3. adds a new consoleLogger in that is a simple object. prefixes w/ the level + has colours so it's obv.

Tests

  1. hit an endpoint on our backend
  2. there should be logs recorded, with colours

notes

  1. init function on cloudWatchLogger was copied over as-is and this wasn't called previously but is now.
  2. formatter was chosen to be placed on the main logger - we can change this if needed?
  3. const defaultImport = require("module") had to be changed to const defaultImport = require("module").default due to how default imports work in es6 vs node (see here) for details.
seaerchin commented 1 year ago

npm run build fails :(

hmm - we actually lack a build step in ci; will be adding this.