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

myfavouritelogger

v1.5.1

Published

typescript logger using winston with cool features and easy to use

Downloads

344

Readme

myfavouritelogger

Build Status codecov npm version

This is my favourite logger and it will be yours.

Try it!

Try on Runkit

Why use it?

  1. You want to write cool console logs (colors, dates...).
  2. You want to write file logs with daily rotation and size control.
  3. You know how to use Winston logger but you don't like how it looks out of the box.
  4. You like colors.
  5. You like customization.
  6. You like log levels.
  7. You like custom print formats.
  8. You don't want to programm all this.

How to use it?

// typescript example
import myfavouritelogger from 'myfavouritelogger';

const logger = myfavouritelogger();

logger.error('Hello world!');
logger.warn('Hello world!');
logger.info('Hello world!');
logger.debug('Hello world!'); // not shown, default level is info
// javascript example
const myfavouritelogger = require('myfavouritelogger').default;

const logger = myfavouritelogger();

logger.error('Hello world!');
logger.warn('Hello world!');
logger.info('Hello world!');
logger.debug('Hello world!'); // not shown, default level is info

How to customize it?

import myfavouritelogger from 'myfavouritelogger'; // or require in vanilla javascript

const logger = myfavouritelogger({
    printFormat: (str: string, info: TransformableInfo) => {
        if (info.level) {
            str += mapLevelColor(info.level, `[${info.level}] `);
        }

        if (info.name) {
            str += `[${info.name}] `.green;
        }

        str += `${info.message}`;

        return str;
    },
    file: {
        path: './logs/application-%DATE%.access.log',
        maxSize: '20m',
        maxFiles: '14d',
        zippedArchive: true,
        pathDatePattern: 'YYYY-MM-DD',
    },
    console: true,
    level: 'debug';
    colors: true;
    dateFormat: 'YYYY-MM-DD HH:mm:ssZ';
});

logger.error('Hello world!');
logger.warn('Hello world!');
logger.info('Hello world!');
logger.debug('Hello world!');

Options

| Option | Type | Default | Description | | -------------------- | ------------------------------------------------ | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | printFormat | (str: string, info: TransformableInfo) => string | (see below table) | Function to override the print format. str is the original string to print. info is the winston object with context info | | file.path | string | No default | Path where the log file will be written. The file name can contains %DATE% keyword for daily rotation. If this option is not present, no file will be generated | | file.maxSize | string|number | '20m' | Indicates the max size for the log file. If it reached the maximum, the file will rotate | | file.maxFiles | string|number | '14d' | Indicates the maximum number of files to store. If the files rotates to reach this number, the older files will be deleted | | file.zippedArchive | boolean | false | Indicates if the rotated files will be zipped or not | | file.pathDatePattern | string | 'YYYY-MM-DD' | If you have set a file path, this option will define the format date for the file name (check momentjs formats for complete documentation) | | console | boolean | true | Indicates if the logs will be printed n the console | | level | 'info'|'warning'|'error'|'debug' | info | The log level | | colors | boolean | true | If true, the logs will show beautiful colors | | dateFormat | string | 'YYYY-MM-DD HH:mm:ssZ' | Each log line will display the date. This option defines de date format (check momentjs formats for complete documentation) |

Default printFormat

function defaultPrint(this: any, str: string, info: TransformableInfo): string {
    if (info.level) {
        str += mapLevelColor(info.level, `[${info.level}] `);
    }
    if (info.name) {
        str += `[${info.name}] `.green;
    }

    str += `${info.message}`;

    return str;
}