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

logger-colors

v1.2.2

Published

Print logs with color and save them to a file at the same time

Downloads

8

Readme

logger-colors npm version npm licence npm installs npm bundle size

Utilities for printing and writing logs for Node.Js

         

Install

npm install -s logger-colors

Demo

import { Logger, LColor } from 'logger-colors';


let myLogger = new Logger({
    operationId: 'demo',
    centerColumns: 50,
});
myLogger.info(`Info`);
myLogger.error("Error");
myLogger.success("Success");
myLogger.warn("Warn");

myLogger.cyan("Cyan");
myLogger.magenta("Magenta");

myLogger.info(spacer(50));

const center = true;
myLogger.info(`Info-Center`, center);
myLogger.error("Error-Center", center);
myLogger.success("Success-Center", center);
myLogger.warn("Warn-Center", center);

myLogger.magenta(`a${LColor.c_green}b${LColor.c_yellow}c`, true);

myLogger.info(
    `${LColor.c_gray}Gray` +
    `${LColor.c_red} Red` +
    `${LColor.c_green} Green` +
    `${LColor.c_yellow} Yellow` +
    `${LColor.c_magenta} Magenta` +
    `${LColor.c_cyan} Cyan` +
    `${LColor.c_white} White`,
);

Will become:

logger-colors demo

         

Methods

  • Logger.info

| method | description | |:---|:---| |logger.info(str, center=false)|prints an info log (grey color) | |logger.error(str, center=false)|prints an error log (red color) | |logger.success(str, center=false)|prints an success log (green color) | |logger.warn(str, center=false)|prints an warn log (yellow color) | |logger.magenta(str, center=false)|prints an magenta color log| |logger.cyan(str, center=false)|prints an cyan color log|

Options

| option | type | default | description | |---:|:---:|:---:|:---| | timeZone | string | 'America/Mexico_City' | https://en.wikipedia.org/wiki/List_of_tz_database_time_zones | | timeFormat | string | 'DD-MM-YYYY HH:mm:ss.SSS' | momentjs format string | | languaje | string | 'es' | languaje string for date (moment locale) | centerColumns | number | 50 | This option centers the content of the log in the indicated, eg. 'a', centered at 5 will become ' a ' | | operationId | string | null | Used for easy identification of logs, will be present after the datetime in each log | writeToFile | WriteToFileOptions | | Options for writing the log to an external file

WriteToFileOptions

| option | type | default | description | |---:|:---:|:---:|:---| | enabled | boolean | false | if enabled then the logs will be writted to the file | preserveColors | boolean | true | if the colors want to be preserved, this will look bad if you open the log file in a non-compatible terminal or if you want to process the log info, useful just for searching with cat/grep | fileName | boolean | log | name of the file to save | fileExtension | boolean | txt | the output will be text, the extension is just for the filename | directory | boolean | /logs | directory name, snippet %date% can be used and will be replaced with the current date when writing the file, eg. /etc/logs/my-logs-%date% ==> /etc/logs/my-logs-2021-01-01 | createDirIfNotExists | boolean | true | whether or not the directory should be created if it does not exists

     

You can also prefix your string with one of this variables to have multiple colors in one line:

import { LColor } from 'logger-colors';
  • LColor.c_gray
  • LColor.c_green
  • LColor.c_red
  • LColor.c_yellow
  • LColor.c_magenta
  • LColor.c_cyan
  • LColor.c_white

Note: All the logs are printed internally using console.log, so this is not useful if you want to handle errors/debug logs with stdout and stderr, everything is sent to stdout.