/*
* This file is part of ORY Editor.
*
* ORY Editor is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ORY Editor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ORY Editor. If not, see .
*
* @license LGPL-3.0
* @copyright 2016-2018 Aeneas Rekkas
* @author Aeneas Rekkas
*
*/
// tslint:disable:no-console
const trace = (): Array => {
const e = new Error('dummy');
return e.stack
.replace(/^[^(]+?[\n$]/gm, '')
.replace(/^\s+at\s+/gm, '')
.replace(/^Object.\s*\(/gm, '{anonymous}()@')
.split('\n');
};
export class Logger {
/**
* Logs a warning. Warnings are things that are exceptional, but easily to recover from.
*/
// tslint:disable-next-line:no-any
warn(...args: any[]) {
console.warn('Warning:', ...args);
}
/**
* Logs a debug message. Debug messages are things that help developers debugging things.
*/
// tslint:disable-next-line:no-any
debug(...args: any[]) {
console.log('Debug:', ...args);
}
/**
* Logs an info. Infos are things that might be interesting for someone who needs to take a closer look.
*/
// tslint:disable-next-line:no-any
info(...args: any[]) {
console.log('Info:', ...args);
}
/**
* Logs an error. Error are things that are exceptional, but can be recovered from.
*/
// tslint:disable-next-line:no-any
error(...args: any[]) {
console.error('Error:', ...args);
console.error('Trace:', trace());
}
/**
* Logs a fatal error. Fatal errors are things that are exceptional and can not be recovered from.
*/
// tslint:disable-next-line:no-any
fatal(...args: any[]) {
console.error('Fatal:', ...args);
console.error('Trace:', trace());
throw new Error(args.join(' '));
}
/**
* Logs a message.
*/
// tslint:disable-next-line:no-any
log(...args: any[]) {
console.log('Fatal:', ...args);
console.log('Trace:', trace());
}
}
const instance = new Logger();
export default instance;