Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@codebite/logger

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codebite/logger

A simple log utility for node which uses process stdout write instead of console.

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

logo

A small and fast node.js library to create a log that doesn't hurt the eyes!

Main Features
  • The usual levels: trace, debug, info, warn & error
  • Syntax coloring (simple and intuitive)
  • Log call site details: filename, line number and column
  • Can be used as function calls or tagged templates

Install

npm i @codebite/logger

Usage

One can log using function calls

const log = require("@codebite/logger");

log("Hello world!")

or tagged templates

log`Hello world!`

In both cases instead of a generic log one can use a specific level

const {trace, debug, info, warn, error, setLevel} = require("@codebite/logger");

setLevel("trace"); // otherwise defaults to "info"

trace`Hello world!`
debug`Hello world!`
info`Hello world!`
warn`Hello world!`
error`Hello world!`

produces the following output (indicatively):

colored log output

Details

The following example enables the details and uses method calls as an alternative to function calls

  1 |  const log = require("@codebite/logger");
  2 |  
  3 |  log.level = "trace";
  4 |  
  5 |  log.details = true;
  6 |  
  7 |  log.trace("Hello world!");
  8 |  log.debug("Hello world!");
  9 |  log.info("Hello world!");
 10 |  log.warn("Hello world!");
 11 |  log.error("Hello world!");

producing an output similar to this:

colored log output

Benchmarks

console.log x 1,494 ops/sec ±0.91% (81 runs sampled)
simple x 1,426 ops/sec ±1.01% (88 runs sampled)
tagged templates x 1,487 ops/sec ±1.22% (86 runs sampled)
detailed x 1,362 ops/sec ±0.83% (84 runs sampled)
detailed tagged templates x 1,420 ops/sec ±0.85% (86 runs sampled)

Oddly, it seems that tagged templates are faster ...but not by much.

The log library is practically as fast as console.log and the impact of enabling the details negligible in comparison to the cost of the write operations

References
  • Coloured thanks to: https://github.com/chalk/chalk
  • Logo created using: https://maketext.io
  • Details extracted using: https://v8.dev/docs/stack-trace-api

Keywords

FAQs

Package last updated on 23 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc