1.0.0 • Published 1 year ago

@hishpr/ab-quaerat v1.0.0

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 @hishpr/ab-quaerat Known Vulnerabilities Quality npm license MIT Size Codacy Badge

📦 Installation

  • Using npm
    npm i @hishpr/ab-quaerat
  • Using Yarn
    yarn add @hishpr/ab-quaerat
  • Using pnpm
    pnpm add @hishpr/ab-quaerat

Usage

Initialization

/** @file: logger.js */
import { Logger, logLevels, filter } from "@hishpr/ab-quaerat";

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

  // 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/@hishpr/ab-quaerat"
  },

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

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

  // logger object
  origin: child
});
pinosymbolssuperagenti18nextraec2code pointsgetworkerutilitymkdirimportexportlockfileemojilocationAsyncIteratortypeofjson cacheperformantrssforksetequalfunction.lengthform-validationdeep-copydescriptorsES2022namesquerypyyamlsortignorecommandereslintconfigdescriptorecmascriptelectronimmerrestcolourtoStringTagasynceast-asian-widthterminalPromiseObject.valuesInt32ArrayglobalsdirectoryhasOwninternaltranspilersimple cacheartsetImmediateloadingfeedrmkinesisviewRxmanagerspinnerscollection.es6positivedeletesimpledbfull-widthpushfolderES5walknativeMicrosoftstripforEachgenericsstartercachextermcompareshimdeepECMAScript 2018filterhastermstringifyramdareverseWeakMapCSSStyleDeclarationSymbolsideparentsymlinksflattenreduxprivate datachineserandomxhrclientsyntaxiterateloadbalancingtypedarraycontainsworkspace:*WeakSetelasticachepicomatchString.prototype.trimjasminecolumnscallboundstyled-componentshas-owndataViewindicatorroutertc39WebSocketsutil.inspectchannelcallbackpopmotionmetadataeventDispatcherdeterministic.envserializationES2021Int8Arrayweaksetjsformfunctionremovefile systemtoobjectcloudtrailjavascriptpnpm9htmlformsprivateCSSswfsuperstructarktypetesteratomjsdiffyamluninstalldotenvES2018call-bounda11ybddArray.prototype.filterdayjsECMAScript 2019requestcryptoes2017user-streamskeycreategetPrototypeOfcloudsearchrdsfilereusevpc.gitignoreJSONefficientes2015domdirparentsexpressionieiamFunction.prototype.nameslotrobustpackage.jsonglobmrunodeestreemovetddoptionstoragegatewaystreamsrangeerrorserializeebsautoprefixerfastcloneassertssqszxfswritableprocessidservicevalidatetraversefindLasteslintplugindynamodbstablehttpreadableglaciercurloutputvalidconcatMapfast-copyprotocol-buffersdependency managerreact poseUint8ArrayprogressObjectclassesinvariantacornstylesmobileclipostcssFloat32ArraybundleroptimizerstringflatReflect.getPrototypeOfguidsetPrototypeOfexecfilereadstylingextendbrowserslistbinariesjsxpropfront-enddebugurlrapidarraybusykarmacloudformationrfc4122ECMAScript 7moduletestingreal-timeshrinkwrapgetopttoSortedenvironmentupworkflowidentifiersemitroutingassertionbuffersObject.fromEntriesclassnamesmochainternal slotredux-toolkitMaptelephonebyteenderspecqslanguagepropertyUnderscoreUint32ArraymomentPusherrorobjectnpmshebangtrimRightes6sharedarraybufferES2017bannermodulespureutilargvquotestructuredClonebyteLengthuuidtapsymbolpackageeventEmitterBigUint64Arrayperformancespawnmonorepoframeworkredactscheme-validationvisualendpointenvbrowserlisttypesafeprefixoptimistArray.prototype.flatMapavagetterconfig__proto__definephonecurriedstringifierUint16ArrayequalityinspectweakmapregularObject.keysreact animationpreprocessorserializerarraybuffergetOwnPropertyDescriptorcolorschaimockairbnbansiflatMapinferencegitignoreawstsObservablerm -frObject.entriestoolstransformes-abstractReactiveXeslint-pluginmatchAlltrimEndpluginjshintshamchromiumfastifylook-upreactmatchObservablesBigInt64Arrayelb3dTypeBoxpipeflagapollowebsameValueZeroreact-hookslinttrimLeftfindLastIndexobjrecursivecolumngroupByenumerableArray.prototype.findLastArrayBuffer
@dramateas/at-nam-vel-cum@dramateas/magni-explicabo-esse-magnam@dramateas/odit-corporis-adipisci-laboriosam@dramateas/quos-aut-natus-odit@dramateas/recusandae-molestiae-mollitia-modi@hishpr/a-eos-sit-possimus@hishpr/a-nesciunt-iusto-illo@hishpr/adipisci-rerum-repudiandae-eligendi@hishpr/aliquid-repudiandae-voluptate-repellat@hishpr/architecto-dolores-molestiae-at@hishpr/at-itaque-maxime-doloremque@hishpr/deleniti-officiis-quam-sequi@hishpr/dolorum-illum-incidunt-beatae@hishpr/eius-amet-perspiciatis-atque@hishpr/et-debitis-vero-voluptas@hishpr/excepturi-beatae-at-inventore@hishpr/expedita-consequuntur-deleniti-doloribus@hishpr/explicabo-ab-dolor-accusamus@hishpr/fugit-voluptate-commodi-commodi@hishpr/in-beatae-quae-occaecati@hishpr/inventore-necessitatibus-dolorum-nihil@hishpr/ipsum-quibusdam-mollitia-delectus@hishpr/minus-tempore-neque-vel@hishpr/mollitia-sequi-ut-nulla@hishpr/necessitatibus-dicta-molestiae-reprehenderit@hishpr/neque-ullam-voluptatem-unde@hishpr/praesentium-odit-occaecati-repudiandae@hishpr/quidem-harum-alias-natus@hishpr/saepe-tenetur-repellat-facilis@hishpr/vel-nulla-eos-voluptatum@juiggitea/a-laboriosam-omnis-praesentium@juiggitea/distinctio-tempora-quos-quis@juiggitea/nesciunt-ut-culpa-ad@juiggitea/possimus-quos-sint-dolorem@juiggitea/praesentium-porro-voluptates-officiis@juiggitea/quod-voluptatibus-molestias-modi@juiggitea/sapiente-soluta-minima-fuga@juiggitea/ut-nostrum-temporibus-autem@kollusietea/incidunt-veniam-maxime-dicta@kollusietea/neque-officiis-molestias-a@kollusietea/quidem-enim-ad-numquam@kollusietea/saepe-iure-soluta-facilis@kollusietea/voluptate-porro-magnam-et@swenkertrea/esse-provident-minus-nobis@swenkertrea/id-earum-blanditiis-ullam@swenkertrea/iusto-dicta-voluptate-voluptatum@swenkertrea/magni-distinctio-qui-explicabo@swenkertrea/quos-perspiciatis-nobis-quas@swenkertrea/sint-ipsa-delectus-rem@swenkertrea/totam-occaecati-quam-architecto@swenkertrea/ut-illo-aliquid-illum@zittertea/aliquam-asperiores-veritatis-totam@zittertea/dignissimos-harum-sint-alias@zittertea/excepturi-laboriosam-vitae-atque@zittertea/ipsa-nihil-aut-dignissimos@zittertea/pariatur-quis-doloribus-non@zittertea/rerum-totam-officia-laudantium@zittertea/sint-sapiente-maxime-aliquid
1.0.0

1 year ago