Neil Patrick's Mansion

    @sapphire/plugin-logger
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.1 • Public • Published

    Sapphire Logo

    @sapphire/plugin-logger

    Plugin for @sapphire/framework to have pretty console output.

    GitHub codecov npm bundle size npm

    Description

    A Logger implementation that implements Sapphire's ILogger interface and implements timestamp and style formatting with the blazing fast colorette library.

    Features

    • Fully ready for TypeScript!
    • Includes ESM ready entrypoint
    • NO_COLOR friendly, inherited by colorette

    Installation

    @sapphire/plugin-logger depends on the following packages. Be sure to install these along with this package!

    You can use the following command to install this package, or replace npm install with your package manager of choice.

    npm install @sapphire/plugin-logger @sapphire/framework

    Usage

    This registers the necessary options and methods in the Sapphire client to be able to use the log plugin.

    // Main bot file
    // Be sure to register the plugin before instantiating the client.
    import '@sapphire/plugin-logger/register';

    In order to use the Logger in any place other than a piece (commands, arguments, preconditions, etc.), you must first import the container property of @sapphire/framework. For pieces, you can simply use this.container.logger to access Logger methods.

    import { container } from '@sapphire/framework';
    
    export class MyAwesomeService {
    	public printAwesomeLog() {
    		container.logger.info('log message');
    	}
    }

    Here is an example ping command, demonstrating the use of this.container.logger from within a piece by omitting the explicit import.

    // ping command
    
    import { Command } from '@sapphire/framework';
    import type { Message } from 'discord.js';
    
    export class PingCommand extends Command {
    	public constructor(context: Command.Context, options: Command.Options) {
    		super(context, {
    			...options,
    			description: 'ping pong'
    		});
    	}
    
    	public async messageRun(message: Message) {
    		this.container.logger.warn('warning message');
    	}
    }

    Types of logs

    1. trace
    2. debug
    3. info
    4. warn
    5. error
    6. fatal

    Example: container.logger.debug('log debug message');

    Buy us some doughnuts

    Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!

    We accept donations through Open Collective, Ko-fi, Paypal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.

    Donate With Address
    Open Collective Click Here
    Ko-fi Click Here
    Patreon Click Here
    PayPal Click Here

    Contributors

    Thanks goes to these wonderful people (emoji key):


    Jeroen Claassens

    💻 🚇 📆

    Nejc Drobnic

    💻 📖

    Antonio Román

    💻

    Vlad Frangu

    👀

    depfu[bot]

    🚧

    dependabot[bot]

    🚧

    allcontributors[bot]

    📖

    Tyler J Russell

    💻 📖

    Stitch07

    💻 🐛

    PlatinBae

    📖

    Kaname

    💻 📖

    Elliot

    💻

    Lioness100

    💻 📖

    UndiedGamer

    💻

    Feralheart

    💻

    Jurien Hamaker

    💻

    renovate[bot]

    🚧

    WhiteSource Renovate

    🚧

    c43721

    💻

    megatank58

    💻

    FC

    💻

    Just a Badly Drawn TABS Dude

    💻

    newt :D

    💻

    Mzato

    💻

    Harry Allen

    💻

    Julian

    💻

    Krish

    💻

    Parbez

    💻

    ricardooow

    💻

    This project follows the all-contributors specification. Contributions of any kind welcome!

    Install

    npm i @sapphire/plugin-logger

    DownloadsWeekly Downloads

    2,000

    Version

    3.0.1

    License

    MIT

    Unpacked Size

    65.1 kB

    Total Files

    32

    Last publish

    Collaborators

    • favna
    • kyranet
    • vladfrangu