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

@backs/logger

v1.1.16

Published

An advanced logger using winston & colorette behind the scenes

Downloads

9

Readme

Back's logger

Join my discord server or visit my website.

What's this?

It's a package that facilitates logging to console by allowing you to add many different loggers and styles. Also provides you with a progress bar and table out of the box. Works out of the box with no configuration needed. Uses under the hood:

  • winston
  • colorette
  • progress
  • table
  • moment

Usage examples

JS

    const createLogger = require("@backs/logger")

    const logger = createLogger()

    logger.log("Test\n%bl_b", "This text is blue in bold.")
    /* Prints
        Test
        This text is blue in bold.
    */

TS

    import createLogger from "@backs/logger"

    const logger = createLogger()

    logger.log("Test\n%bl_b", "This text is blue in bold.")
    /* Prints
        Test
        This text is blue in bold.
    */

Customization

Since it uses winston under the hood, you can use custom levels, colors, handlers, transports. You can also disable colors if needed. Check options down below.

Options

  • levels?: string[] - Array of winstom levels from most important to least important. Defaults to ["error", "warn", "debug", "log", "info"].
  • colors?: Record<string, Color> - An object that contains a function that takes a string or number and returns a string, for each log level. Defaults to { error: red, warn: yellow, debug: magenta, log: blue, info: green }.
  • transports?: transports[] - Array of winston transports. Defaults to a Console transport and File transport (error level only) with custom formats.
  • log?: Record<T[number], boolean | (() => boolean)> - An object containing levels as values and a boolean or a function returning a boolean as value to decide whether or not to log to the transports provided.
  • handlers?: Record<string, (logger: WinstonLogger, message: any, ...args: any[]) => void> - An object containing objects for each level containing a function to handle that level. Provides the winston logger, a message which can be any type, and an array of arguments.
  • disableColors?: boolean - Whether or not to disable colors in the console.

Color & Modifiers

You can pass into the message argument replacements formated as such %color_modifiers. These will be replaced by the arguments in order. Both the color and the modifiers are optional.

  • Color only: %b
  • Modifier only: %_u
  • Color and modifier: %b_u
  • Multiple modifiers: %b_u,s

All possible colors

{
    b: black,
    bb: bgBlack,
    bbr: blackBright,
    bbbr: bgBlackBright,
    r: red,
    br: bgRed,
    rbr: redBright,
    brbr: bgRedBright,
    g: green,
    bg: bgGreen,
    gbr: greenBright,
    bgbr: bgGreenBright,
    y: yellow,
    by: bgYellow,
    ybr: yellowBright,
    bybr: bgYellowBright,
    bl: blue,
    bbl: bgBlue,
    blbr: blueBright,
    bblbr: bgBlueBright,
    m: magenta,
    bm: bgMagenta,
    mbr: magentaBright,
    bmbr: bgMagentaBright,
    c: cyan,
    bc: bgCyan,
    cbr: cyanBright,
    bcbr: bgCyanBright,
    w: white,
    bw: bgWhite,
    wbr: whiteBright,
    bwbr: bgWhiteBright,
    gr: gray,
    black: black,
    bgBlack: bgBlack,
    blackBright: blackBright,
    bgBlackBright: bgBlackBright,
    red: red,
    bgRed: bgRed,
    redBright: redBright,
    bgRedBright: bgRedBright,
    green: green,
    bgGreen: bgGreen,
    greenBright: greenBright,
    bgGreenBright: bgGreenBright,
    yellow: yellow,
    bgYellow: bgYellow,
    yellowBright: yellowBright,
    bgYellowBright: bgYellowBright,
    blue: blue,
    bgBlue: bgBlue,
    blueBright: blueBright,
    bgBlueBright: bgBlueBright,
    magenta: magenta,
    bgMagenta: bgMagenta,
    magentaBright: magentaBright,
    bgMagentaBright: bgMagentaBright,
    cyan: cyan,
    bgCyan: bgCyan,
    cyanBright: cyanBright,
    bgCyanBright: bgCyanBright,
    white: white,
    bgWhite: bgWhite,
    whiteBright: whiteBright,
    bgWhiteBright: bgWhiteBright,
    gray: gray
}

All possible modifiers

{
    d: dim,
    h: hidden,
    i: italic,
    u: underline,
    s: strikethrough,
    b: bold,
    r: reset,
    dim: dim,
    hidden: hidden,
    italic: italic,
    underline: underline,
    strikethrough: strikethrough,
    bold: bold,
    reset: reset
}

NOTE:

You can only pass one color unlike modifiers which can be stacked by seperating them with a comma.

Additional Methods & Properties

  • resolveLevel: Method - This just returns the level you want but padded by spaces so all levels are the same length.
  • color: Method - Takes a function that takes a string or number and returns a string. It either applies the color to the string or returns it as is depending on whether or not colors are disabled.
  • stringifyArg: Method - Stringifies whatever you pass into it.
  • formatArgs: Method - Takes a message as the first argument and an array of arguments as the second one. This is the function that handles all colors and modifiers.
  • table: Method - Creates a table. Documentation available here.
  • createTableStream: Method - Creates a table stream. Documentation available here.
  • progress: Method - Creates a progress bar. Documentation available here.
  • isColorEnabled: Property - Returns a boolean that indicates whether colors are enabled or not.
  • logger: Property - Returns the winston logger used under the hood.