Tie Logger
👔 Fully typed minimal platform-agnostic logger
📦 Installation
- Using
npm
npm i @diotoborg/distinctio-a-doloremque
- Using
Yarn
yarn add @diotoborg/distinctio-a-doloremque
- Using
pnpm
pnpm add @diotoborg/distinctio-a-doloremque
Usage
Initialization
import { Logger, logLevels, filter } from "@diotoborg/distinctio-a-doloremque";
export const logger = new Logger(
"app",
logLevels(),
{
appVersion: "3.1"
moduleName: "root",
moduleVersion: "1.0.0"
}
);
export const child = logger.child(
"auth",
{ moduleName: "auth", moduleVersion: "0.3.1" }
);
const criticalLogs = [];
const unsubscribe = logger.subscribe(
(log) => console.log(...log.message.parts),
filter(">=", "warn", (log) => criticalLogs.push(log))
)
process.on("SIGINT", () => {
unsubscribe();
})
Logging
import { child, logger } from "./logger.js";
const PORT = parseInt(process.env.PORT) || 3000;
logger.subscribe(log => console.log(log));
child.log.debug`Application initialized. Port: ${{ port: PORT }}. Environment: ${{process.env}}`;
Log format
({
level: "debug",
message: {
template:
"Application initialized. Port: {port}. Environment: {SHELL,COLORTERM,PWD}",
plain:
'Application initialized. Port: 3000. Environment: {"SHELL":"/bin/bash","COLORTERM":"truecolor","PWD":"/home/alexxgrib/Projects/@diotoborg/distinctio-a-doloremque"}',
parts: [
"Application initialized. Port:",
{ port: 3000 },
". Environment: ",
{
SHELL: "/bin/bash",
COLORTERM: "truecolor",
PWD: "/home/alexxgrib/Projects/@diotoborg/distinctio-a-doloremque"
}
]
},
data: {
appVersion: "3.1",
moduleName: "auth",
moduleVersion: "0.3.1",
port: 3000,
SHELL: "/bin/bash",
COLORTERM: "truecolor",
PWD: "/home/alexxgrib/Projects/@diotoborg/distinctio-a-doloremque"
},
context: {
name: "auth",
path: ["app", "auth"]
},
origin: child
});