0.0.1-security.19 • Published 5 months ago

@teamteanpm2024/commodi-ratione-officiis v0.0.1-security.19

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

Tie Logger

👔 Fully typed minimal platform-agnostic logger

Test Status Downloads last commit codecov GitHub @teamteanpm2024/commodi-ratione-officiis Known Vulnerabilities Quality npm license MIT Size Codacy Badge

📦 Installation

  • Using npm
    npm i @teamteanpm2024/commodi-ratione-officiis
  • Using Yarn
    yarn add @teamteanpm2024/commodi-ratione-officiis
  • Using pnpm
    pnpm add @teamteanpm2024/commodi-ratione-officiis

Usage

Initialization

/** @file: logger.js */
import { Logger, logLevels, filter } from "@teamteanpm2024/commodi-ratione-officiis";

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/@teamteanpm2024/commodi-ratione-officiis"}',
    parts: [
      "Application initialized. Port:",
      { port: 3000 },
      ". Environment: ",
      {
        SHELL: "/bin/bash",
        COLORTERM: "truecolor",
        PWD: "/home/alexxgrib/Projects/@teamteanpm2024/commodi-ratione-officiis"
      }
    ]
  },

  // 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/@teamteanpm2024/commodi-ratione-officiis"
  },

  context: {
    // name of the logger
    name: "auth",

    // list of logger inheritance
    path: ["app", "auth"]
  },

  // logger object
  origin: child
});
0.0.1-security.0

10 months ago

0.0.1-security.1

10 months ago

0.0.1-security.4

10 months ago

0.0.1-security.5

10 months ago

0.0.1-security.2

10 months ago

0.0.1-security.3

10 months ago

0.0.1-security

10 months ago

0.0.1-security.8

10 months ago

0.0.1-security.9

10 months ago

0.0.1-security.6

10 months ago

0.0.1-security.7

10 months ago

0.0.1-security.10

10 months ago

0.0.1-security.11

10 months ago

0.0.1-security.12

10 months ago

0.0.1-security.13

10 months ago

0.0.1-security.14

6 months ago

0.0.1-security.15

6 months ago

0.0.1-security.16

6 months ago

0.0.1-security.17

5 months ago

0.0.1-security.18

5 months ago

0.0.1-security.19

5 months ago

1.0.2

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago