npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tian-logger

v1.0.0

Published

A simple and configurable logger using async_hooks

Downloads

2

Readme

tian-logger

A simple logger using async_hooks. With it you don't neet to pass logger everywhere.

Quick start

1. Install

npm i tian-logger

2. Usage

Create a logger with default writer in file ./globalLogger.js

const { Logger } = require('tian-logger');
const logger = new Logger({ level: 'info', meta: { meta1: '' } });
module.exports = logger;

Use the global logger anywhere

const globalLogger = require('./globalLogger');
globalLogger.info('message only');
// {"level":"info","time":"2020-08-03T11:49:30.110Z","message":"message only","meta":{"meta1":""},"data":{}}
globalLogger.error('error with data', new Error('error'));
// {"level":"error","time":"2020-08-03T12:34:11.846Z","message":"error with data","meta":{"meta1":""},"data":{"name":"Error","message":"error","stack":["file positions"]}}

Customize writer:

const { Logger } = require('tian-logger');
const fs = require('fs');
const logger = new Logger({
  writer: (object) => {
    // object is a object like
    // {
    //   message: "message",
    //   level: "debug|info|warn|error|fatal",
    //   time: "2020-08-03T10:42:25.415Z"
    //   meta: { meta1: '' },
    //   data: { field1: '' }
    // }
    fs.writeSync(1, JSON.stringify(object));
  }
})

API

Logger

constructor([options])

  • options.level: 'debug' or 'info' or 'warn' or 'error' or 'final'. 'info' by default.
  • options.meta: the object you want to add to current context.
  • options.writer: customize writing logic

attach(meta)

Add meta data to current context.

  • meta: the object you want to add to current context.

setLevel(level)

Change logging level.

  • level: new logging level.

setWriter(writer)

Customize writer.

  • writer: new writer.

debug(message[, data])

Write message a debug level.

  • message: logging message
  • data: extra logging object

info(message[, data])

Write message a info level.

  • message: logging message
  • data: extra logging object

warn(message[, data])

Write message a warn level.

  • message: logging message
  • data: extra logging object

error(message[, data])

Write message a error level.

  • message: logging message
  • data: extra logging object

final(message[, data])

Write message a final level.

  • message: logging message
  • data: extra logging object