2.1.17 • Published 1 year ago

@kollorg/odio-aspernatur v2.1.17

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Tie Logger

👔 Fully typed minimal platform-agnostic logger

Test Status Downloads last commit codecov GitHub @kollorg/odio-aspernatur Known Vulnerabilities Quality npm license MIT Size Codacy Badge

📦 Installation

  • Using npm
    npm i @kollorg/odio-aspernatur
  • Using Yarn
    yarn add @kollorg/odio-aspernatur
  • Using pnpm
    pnpm add @kollorg/odio-aspernatur

Usage

Initialization

/** @file: logger.js */
import { Logger, logLevels, filter } from "@kollorg/odio-aspernatur";

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

  // 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/@kollorg/odio-aspernatur"
  },

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

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

  // logger object
  origin: child
});
byteLengthspeceslintpluginawswaapisameValueZeronodejsfsreworkutilprivateregular-expressioncoercibleschemefrompurejsutilsbabel-coredeepcopyeventEmitterflatentrieses-shim APIreducereal-timeownjsxhas-ownlengthwaitassertsAsyncIteratorsidesuperstructworkspace:*Array.prototype.includestakeuphelperconfigurablesetPrototypeOfenderslot[[Prototype]]sqscollectioninternal slots3redactweblocationcssdirectoryiteratortypescriptfile systemObject.iscall-boundES8hasOwnramdanpmrecursiveworkflowwgetparentequalitynativeagentfastES2016cacheexecArray.prototype.containsaccessibilityflagfast-cloneecmascriptclassessharediedefinePropertyshellespreepatchcopyperformantArrayBufferreactfetchcore-jsstringifierObject.keysnegativeInt32Arrayclassnamesletdeep-cloneArray.prototype.findLastIndexWebSocketsRxestreeECMAScript 2017visual.envweakmapECMAScript 7importvarstouchidentifiersRxJSiamcollection.es6dependencieshelperseast-asian-widthcodesES7isstringifyselfmkdirsString.prototype.matchAllECMAScript 20200definebabelmruReactiveXbrowserslisttyped arraypreprocessoruser-streamsenvironmentmodulesobjectArray.prototype.flatMapjshintfullloadingcolorperformanceWebSocketzodvaluesponyfillhashstreamsjson-schema-validatorsyntaxeffect-tsES2023linkmonorepobintoolkitcolumnrandomdescriptorenvtc39point-freesestrimsimpledbschemaomitcomparetypesreducercallbackrequestes2017varstoragegatewaydeepcontainsfindupfull-widthreact-hookslook-upECMAScript 5binariesfolderi18nresta11yvariablesglobtslibxhrtestingBigUint64ArraypositivezxcryptoistanbulTypeBoxreact animationutilityterminalio-tsmetadata@@toStringTagequalpropertiesidleUint8ClampedArraypnpm9functionconcatMaptapextendawesomesauce$.extendHyBitrimStartinstrumentationchannelCSSStyleDeclarationignoresortedviewECMAScript 3moduleES2022walkingdotenvharmonyapirfc4122figletbyteOffsetcensorWeakSetinspectdayjsnopeUint32Arrayjson-schemagroupajaxkinesisreadablequeryparserconsumemochabuffersemojiObject.entriesrequireinputpinoMapfantasy-landenumerabledatemake direxecutefind-upfnmatcheslint-plugintoReversedassertECMAScript 2015redux-toolkitES2020cloudwatchnegative zeroregular expressionspushlocalcloudformationloggerObservablescallbindautoscalingtypesafechineseECMAScript 2019getPrototypeOfSymbol.toStringTagjestdescriptorsvalidatorconcatlistenerstapechaivalueremove__proto__protowriteargumentttyFunction.prototype.namestyleguideECMAScript 2023filterReflect.getPrototypeOfinfastcopy
2.1.17

1 year ago

2.1.16

1 year ago

2.1.15

1 year ago

2.1.14

1 year ago

2.1.13

1 year ago

2.1.12

1 year ago

2.1.11

1 year ago

2.1.10

1 year ago

2.1.9

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago