smartlog-destination-local/ts/beautylog.console.ts

41 lines
992 B
TypeScript
Raw Permalink Normal View History

2018-03-01 00:06:12 +00:00
import 'typings-global';
import plugins = require('./beautylog.plugins');
import { activeOra, oraActive } from './beautylog.classes.ora';
let nativeLog = console.log;
let nativeError = console.error;
2016-05-19 17:27:09 +00:00
/**
* routes the console to got through beautylog, so beautylog can take action before things are logged to console.
*/
2018-03-01 00:06:12 +00:00
let route = function(statusArg: boolean) {
2017-08-28 11:14:35 +00:00
if (statusArg === true) {
2018-03-01 00:06:12 +00:00
console.log = beautyConsole.log;
console.error = beautyConsole.error;
2017-08-28 11:14:35 +00:00
} else {
2018-03-01 00:06:12 +00:00
console.log = nativeLog;
2017-08-28 11:14:35 +00:00
}
2018-03-01 00:06:12 +00:00
};
2016-05-19 17:27:09 +00:00
export let beautyConsole = {
2018-03-01 00:06:12 +00:00
log: function(logArg: any) {
2017-08-28 11:14:35 +00:00
if (oraActive) {
2018-03-01 00:06:12 +00:00
activeOra.pause();
nativeLog.apply(nativeLog, arguments);
activeOra.start();
2017-08-28 11:14:35 +00:00
} else {
2018-03-01 00:06:12 +00:00
nativeLog.apply(nativeLog, arguments);
2017-08-28 11:14:35 +00:00
}
},
2018-03-01 00:06:12 +00:00
error: function() {
2017-08-28 11:14:35 +00:00
if (oraActive) {
2018-03-01 00:06:12 +00:00
activeOra.pause();
nativeLog.apply(nativeError, arguments);
activeOra.start();
2017-08-28 11:14:35 +00:00
} else {
2018-03-01 00:06:12 +00:00
nativeLog.apply(nativeError, arguments);
2016-05-19 17:27:09 +00:00
}
2017-08-28 11:14:35 +00:00
}
2018-03-01 00:06:12 +00:00
};
2016-05-19 17:45:31 +00:00
2018-03-01 00:06:12 +00:00
route(true);