mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 02:19:08 +00:00
first sync
This commit is contained in:
parent
5d6f382c8a
commit
a4acc441ea
52 changed files with 28315 additions and 0 deletions
56
Server/logger.js
Normal file
56
Server/logger.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
const chalk = require('chalk')
|
||||
// const { debug } = require('yargs').argv
|
||||
// process.env.DEBUG = process.env.DEBUG || debug
|
||||
// logger template//
|
||||
// const log = new (require('../logger'))('server/thing')
|
||||
|
||||
class Logger {
|
||||
constructor (name, debugOverride = false) {
|
||||
this.name = name
|
||||
this.debugOn = (process.env.DEBUG === 'true' || process.env.DEBUG === '*') || debugOverride
|
||||
}
|
||||
|
||||
fatal (text, ...data) {
|
||||
this.error(text, data)
|
||||
|
||||
if (typeof data[data.length - 1] === 'number') {
|
||||
process.exit(data[data.length - 1])
|
||||
}
|
||||
|
||||
throw text
|
||||
}
|
||||
|
||||
error (text, ...data) {
|
||||
console.error(chalk.red.bold(`ERR ${this.name}:`) + `\n ${text}`, data)
|
||||
}
|
||||
|
||||
warn (text, ...data) {
|
||||
console.warn(chalk.yellow.bold(`WARN ${this.name}:`) + `\n ${text}`, data)
|
||||
}
|
||||
|
||||
notice (text, ...data) {
|
||||
console.log(chalk.cyan.bold(`NOTICE ${this.name}:`) + `\n ${text}`, data)
|
||||
}
|
||||
|
||||
info (text, ...data) {
|
||||
console.info(chalk.blue.bold(`INFO ${this.name}:`) + `\n ${text}`, data)
|
||||
}
|
||||
|
||||
request (text, ...data) {
|
||||
console.info(chalk.green.bold(`HTTP ${this.name}:`) + `\n ${text}`)
|
||||
}
|
||||
|
||||
debug (text, ...data) {
|
||||
if (this.debugOn) {
|
||||
console.log(chalk.gray.bold(`DEBUG ${this.name}:`) + `\n ${text}`, data)
|
||||
}
|
||||
}
|
||||
|
||||
sql (logger, ...data) {
|
||||
if (logger.debugOn) {
|
||||
console.log(chalk.bold('DEBUG SQL:\n '), data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Logger
|
Loading…
Add table
Add a link
Reference in a new issue