@chkt/onceupon

Logging without compromises

Usage no npm install needed!

<script type="module">
  import chktOnceupon from 'https://cdn.skypack.dev/@chkt/onceupon';
</script>

README

Tests Version Node Dependencies Licence Language Size

onceupon

Logging without compromises

onceupon is a fully configurable logging system for all javascript platforms. It is written in typescript. All major components use Promises.

Install

npm install @chkt/onceupon

Use

Initialize the logger by importing the default export and calling it:

import { createLogger, log_level } from '@chkt/onceupon';

const logger = createLogger();

async () => {
  await logger
    .message('foo')
    .value([1, 2, 3], log_level.warn)
    .failure(new Error(), log_level.error, 'reporting api')
    .settle();
}

The initializer supports extensive configuration:

import { createLogger, log_level } from '@chkt/onceupon';
import { getTime} from "@chkt/onceupon/dist/time";
import { inferType } from "@chkt/onceupon/dist/type";
import { Parsers } from "@chkt/onceupon/dist/parse";
import { attachEmitter } from "@chkt/onceupon/dist/aggregate";
import { decorateTokens } from "@chkt/onceupon/dist/decorate";
import { handleLog } from "@chkt/onceupon/dist/handler";

const logger = createLogger({
  threshold : log_level,
  tags : string,
  time : getTime,
  infer : inferType,
  parsers : Parsers,
  aggregate : attachEmitter,
  decorate : decorateTokens,
  handle : handleLog
});

Public api

const enum log_level {
  fatal,
  error,
  warn,
  notice,
  info,
  verbose,
  debug
}

interface LoggerConfig {
  readonly threshold : log_level;
  readonly tags : string;
  readonly infer : inferType;
  readonly parsers : Parsers;
  readonly time : getTime;
  readonly aggregate : attachEmitter;
  readonly decorate : decorateTokens;
  readonly handle : handleLog;
}

interface Logger {
  message(message:string|Composition, level?:log_level, tags?:string) : Logger;
  value(value:any, level?:log_level, tags?:string) : Logger;
  failure(reason:any, level?:log_level, tags?:string) : Logger;
  create(value:any, opts:ParseOptions) : Promise<Log>;
  submit(data:Log) : Logger;
  threshold(threshold:log_level) : Logger;
  settings(settings:Partial<LoggerConfig>) : Logger;
  settle() : Promise<void>;
}

type createLogger = (settings?:Partial<LoggerConfig>) => Logger;