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

better-console-log-plus

v1.4.4

Published

Simple console (colored) logger for Node.js

Downloads

41

Readme

Better Console Log Plus

Better Console Log Plus is a super efficient and performant package that enhances console logging functionality by providing colors, timestamps, and additional options to improve log readability.

Installation

npm install better-console-log-plus

Usage

const logger = require('better-console-log-plus');
// OR
import * as logger from 'better-console-log-plus';

// Example logging
logger.log('This is a log message');
logger.error('This is an error message');
logger.warn('This is a warning message');
logger.info('This is an info message');
logger.debug('This is a debug message');

The "better-console-log-plus" package provides a logger object with five available functions: log, error, warn, info, and debug. You can call these functions to log messages to the console with different levels of importance.

Additional Options

The package also offers additional options to improve the log output:

  • Arguments: You can provide additional arguments to the logging functions to include extra information in the message. These arguments will be displayed after the main message.

    logger.log('Message with arguments', { foo: 'bar' }, [1, 2, 3]);

    The above code will display the main message followed by the arguments in JSON format.

Nest.js integration

  1. Create a custom logger service in your Nest.js application.

    import { Injectable, LoggerService } from '@nestjs/common';
    import * as logger from 'better-console-log-plus';
    
    @Injectable()
    export class CustomLogger implements LoggerService {
        log(message: any, context?: string) {
            logger.log(message, context || '');
        }
    
        error(message: any, trace?: string, context?: string) {
            logger.error(message, trace || '', context || '');
        }
    
        warn(message: any, context?: string) {
            logger.warn(message, context || '');
        }
    
        debug?(message: any, context?: string) {
            logger.debug(message, context || '');
        }
    }

    The custom logger service implements the Nest.js LoggerService interface and utilizes the better-console-log-plus package for logging.

  2. Register the custom logger service in your application module.

    import { Module } from '@nestjs/common';
    import { CustomLogger } from './CustomLoggerService';
    
    @Module({
        providers: [CustomLogger],
        // ...
        exports: [CustomLogger]
    })
    export class AppModule {}

    Make sure to include the `CustomLogger` in the `providers` array of your application module.

  3. Use the custom logger throughout your application.

    import { Controller, Get, Inject } from '@nestjs/common';
    import { CustomLogger } from './CustomLoggerService';
    
    @Controller()
    export class AppController {
        constructor(private readonly _logger: CustomLogger) {}
    
        @Get()
        getData() {
            this._logger.log('Logging a message');
            this._logger.error('Logging an error');
            // ...
        }
    }

    Inject the `CustomLogger` into your controllers, services, or other components where logging is required.

Contributing

If you'd like to contribute to this package, feel free to do so. You can open an issue to report bugs or suggest improvements, or submit a pull request to contribute code.

License

This package is licensed under the MIT License. See the LICENSE file for more information.

Credits

This package was developed by Ignacio Chemes.