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

@studiohyperdrive/logger

v1.1.2

Published

SHD logging module: an abstraction on console.log for both frontend as backend (Node.js).

Downloads

199

Readme


Table of Contents


@studiohyperdrive/logger is a logging library that supports both the browser and Node.js by exporting different bundles for both targets.

Installation

Install through npm:

$ npm install @studiohyperdrive/logger

Install through yarn:

$ yarn add @studiohyperdrive/logger

Browser

For usage with the browser a UMD and ESModule bundle are exported. It provides a Logger class which is an abstraction on console.log based on high-console.

Usage

Create an instance of the logger and export it for usage in your application:

logger.js

import { Logger } from "@studiohyperdrive/logger";

export const logger = new Logger();

app.js

import { logger } from "./logger";

logger.debug("some debug message", { key: "value" });
logger.info("some info message", { key: "value" });
logger.success("some success message", { key: "value" });
logger.warn("some warn message", { key: "value" });
logger.error("some error message", { key: "value" });

Output

Overloads

As documented in the typings, each method has several overloads:

logger.info("some info message", { key: "value" }); // Message and object
logger.info("some info message"); // Message
logger.info({ key: "value" }); // Object
logger.info("some info message", { key: "value" }, true); // Force a log when loglevel is disabled

Configuration

When creating an instance of the Logger class configuration can be provided by passing an options object to the constructor.

import { Logger } from "@studiohyperdrive/logger";

export const logger = new Logger({
    enabled: [
        "error",
    ],
});

Default configuration

The default configuration is the following:

{
    enabled: [ // Enabled loglevels
        "debug",
        "info",
        "success",
        "warn",
        "error"
    ],
    timestamp: true
}

Node.js

For usage with Node.js a CommonJS bundle is exported. It provides a Logger class which is an abstraction on console.log based on signale.

Other features:

  • Logging to the filesystem using daily rotating files
    • all
    • warn
    • error

Usage

Create an instance of the logger and export it for usage in your application:

logger.js

const Logger = require("@studiohyperdrive/logger");

const logger = new Logger();

module.exports = logger;

app.js

const logger = require("./logger");

logger.debug("some debug message", { key: "value" });
logger.info("some info message", { key: "value" });
logger.cron("some cron message", { key: "value" });
logger.db("some db message", { key: "value" });
logger.success("some success message", { key: "value" });
logger.warn("some warn message", { key: "value" });
logger.error("some error message", { key: "value" });

Output

Overloads

As documented in the typings, each method has several overloads:

logger.info("some info message", { key: "value" }); // Message and object
logger.info("some info message"); // Message
logger.info({ key: "value" }); // Object
logger.info("some info message", { key: "value" }, true); // Force a log when loglevel is disabled

Configuration

When creating an instance of the Logger class configuration can be provided by passing an options object to the constructor.

const Logger = require("@studiohyperdrive/logger");

const logger = new Logger({
    enabled: [
        "error",
    ],
    filesystem: {
        enabled: true,
        path: "logs",
    },
});

module.exports = logger;

Default configuration

The default configuration is the following:

{
    enabled: [ // Enabled loglevels
        "debug",
        "info",
        "cron",
        "db",
        "success",
        "warn",
        "error"
    ],
    filesystem: {
        enabled: true, // Enable logging to filesystem
        path: "logs" // Path for the filesystem logs (from root)
    },
    timestamp: true,
}

Snippets

Snippets for JavaScript and TypeScript can be found in the snippets folder.

Roadmap

We are continuously looking to improve this package. If you have any feedback or ideas, please let us know.

The roadmap as is today:

  • ...

Contributing

Feel free to provide feedback, open issues or create pull-requests to this repository.

License

@studiohyperdrive/logger is MIT licensed by Studio Hyperdrive.

About us

Studio Hyperdrive is an experienced digital development studio focussed on all things JavaScript. Already 18 strong. Based in Antwerp & Ghent! With a handpicked set of skills we build anything from websites to chatbots and immersive cross reality experiences. Feel free to contact us through our website.