Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@studio/log

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@studio/log - npm Package Compare versions

Comparing version
1.4.1
to
1.5.0
+9
-0
CHANGES.md
# Changes
## 1.5.0
- 🍏 Serialize the error `cause` as a new JSON property
- 🍏 Serialize the error `code` into the `data` object
- 🍏 Serialize the error `cause.code` into the `data` object
- 🍏 Support the new `cause` property in the basic and fancy formatters
- 📚 Add new feature to docs and improve usage example and API docs
- 📚 Add cause example to demo
## 1.4.1

@@ -4,0 +13,0 @@

+4
-1

@@ -71,3 +71,6 @@ /*

}
const str = parts.join(' ');
let str = parts.join(' ');
if (stack && entry.cause) {
str += `\n caused by ${formatStack(stack, entry.cause)}`;
}
callback(null, `${str}\n`);

@@ -74,0 +77,0 @@ }

+5
-1

@@ -136,3 +136,7 @@ /*

}
const str = parts.join(' ');
let str = parts.join(' ');
if (stack && entry.cause) {
str += `\n ${chalk.magenta('caused by')} ${
formatStack(stack, entry.cause)}`;
}
callback(null, `${str}\n`);

@@ -139,0 +143,0 @@ }

@@ -29,2 +29,18 @@ /*

function addError(entry, error) {
const cause = error.cause;
const cause_code = cause && cause.code;
if (error.code || cause_code) {
entry.data = entry.data ? Object.assign({}, entry.data) : {};
entry.data.code = error.code;
if (cause_code) {
entry.data.cause = { code: cause_code };
}
}
entry.stack = error.stack || String(error);
if (cause) {
entry.cause = cause.stack || String(cause);
}
}
function write(ns, base_data, topic, msg, data, error) {

@@ -47,7 +63,7 @@ const mutes = state.muted[ns];

if (data instanceof Error) {
entry.stack = data.stack;
addError(entry, data);
} else {
entry.data = base_data ? Object.assign({}, base_data, data) : data;
if (error) {
entry.stack = error.stack || String(error);
addError(entry, error);
}

@@ -54,0 +70,0 @@ }

{
"name": "@studio/log",
"version": "1.4.1",
"version": "1.5.0",
"description": "A tiny JSON logger with emoji support",

@@ -5,0 +5,0 @@ "bin": {

+85
-39

@@ -18,11 +18,30 @@ # Studio Log

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
const logger = require('@studio/log').out(process.stdout);
// 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');
log.launch('my service', { port: 433 });
exports.startService = function (port) {
log.launch('my service', { port: 433 });
};
```
The above produces this output:
In the server example above, this output is produced:

@@ -33,2 +52,9 @@ ```json

Send your logs to the `emojilog` command for pretty printing:
```bash
$ cat logs.ndjson | emojilog
09:52:58 🚀 app my service port=433
```
## Install

@@ -49,2 +75,40 @@

## 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

@@ -66,9 +130,17 @@

- `log.{topic}([message][, data][, error])`: Create a new log entry with these
properties:
- `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.
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.
- If `error.code` is present, it is added to the `"data"` without modifying
the original object.
- If `error.cause` is present, the `stack` property of the cause is added
as the `"cause"`. If no `stack` is present, the `toString` representation
of the cause is used.
- If `error.cause.code` is present, a `cause` object is added to the
`"data"` with `{ code: cause.code }` and without modifying the original
object.
- `log.filter(stream)`: Configure a filter stream for this logger namespace.

@@ -95,30 +167,2 @@ See ["Filter Streams"](#filter-streams).

## 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`
## CLI Options

@@ -174,3 +218,3 @@

- `stack: style` with these stack styles:
- `false: hide the error entirely
- `false`: hide the error entirely
- `message` only show the error message

@@ -180,2 +224,4 @@ - `peek` show the message and the first line of the trace (default)

The `stack` option is also used to format the `"cause"`, if present.
## Custom Format Transforms

@@ -182,0 +228,0 @@