2020-04-12 14:34:26 +02:00
const chalk = require ( 'chalk' ) ;
class Logger {
constructor ( client ) {
this . client = client ;
2020-04-13 22:38:10 +02:00
this . client . eventHooker . hook ( 'ready' , ( ) => {
this . info ( ` Client connected to ${ chalk . bold ( this . client . user . tag ) } with ${ chalk . bold ( ` ${ this . client . guilds . size } guild ${ this . client . guilds . size === 1 ? '' : 's' } ` ) } . ` ) ;
2020-04-12 14:34:26 +02:00
} ) ;
2020-04-13 22:38:10 +02:00
this . client . eventHooker . hook ( 'componentUpdate' , ( { component , type } ) => {
2020-04-12 14:34:26 +02:00
this . info ( ` Component ${ chalk . bold ( component . resolveable ) } was ${ chalk . bold ( Constants . ComponentTypes [ type ] ) } . ` ) ;
} ) ;
2020-04-13 22:38:10 +02:00
this . client . eventHooker . hook ( 'reconnect' , ( ) => {
this . warn ( ` Shard is reconnecting. ` ) ;
2020-04-12 14:34:26 +02:00
} ) ;
}
async transport ( message = 'N/A' , opts = { } ) {
process . send ( { message , ... opts } ) ;
}
/* Quick & Dirty Functions */
2020-04-13 22:38:10 +02:00
silly ( message , opts = { } ) {
this . transport ( message , { ... opts , type : 'silly' } ) ;
2020-04-12 14:34:26 +02:00
}
2020-04-13 22:38:10 +02:00
debug ( message , opts = { } ) {
this . transport ( message , { ... opts , type : 'debug' } ) ;
2020-04-12 14:34:26 +02:00
}
2020-04-13 22:38:10 +02:00
verbose ( message , opts = { } ) {
this . transport ( message , { ... opts , type : 'verbose' } ) ;
2020-04-12 14:34:26 +02:00
}
2020-04-13 22:38:10 +02:00
info ( message , opts = { } ) {
this . transport ( message , { ... opts , type : 'info' } ) ;
}
warn ( message , opts = { } ) {
this . transport ( message , { ... opts , type : 'warn' } ) ;
2020-04-12 14:34:26 +02:00
}
error ( message , opts = { } ) {
2020-04-13 22:38:10 +02:00
this . transport ( message , { ... opts , type : 'error' } ) ;
2020-04-12 14:34:26 +02:00
}
}
module . exports = Logger ;
const Constants = {
ComponentTypes : {
LOAD : 'loaded' ,
UNLOAD : 'unloaded' ,
RELOAD : 'reloaded' ,
ENABLE : 'enabled' ,
DISABLE : 'disabled'
}
} ;