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
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
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
adds a new consoleLogger in that is a simple object. prefixes w/ the level + has colours so it's obv.
Tests
hit an endpoint on our backend
there should be logs recorded, with colours
notes
init function on cloudWatchLogger was copied over as-is and this wasn't called previously but is now.
formatter was chosen to be placed on the main logger - we can change this if needed?
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.
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
string
, the method takesstring | InternalError
Logger
interface + allows us to inject loggers into ituseFormatter
method to allow people to customise their log formats (idk if this should be on main or sub loggers ._. feel free to discuss)consoleLogger
in that is a simple object. prefixes w/ the level + has colours so it's obv.Tests
notes
init
function oncloudWatchLogger
was copied over as-is and this wasn't called previously but is now.formatter
was chosen to be placed on the main logger - we can change this if needed?const defaultImport = require("module")
had to be changed toconst defaultImport = require("module").default
due to how default imports work in es6 vs node (see here) for details.