All Projects → javascript-studio → studio-log

javascript-studio / studio-log

Licence: MIT license
👻 A tiny JSON logger with emoji support

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to studio-log

Pino Colada
cute ndjson formatter for pino 🌲🍹
Stars: ✭ 189 (+384.62%)
Mutual labels:  emoji, logger
printer
A fancy logger yet lightweight, and configurable. 🖨
Stars: ✭ 65 (+66.67%)
Mutual labels:  emoji, logger
country-flag-emoji-json
Country flag emojis in JSON format.
Stars: ✭ 92 (+135.9%)
Mutual labels:  emoji
Emojions
Embeddable Emoji Bar
Stars: ✭ 15 (-61.54%)
Mutual labels:  emoji
l
Cross-platform html/io [L]ogger with simple API.
Stars: ✭ 26 (-33.33%)
Mutual labels:  logger
icons
a collection of custom icons for use with the notion-enhancer's "icon sets" integration
Stars: ✭ 29 (-25.64%)
Mutual labels:  emoji
random-logger
Docker image for a random log generator.
Stars: ✭ 104 (+166.67%)
Mutual labels:  logger
Meteor-logger-file
🔖 Meteor Logging: Store application log messages into file (FS)
Stars: ✭ 24 (-38.46%)
Mutual labels:  logger
ham-go
Amateur radio related code written in go
Stars: ✭ 24 (-38.46%)
Mutual labels:  logger
faraday-detailed logger
A detailed request and response logger for Faraday.
Stars: ✭ 56 (+43.59%)
Mutual labels:  logger
GoogleCloudLogging
Swift (Darwin) library for logging application events in Google Cloud.
Stars: ✭ 24 (-38.46%)
Mutual labels:  logger
logger
Gin middleware/handler to logger url path using rs/zerolog
Stars: ✭ 119 (+205.13%)
Mutual labels:  logger
emoji-slider
A slider control with emojis
Stars: ✭ 40 (+2.56%)
Mutual labels:  emoji
sqlite micro logger arduino
Fast and Lean Sqlite database logger for Microcontrollers
Stars: ✭ 128 (+228.21%)
Mutual labels:  logger
neptune-client
📒 Experiment tracking tool and model registry
Stars: ✭ 348 (+792.31%)
Mutual labels:  logger
pio
Low-level package that provides an easy way to centralize different output targets. Supports colors and text decoration to all popular terminals
Stars: ✭ 21 (-46.15%)
Mutual labels:  logger
winmoji
Emoji lookup for Windows 😉 https://www.winmoji.com https://twitter.com/winmoji
Stars: ✭ 79 (+102.56%)
Mutual labels:  emoji
ReactButton
Android Library to make it easy to add ReactButton feature in your app with Multi Reactions like Facebook or Linkedin, you can add many reactions as you want, you can also split them into a number of columns, and also customize the colours and text for each reaction
Stars: ✭ 100 (+156.41%)
Mutual labels:  emoji
emoji-commit
No description or website provided.
Stars: ✭ 40 (+2.56%)
Mutual labels:  emoji
QueerCats
A whole bunch of pride flags represented as blobby cat emoji
Stars: ✭ 72 (+84.62%)
Mutual labels:  emoji

Studio Log 2

👻 Log ndjson to an output stream, pretty print the output with emoji

Note! Version 2 has significantly changed compared to the original announcement. Make sure to read the release notes for migration instructions!

Features

  • 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:

// Sending raw ndJSON logs to stdout, e.g. in a server application:
const Stringify = require('@studio/ndjson/stringify');
require('@studio/log')
  .pipe(new Stringify())
  .pipe(process.stdout);

// Sending fancy formatted logs to stdout, e.g. in a command line tool:
const Format = require('@studio/log-format/fancy');
require('@studio/log')
  .pipe(new Format())
  .pipe(process.stdout);

// Sending logs to console.log, e.g. in a browser:
const Format = require('@studio/log-format/console');
require('@studio/log')
  .pipe(new Format())

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

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:

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

Send your logs to the emojilog CLI for pretty printing:

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

Install

❯ npm i @studio/log

Topics

Instead of log levels, this logger uses a set of topics. Unlike log levels, topics are not ordered by severity.

These topics are available: ok, warn, error, issue, ignore, input, output, send, receive, fetch, finish, launch, terminate, spawn, broadcast, disk, timing, money, numbers and wtf.

Topics and their mapping to emojis are defined in the Studio Log Topics project.

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 API

  • 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.
    • 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.

Module API

  • logger.pipe(stream): Configure the output stream to write logs to. If not specified, no logs are written. Returns the stream.
  • logger.hasStream(): Whether a stream was set.
  • logger.reset(): Resets the internal state.

Transform streams

Transform streams can be used to alter the data before passing it on. For example, Studio Log X is a Transform stream that can remove confidential data from the log data and Studio Log Format project implements the basic, fancy and console pretty printers.

Format transforms are node transform streams in writableObjectMode. Here is an example implementation, similar to the ndjson stringify transform:

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

License

MIT

Made with ❤️ on 🌍
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].