1.0.0 ⢠Published 7 years ago
@studio/log-format v1.0.0
Studio Log Format
š© Transform streams to format Studio Log streams
This module also works in the browser using a naive
streamshim for small Browserify bundles.
Usage
const FancyFormat = require('@studio/log-format/fancy');
require('@studio/log')
  .pipe(new FancyFormat())
  .pipe(process.stdout);Install
⯠npm i @studio/log-formatAPI
Transform Streams
@studio/log-format/basic: Basic formatting with ISO dates and no colors.@studio/log-format/fancy: Colored output with localized dates. This is the default formatter when using theemojilogCLI.
Some advanced formatting is applied by naming conventions on top level
properties of the data object.
tsor prefixts_formats a timestamp.msor prefixms_formats a millisecond value.bytesor prefixbytes_formats a byte value.
These options can be passed to the bundled format transforms:
ts: falsehide timestampstopic: falsehide topicsns: falsehide namespacesdata: falsehide datastack: stylewith these stack styles:false: hide the error entirelymessageonly show the error messagepeekshow the message and the first line of the trace (default)fullshow the message and the full trace
The stack option is also used to format the "cause", if present.
Writable Streams
@studio/log-format/console: Console logger, making use of theconsole.logdefault formatting. This format has no options.
Custom Format Transforms
You can also write your own format transforms by implementing a node transform
streams in writableObjectMode. Here is an example transform
implementation, similar to the ndjson transform for Studio Log:
const { Transform } = require('stream');
const ndjson = new Transform({
  writableObjectMode: true,
  transform(entry, enc, callback) {
    const str = JSON.stringify(entry);
    callback(null, `${str}\n`);
  }
});Related modules
- š» Studio Log logs ndjson to an output stream
 - š· Studio Log Topics defines the topics used by Studio Log
 - š Studio Emojilog is a CLI to pretty print the Studio Log ndjson with emoji
 - š¦ Studio Changes is used to create the changelog for this module.
 
License
MIT
1.0.0
7 years ago