@larvit/log
Zero dependency, structured logging with a simple interface.
Installation
npm i @larvit/log
or yarn add @larvit/log
Usage
import { Log } from "@larvit/log";
const log = new Log();
log.error("Apocalypse! :O");
log.warn("The chaos is near");
log.info("All is well, but this message is important");
log.verbose("Extra info, likely good in a production environment");
log.debug("A lot of detailed logs to debug your application");
log.silly("Open the flood gates!");
Configuration
Log level
const log = new Log("info");
Will only output error, warn and info logs. This is the default. All possible options: "error", "warn", "info", "verbose", "debug", "silly" and "none".
Other options
const log = new Log({
context: {
key: "string",
anotherKey: "string",
},
format: "text",
logLevel: "info",
entryFormatter: ({ logLevel, metadata, msg }) => {
return `${logLevel}: ${msg} ${JSON.stringify(metadata)}`;
},
stdout: console.log,
stderr: console.error,
});
Metadata
log.info("foo", { hey: "luring" });
--> 2022-09-24T23:40:39Z [info] foo {"hey":"luring"}