Skip to content

joaopmi/discord-textchannel-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Info

Simple logger for textChannels.

See NPM

Installation

npm i discord-textchannel-logger

Usage

import { initLogger, Logger } from 'discord-textchannel-logger';

initLogger(getClient());//INIT ONLY ONCE

let loggerOne: Logger = new Logger(
    {
        textChannelID: "idTextChannel",
        consoleLog: true,
        customHeaderConsole: "=== CONSOLE CUSTOM HEADER ===",
        printCurrentTimeConsole:true,
    }
);

loggerOne.log('Hello World');

let loggerTwo: Logger = new Logger(
    {
        textChannelID: "idTextChannel",
        customHeader: "=== TEXT CHANNEL CUSTOM HEADER ===",
    }
);

loggerTwo.log('Hello World 2');

export {loggerOne,loggerTwo};

Dependencies Used

discord.js: ^14.2.0
circular-reference-remover: ^1.0.5

Documentation

  • Function initLogger(client:Client):void - Accepts the Client your bot is connected to. Need to init once.

  • Class Logger - Class to send messages to textChannels and console. Needs InitOptions on constructor, if it's an invalid value, it'll throw a TextChannelNotFound.

    • Function log(value:any):void - Send value (if not undefined) to configured textChannel on InitOptions and print on console (if configured on InitOptions). If value it's a typeof object, it'll try to JSON.stringify it, unless, if it's an Error instance, it'll print its stack trace. In case of JSON.stringify failure it'll use the object.toString.
    • Function trace(value:any):void - Send value (if not undefined) to configured textChannel on InitOptions and print on console with console.trace (if configured on InitOptions). It'll do the same value conversion on log to send to TextChannel, except it'll trace the raw value — passed to this function — on console.
  • Options Logger.InitOptions -

    • console.log?:boolean - If true print the value on console. Valid for both log and trace
    • printCurrentTimeConsole?:boolean - If true print the current time as toLocaleString on console. If it's true, prints after the custom headers. Example: 'customHeaderIfExists\n' + 14/12/2021 10:39:54 ==> 'message'
    • jsonSpace?:number - The space indent of JSON.stringify on log. Default: 2
    • textChannelID:string - (Obligatory) ID of the textChannel to print on.
    • customHeader?:string - Custom log header to print along before the message
    • customHeaderConsole?:string - Custom log header to print on console before the message
  • Errors -

    • NoClientError - In case there's no client configured with initLogger
    • TextChannelNotFound - If the ID of the textChannel does not resolve to an existent channel
    • InvalidTextChannel - If the ID of the textChannel resolve to a non-textChannel

Contributing

Pull requests are welcome, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

About

Simple logger for textChannels

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published