@hishprorg/ad-minima v2.6.74
Tie Logger
👔 Fully typed minimal platform-agnostic logger
📦 Installation
- Using
npm
npm i @hishprorg/ad-minima
- Using
Yarn
yarn add @hishprorg/ad-minima
- Using
pnpm
pnpm add @hishprorg/ad-minima
Usage
Initialization
/** @file: logger.js */
import { Logger, logLevels, filter } from "@hishprorg/ad-minima";
export const logger = new Logger(
"app", // Root logger name
logLevels(), // Define log levels. By default are: verbose, debug, info, warn, error, fatal
// You can use custom levels by using
// logLevels("info", "warn", "error")
{
// Custom data
appVersion: "3.1"
moduleName: "root",
moduleVersion: "1.0.0"
}
);
export const child = logger.child(
// Child logger name
"auth",
// Child logger data
{ moduleName: "auth", moduleVersion: "0.3.1" }
);
const criticalLogs = [];
const unsubscribe = logger.subscribe(
// Subscribe to all logs, they go to console
(log) => console.log(...log.message.parts),
// All logs, that level is greater or equal than "warn" will be added to critical logs
// Severity is determined by index of level in levels array
// Current array is: verbose, debug, info, warn, error, fatal
// [less] <<< ^^^^ >> [greater]
filter(">=", "warn", (log) => criticalLogs.push(log))
)
process.on("SIGINT", () => {
unsubscribe();
})
Logging
/** @file: index.js */
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}}`;
// Level: ^^^^^
// Here goes app
Log format
({
// One of defined levels
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/@hishprorg/ad-minima"}',
parts: [
"Application initialized. Port:",
{ port: 3000 },
". Environment: ",
{
SHELL: "/bin/bash",
COLORTERM: "truecolor",
PWD: "/home/alexxgrib/Projects/@hishprorg/ad-minima"
}
]
},
// merge of
// - logger data
// - logger parents data
// - data passed in log message
data: {
appVersion: "3.1",
moduleName: "auth",
moduleVersion: "0.3.1",
port: 3000,
SHELL: "/bin/bash",
COLORTERM: "truecolor",
PWD: "/home/alexxgrib/Projects/@hishprorg/ad-minima"
},
context: {
// name of the logger
name: "auth",
// list of logger inheritance
path: ["app", "auth"]
},
// logger object
origin: child
});
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago