Skip to content

Latest commit

 

History

History

rstream-log

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

rstream-log

npm version npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

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

Installation

yarn add @thi.ng/rstream-log
// ES module
<script type="module" src="https://unpkg.com/@thi.ng/rstream-log?module" crossorigin></script>

// UMD
<script src="https://unpkg.com/@thi.ng/rstream-log/lib/index.umd.js" crossorigin></script>

Package sizes (gzipped, pre-treeshake): ESM: 760 bytes / CJS: 886 bytes / UMD: 957 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

Karsten Schmidt

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 - 2021 Karsten Schmidt // Apache Software License 2.0