<commit_before># Studio Log

👻 Log [ndjson][1] to an output stream, format the output with emoji ✨

![](https://github.com/javascript-studio/studio-log/raw/master/emojilog.png)

## Features

- Fancy formats with emoji for log file reading pleasure.
- API designed to produce expressive source code.
- Uses topics instead of log levels for more fine grained filtering.
- Uses object streams to avoid serialize -> parse -> serialize when used in a
  command line application.
- Disabled by default. If no output stream is specified, no logs are written.

## Usage

Log output is disabled by default to ensure logs don't get in the way when
writing unit tests. Therefore you want to set this up as the first thing in
your main:

```js
// Sending raw JSON logs to stdout, e.g. in a server application:
require('@studio/log').out(process.stdout);

// Sending fancy formatted logs to stdout, e.g. in a command line tool:
require('@studio/log')
  .transform(require('@studio/log/format/fancy')())
  .out(process.stdout);
```

Next, create a logger instance in a module and start writing logs:

```js
const logger = require('@studio/log');

const log = logger('app');

exports.startService = function (port) {
  log.launch('my service', { port: 433 });
};

```

In the server example above, this output is produced:

```json
{"ts":1486630378584,"ns":"app","topic":"launch","msg":"my service","data":{"port":433}}
```

Send your logs to the `emojilog` command for pretty printing:

```bash
$ cat logs.ndjson | emojilog
09:52:58 🚀  app my service port=433
```

## Install

```bash
$ npm install @studio/log --save
```

Install this module globally to get the `emojilog` command line tool to format
logs:

```bash
$ npm install @studio/log -g
# ...
$ node app.js | emojilog
```

## Topics

Instead of log levels, this logger uses a set of topics to categorize, format
and filter logs. Unlike log levels, topics are not ordered by severity.

These topics are available:

- ✅ = `ok`
- ⚠️ = `warn`
- 🐛 = `issue`
- 🚨 = `error`
- 🙈 = `ignore`
- 🔺 = `input`
- 🔻 = `output`
- 📤 = `send`
- 📥 = `receive`
- 📡 = `fetch`
- 🏁 = `finish`
- 🚀 = `launch`
- ⛔️ = `terminate`
- ✨ = `spawn`
- 📣 = `broadcast`
- 💾 = `disk`
- ⏱  = `timing`
- 💰 = `money`
- 🔢 = `numbers`
- 👻 = `wtf`

## Log format

- `ns`: The logger instance namespace.
- `ts`: The timestamp as returned by `Date.now()`.
- `topic`: The topic name.
- `msg`: The message.
- `data`: The data.
- `stack`: The stack of error object.
- `cause`: The cause stack of `error.cause` object, if available.

## API

### Creating a logger

- `log = logger(ns[, data])`: Creates a new logger with the given namespace.
  The namespace is added to each log entry as the `ns` property. If `data` is
  provided, it is added to each log entry. Multiple calls with the same `ns`
  property return the same logger instance while data is replaced.
- `log.child(ns[, data])`: Creates a child logger of a log instance. The
  namespaces are joined with a blank and `data` is merged. Multiple calls with
  the same `ns` property return the same logger instance while data is
  replaced.

### Log instance functions

- `log.{topic}([message][, data][, error])`: Create a new log entry with these
  behaviors:
    - The `topic` is added as the `"topic"`.
    - If `message` is present, it's added as the `"msd"`.
    - If `data` is present, it's added as the `"data"`.
    - If `error` is present, the `stack` property of the error is added as the
      `"stack"`. If no `stack` is present, the `toString` representation of the
      error is used.<commit_msg>Fix typo in message docs<commit_after># Studio Log

👻 Log [ndjson][1] to an output stream, format the output with emoji ✨

![](https://github.com/javascript-studio/studio-log/raw/master/emojilog.png)

## Features

- Fancy formats with emoji for log file reading pleasure.
- API designed to produce expressive source code.
- Uses topics instead of log levels for more fine grained filtering.
- Uses object streams to avoid serialize -> parse -> serialize when used in a
  command line application.
- Disabled by default. If no output stream is specified, no logs are written.

## Usage

Log output is disabled by default to ensure logs don't get in the way when
writing unit tests. Therefore you want to set this up as the first thing in
your main:

```js
// Sending raw JSON logs to stdout, e.g. in a server application:
require('@studio/log').out(process.stdout);

// Sending fancy formatted logs to stdout, e.g. in a command line tool:
require('@studio/log')
  .transform(require('@studio/log/format/fancy')())
  .out(process.stdout);
```

Next, create a logger instance in a module and start writing logs:

```js
const logger = require('@studio/log');

const log = logger('app');

exports.startService = function (port) {
  log.launch('my service', { port: 433 });
};

```

In the server example above, this output is produced:

```json
{"ts":1486630378584,"ns":"app","topic":"launch","msg":"my service","data":{"port":433}}
```

Send your logs to the `emojilog` command for pretty printing:

```bash
$ cat logs.ndjson | emojilog
09:52:58 🚀  app my service port=433
```

## Install

```bash
$ npm install @studio/log --save
```

Install this module globally to get the `emojilog` command line tool to format
logs:

```bash
$ npm install @studio/log -g
# ...
$ node app.js | emojilog
```

## Topics

Instead of log levels, this logger uses a set of topics to categorize, format
and filter logs. Unlike log levels, topics are not ordered by severity.

These topics are available:

- ✅ = `ok`
- ⚠️ = `warn`
- 🐛 = `issue`
- 🚨 = `error`
- 🙈 = `ignore`
- 🔺 = `input`
- 🔻 = `output`
- 📤 = `send`
- 📥 = `receive`
- 📡 = `fetch`
- 🏁 = `finish`
- 🚀 = `launch`
- ⛔️ = `terminate`
- ✨ = `spawn`
- 📣 = `broadcast`
- 💾 = `disk`
- ⏱  = `timing`
- 💰 = `money`
- 🔢 = `numbers`
- 👻 = `wtf`

## Log format

- `ns`: The logger instance namespace.
- `ts`: The timestamp as returned by `Date.now()`.
- `topic`: The topic name.
- `msg`: The message.
- `data`: The data.
- `stack`: The stack of error object.
- `cause`: The cause stack of `error.cause` object, if available.

## API

### Creating a logger

- `log = logger(ns[, data])`: Creates a new logger with the given namespace.
  The namespace is added to each log entry as the `ns` property. If `data` is
  provided, it is added to each log entry. Multiple calls with the same `ns`
  property return the same logger instance while data is replaced.
- `log.child(ns[, data])`: Creates a child logger of a log instance. The
  namespaces are joined with a blank and `data` is merged. Multiple calls with
  the same `ns` property return the same logger instance while data is
  replaced.

### Log instance functions

- `log.{topic}([message][, data][, error])`: Create a new log entry with these
  behaviors:
    - The `topic` is added as the `"topic"`.
    - If `message` is present, it's added as the `"msg"`.
    - If `data` is present, it's added as the `"data"`.
    - If `error` is present, the `stack` property of the error is added as the
      `"stack"`. If no `stack` is present, the `toString` representation of the
      error is used.
{'fraction_non_alphanumeric': 0.1391182645206438, 'fraction_numerical': 0.008117564730580826, 'mean_word_length': 3.5719769673704413, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1231595', 'n_tokens_mistral': 2507, 'n_tokens_neox': 2343, 'n_words': 979}