UNPKG

rjweb-server

Version:

Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS

80 lines (79 loc) 1.54 kB
const colors = { reset: "\x1B[0m", bright: "\x1B[1m", dim: "\x1B[2m", underscore: "\x1B[4m", blink: "\x1B[5m", reverse: "\x1B[7m", hidden: "\x1B[8m", fg: { black: "\x1B[30m", red: "\x1B[31m", green: "\x1B[32m", yellow: "\x1B[33m", blue: "\x1B[34m", magenta: "\x1B[35m", cyan: "\x1B[36m", white: "\x1B[37m", gray: "\x1B[90m" }, bg: { black: "\x1B[40m", red: "\x1B[41m", green: "\x1B[42m", yellow: "\x1B[43m", blue: "\x1B[44m", magenta: "\x1B[45m", cyan: "\x1B[46m", white: "\x1B[47m", gray: "\x1B[100m", crimson: "\x1B[48m" } }; class Logger { /** * Create a new Logger instance * @since 7.4.0 */ constructor(options) { this.logs = 0; this.options = options; } /** * Log an error message * @since 7.4.0 */ error(...messages) { if (!this.options.error) return this; console.error(`${colors.bg.red} ERROR ${colors.reset}`, ...messages); this.logs++; return this; } /** * Log a warn message * @since 7.4.0 */ warn(...messages) { if (!this.options.warn) return this; console.warn(`${colors.bg.yellow} WARN ${colors.reset}`, ...messages); this.logs++; return this; } /** * Log a debug message * @since 7.4.0 */ debug(...messages) { if (!this.options.debug) return this; console.debug(`${colors.bg.blue} DEBUG ${colors.reset}`, ...messages); this.logs++; return this; } } export { colors, Logger as default };