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

utils-logger-av

v2.0.0

Published

Backend colored logs

Downloads

247

Readme

Utils Logger Av

v2.0.0

This is a package i made for myself but can surely be helpful to others, feel free to contribute if you like it.

Install:

npm install utils-logger-av

The Logger is just an exported class, the interface is as it follows:

Logger Class

interface ILogger {
    logDetail: (coloredMessage:any, ...messages:any[]) => void;
    logError: (coloredMessage:any,...errs:any[]) => void;

    base: (coloredMessage:any, ...messages:any[]) => void;
    white: (coloredMessage:any, ...messages:any[]) => void;
    green: (coloredMessage:any,...messages:any[]) => void;
    yellow: (coloredMessage:any,...messages:any[]) => void;
    blue: (coloredMessage:any,...messages:any[]) => void;
    magenta: (coloredMessage:any,...messages:any[]) => void;
    cyan: (coloredMessage:any,...messages:any[]) => void;
    gray: (coloredMessage:any,...messages:any[]) => void;
    orange: (coloredMessage:any,...messages:any[]) => void;
    pink: (coloredMessage:any,...messages:any[]) => void;
    purple: (coloredMessage:any,...messages:any[]) => void;
    teal: (coloredMessage:any,...messages:any[]) => void;
    brown: (coloredMessage:any,...messages:any[]) => void;
    lime: (coloredMessage:any,...messages:any[]) => void;
    gold: (coloredMessage:any,...messages:any[]) => void;
    violet: (coloredMessage:any,...messages:any[]) => void;

    logFile: (message:string, type?:"log" | "error", isClosing?:boolean) => void;
}


private readonly fileStream:WriteStream = null!;
private readonly isDebug:boolean = true;
protected readonly dateLocale:DateLocales = "it-IT";
protected readonly primaryColor:LogColors = null;
protected readonly isErrorStackFull:boolean = false;
constructor(data?:LoggerConstructor) {
	if (data?.logFilePath) this.fileStream = createWriteStream(data.logFilePath, { flags: 'a' });
}

export interface LoggerConstructor {
    logFilePath?:string,
    debug?:boolean,                 // if set to false, there won't be any more log.
    locale?: DateLocales,           // to set the locale timezone view
    primaryColor?:LogColors,        // set your color for the "base" method. default is white
    isErrorStackFull?:boolean       // if set to true, logError will log the full stack trace
}

Initialize the class

import { Logger } from "utils-logger-av"

You can export the default class like

const log = new Logger({ primaryColor:"cyan" });
export { log }

Or creating a new class extending mine to add some custom utilities

class MyLogger extends Logger
{
    public baseFile = (message:any, type:FileLogType, isClosing:boolean = true) => {
        this.base(message);
        this.logFile(message, type, isClosing)
    }
}

const log = new MyLogger({
    debug:true,
    logFilePath: "../files/logs.txt",
    primaryColor: "cyan"
});


export { log };

Use the logger

You can now import the log object and call the related methods:

import { log } from "./your/filepath"; // I'm confident about your ide auto-import features

log.color("green", "Ciao")
log.base("Hello there, this is a log");
log.baseFile("Hello there", "log", false);
log.baseFile("An Error", "error");


log.orange("Another test", { test: 1, test2: true, prova: { test3: [ "Hello", 2, false] } }, false, 12.3);
log.white("This is white")
log.blue("This is blue")
log.brown("This is brown")
log.logError("This is an error", "err")
log.lime("This is lime")
log.teal("This is teal")
log.magenta("This is magenta")