Skip to content

Latest commit

 

History

History

rstream-log

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@thi.ng/rstream-log

npm version npm downloads Mastodon Follow

This project is part of the @thi.ng/umbrella monorepo and anti-framework.

About

Structured, multilevel & hierarchical loggers based on @thi.ng/rstream.

This package provides extensible, multi-level & multi-hierarchy logging infrastructure, with logged values transformable via @thi.ng/transducers. Several built-in transformers are provided.

The Logger class provided by this package implements the @thi.ng/api ILogger interface and uses LogLevel enums to configure levels / filtering.

Status

STABLE - used in production

Search or submit any issues for this package

Support packages

Related packages

  • @thi.ng/logger - Types & basis infrastructure for arbitrary logging (w/ default impls)

Installation

yarn add @thi.ng/rstream-log

ES module import:

<script type="module" src="https://cdn.skypack.dev/@thi.ng/rstream-log"></script>

Skypack documentation

For Node.js REPL:

const rstreamLog = await import("@thi.ng/rstream-log");

Package sizes (brotli'd, pre-treeshake): ESM: 848 bytes

Dependencies

API

Generated API docs

import { LogLevel } from "@thi.ng/api";
import * as log from "@thi.ng/rstream-log";

const logger = new log.Logger("main");
// or with min level
const logger = new log.Logger("main", LogLevel.DEBUG);

// add console output w/ string formatter (a transducer)
logger.subscribe(log.writeConsole(), log.formatString());

logger.debug("hello world");
// [DEBUG] [main] 2018-01-20T09:04:05.198Z hello world

logger.warn("eek");
// [WARN] [main] 2018-01-20T09:04:16.913Z eek

// each logger instance is a rstream StreamMerge instance
// allowing to form logger hierarchies

const mod1 = new log.Logger("module-1", LogLevel.INFO);
// pipe mod1 into main logger
logger.add(mod1);

import { postWorker } from "@thi.ng/rstream";
// additionally send messages from this logger to worker
mod1.subscribe(postWorker("log-worker.js"));

mod1.info("hi from sub-module");

// only shown in console:
// [INFO] [module-1] 2018-01-20T09:05:21.198Z hi from sub-module

TODO

Authors

If this project contributes to an academic publication, please cite it as:

@misc{thing-rstream-log,
  title = "@thi.ng/rstream-log",
  author = "Karsten Schmidt",
  note = "https://thi.ng/rstream-log",
  year = 2017
}

License

© 2017 - 2023 Karsten Schmidt // Apache License 2.0