@steambrew/client
Version:
A support library for creating plugins with Millennium.
44 lines (43 loc) • 1.91 kB
JavaScript
const styles = {
module: 'background: white; color: black; padding: 2px 6px; font-weight: bold;',
name: 'background: rgb(181, 181, 181); color: black; padding: 2px 6px; font-weight: bold;',
reset: 'background: transparent;',
debug: 'background: #1abc9c; color: white; padding: 2px 6px; font-weight: bold;',
warn: 'background: #ffbb00; color: white; padding: 2px 6px; font-weight: bold;',
error: 'background: #FF0000; color: white; padding: 2px 6px; font-weight: bold;',
};
const format = (moduleName, name, style) => [`%c${moduleName}%c${name}%c`, styles.module, style, styles.reset];
export const log = (moduleName, name, ...args) => console.log(...format(moduleName, name, styles.name), ...args);
export const group = (moduleName, name, ...args) => console.group(...format(moduleName, name, styles.name), ...args);
export const debug = (moduleName, name, ...args) => console.debug(...format(moduleName, name, styles.debug), ...args);
export const warn = (moduleName, name, ...args) => console.warn(...format(moduleName, name, styles.warn), ...args);
export const error = (moduleName, name, ...args) => console.error(...format(moduleName, name, styles.error), ...args);
export const groupEnd = (...args) => {
console.groupEnd();
if (args.length)
console.log(...args);
};
export default class Logger {
constructor(name, moduleName = 'Millennium') {
this.name = name;
this.moduleName = moduleName;
}
log(...args) {
log(this.moduleName, this.name, ...args);
}
debug(...args) {
debug(this.moduleName, this.name, ...args);
}
warn(...args) {
warn(this.moduleName, this.name, ...args);
}
error(...args) {
error(this.moduleName, this.name, ...args);
}
group(...args) {
group(this.moduleName, this.name, ...args);
}
groupEnd(...args) {
groupEnd(...args);
}
}