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

zoya

v1.0.2

Published

Highly configurable logging utility

Downloads

27

Readme

Description

Zoya is a highly composable logging library used for both client and server applications.

Visit the contributing guidelines to learn more on how to translate this document into more languages.

Come over to Discord or Twitter to share your thoughts on the project.

This is a complete rewrite of Signale, written by Klaus Siani, and it's NOT intended to be a drop-in replacement.

Highlights

  • Easy to setup and compose as you like
  • Easy to control how things look
  • Easy to extend
  • Clean and beautiful output, configure as you wish
  • Supports JSON outputs
  • Extensible fields with several fields built in
    • Labels, Badge (emoji), Scopes, Level, Separators, Message, Context
  • Multiple configurable writable streams with stream level filtering
  • Simple and minimal syntax
  • Written in TypeScript

Contents

Install

Yarn

yarn add zoya

NPM

npm install zoya

Usage

Overview

Zoya tries to make it simple to configure and compose your loggers, so you can easily control how the output will look like. This is possible due to the field chain passed to the logger in its creation.

To use the default exported logger you just import and use it.

import zoya from "zoya";

zoya.info("Hello world!");

To see all the available examples check the examples folder

Default logger

The default export of zoya is an instance of a logger (called the default logger). This instance is preconfigured to write to process.stdout with all logging levels enabled (so you can use debug and trace for example).

These are all the available loggers in the default logger.

import log from "zoya";

log.trace("trace messages...");
log.debug("debug messages...");
log.info("info messages...");
log.success("success messages...");
log.warn("warn messages...");
log.error("error messages...");
log.failed("failed messages...");
log.fatal("fatal messages...");

The fields configured in the default logger are:

[scope][separator][badge][label][level][message][context]

More on fields later.

On new instances

To create a new Zoya instance, use zoya function passing the proper configs you want. Note that all first level values uses the default values from the default logger, so you don't need to specify all of them if you want for example to just enable json logging.

Note that if you pass value to an object, for example types, all the child values are overwritten.

import { zoya, Level } from "zoya";

// Just enables json
const jsonLogger = zoya({ json: true });

// Only outputs to stderr
const stderrLogger = zoya({
  streams: [
    {
      level: Level.error,
      stream: process.stderr
    }
  ]
});

Enhancing loggers

Zoya allows you to enhance existing loggers in order to add new logging types. Enhancing logger will create a new logger instance and will keep the old logger intact.

import { bold, underline } from "chalk";
import log, { Level } from "zoya";

const xmasLogger = log.enhance({
  santa: {
    level: Level.info,
    options: {
      badge: "santa"
      label: {
        name: "santa",
        transformer: label => bold(underline(label))
      }
      scope: ["xmas"]
    }
  }
});

xmasLogger.santa("Hohoho!");

The above logger will output something like this

Configuration

Fields

Zoya has the concept of fields. All log messages are built by a chain of fields that are configured when creating a new logger through zoya function. Fields are context sensitive, this means that you can output different things in a field depending on what the message contains.

Configuring fields

For example, if you just want to show the message and its context, you can configure zoya like this:

import { context, message, zoya } from "zoya";

const custom = zoya({
  fields: [message(), context()]
});

custom.info("Hello world", { ip: "127.0.0.1" });

This will output something like this in text mode:

And this in JSON mode:

Zoya fields

Zoya contains several fields that can be imported from zoya package.

Badge

Used to display emojis in the log text

Context

Displays the message context

Label

Displays a customizable label for each message type

Level

Adds the message level only on json outputs

Message

Displays the message itself

Scope

Display the message scope(s)

Separator

Displays a customizable separator only in text mode


Custom fields

You can easily write custom fields.

TODO: write example custom fields. For now you can take the bundled ones as an example from here.

Development

For more info on how to contribute to the project, please read the contributing guidelines.

  • Fork the repository and clone it to your machine
  • Navigate to your local fork: cd zoya
  • Install the project dependencies: npm install or yarn install
  • Lint code for errors: npm test or yarn test

Related

  • Signale - Highly configurable logging utility

Team

FAQ

Why "Zoya"?

Because I like Trine :)

Acknowledgements

Thanks

Huge thanks to brain (brain#4221), Micah (Micha#6878) and undefined.toString() (elderapo#8225) for the helpful insights over TypeScript discord channel

License

MIT