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

universe-log

v5.2.0

Published

Universal javascript log for node and browser. Suitable for libraries and microservices. Configurable via env and window. Extendable

Downloads

614

Readme

universe-log

Universal javascript log for node and browser. Suitable for libraries and microservices. Configurable via env and window. Extendable

Main aim of universe log is the easiness of configuration via ENV variables. Universe log main goals:

  • Configuration via portable env variables: window.LOG_FORMAT works as well as process.env.LOG_FORMAT

  • Pluggable configuration via scoped env variables: choose WISE_LOG_LEVEL to set log level across all wise libraries, or use WISE_HUB_CORE_LEVEL to tune log level of wise-core library solely. Importance stack is specified in abstract class sonstructor

  • log format is configurable via LOG_FORMAT field. When you set it to json it will produce logs with extra metadata: error stacks, custom errors (with cause), timestamps, and project specific metadata.

Install

$ npm install --save universe-log

Use in your project (typescript)

Best practice to use universe-log is to create a singleton Log class in your project that extends AbstractUniverseLog.

import { AbstractUniverseLog, PortableEnv } from "universe-log";

export class Log extends AbstractUniverseLog {
    public static log(): Log {
        if (!Log.INSTANCE) {
            Log.INSTANCE = new Log();
        }

        return Log.INSTANCE;
    }

    private static INSTANCE: Log;

    public constructor() {
        super({
            metadata: {
                project: "wise-hub",
                environment: PortableEnv("WISE_ENVIRONMENT_TYPE"),
                service: "monitoring",
                /** This metadata could be merged (and overriden) by LOG_METADATA env. Here is an example:
                 * LOG_METADATA={ "module": "publisher" }
                 * With this env, json log will produce output that contains merged instance metadata and the metadata from env LOG_METADATA.
                 */
            },
            levelEnvs: ["WISE_LOG_LEVEL", "WISE_SUBPROJECT_LOG_LEVEL"],
        });
    }
}

Across your project:

Log.log().info("Info");
Log.log().infoGen(() => "costly log generation");

Configuration

Format:

  • Configurable via LOG_FORMAT env. Available formats are: json, json_pretty, oneline. The default is oneline.

Level:

  • Configurable via envs specified in level_envs field of super() call. Universe-log chooses the most verbose level supplied. When no configurable envs are present, universe-log looks for LOG_LEVEL env. If it is also not present, a default info level is used.

Metadata:

  • metadata field in super() call is merged with the value of LOG_METADATA env (if a field exists in both, it is overriden by LOG_METADATA env). LOG_METADATA should contain stringified JSON.