@pagopa/winston-ts
v2.2.0
Published
fp-ts wrapper for logging with winston logger
Downloads
400
Keywords
Readme
@pagopa/winston-ts
fp-ts wrapper to use winston logging library inside a pipe.
Quick Start
The index define an object for each supported fp-ts monad (Option, Either, ...) implementing the relative log functions (log, tarce, info, warn and error). A log function could be used directly in the pipe, without output changes.
Example
import { pipe } from "fp-ts/lib/function";
import * as TE from "fp-ts/TaskEither";
import * as L from "@pagopa/winston-ts";
L.useWinston(L.withConsole()); // configure the default winston tranport
pipe(
{ name: "Bob" },
TE.right,
L.taskEither.info("INFO!"), // log an info if the taskEither is right
L.taskEither.debug(i => `DEBUG ${i.name}`), // log a debug if the taskEither is right using data conteined in the monad (rigth)
TE.chain(i => TE.left(Error(i.name))),
L.taskEither.debugLeft(i => `DEBUG ${i}`) // log a debug if the taskEither is left using data contained in the monad (left)
);
About Side-Effect
A winston logger is backed by a node stream. Each log call will be an asynchronous 'fire and forget': no further error will be throw by winston transport.
About Azure
This logger could be used in an Azure context using the AzureContextTransport. NB: if you use a Function App, the transport logging level must be set to FINEST_LEVEL. The final logging level will be the one set in the function host.json.
export const run = (context: Context) => {
...
L.useWinston(new AzureContextTransport(() => context.log, { level: FINEST_LEVEL })); // configure the default winston tranport
...
}