2016-10-16 00:26:43 +00:00
|
|
|
import 'typings-global'
|
|
|
|
import plugins = require('./beautylog.plugins')
|
2017-01-21 18:29:20 +00:00
|
|
|
import { activeOra, oraActive } from './beautylog.classes.ora'
|
2016-10-16 00:26:43 +00:00
|
|
|
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.
|
|
|
|
*/
|
2017-01-21 00:05:28 +00:00
|
|
|
let route = function(statusArg: boolean){
|
|
|
|
if (statusArg === true) {
|
2016-10-16 00:26:43 +00:00
|
|
|
console.log = beautyConsole.log
|
|
|
|
console.error = beautyConsole.error
|
2016-05-19 17:27:09 +00:00
|
|
|
} else {
|
2016-10-16 00:26:43 +00:00
|
|
|
console.log = nativeLog
|
2016-05-19 17:27:09 +00:00
|
|
|
}
|
2016-10-16 00:26:43 +00:00
|
|
|
}
|
2016-05-19 17:27:09 +00:00
|
|
|
|
|
|
|
export let beautyConsole = {
|
2017-01-21 18:29:20 +00:00
|
|
|
log: function(logArg: any) {
|
2017-01-21 00:05:28 +00:00
|
|
|
if (oraActive) {
|
2016-10-16 00:26:43 +00:00
|
|
|
activeOra.pause()
|
|
|
|
nativeLog.apply(nativeLog, arguments)
|
|
|
|
activeOra.start()
|
2016-05-19 17:27:09 +00:00
|
|
|
} else {
|
2016-10-16 00:26:43 +00:00
|
|
|
nativeLog.apply(nativeLog, arguments)
|
2016-05-19 17:27:09 +00:00
|
|
|
}
|
2016-07-23 17:47:23 +00:00
|
|
|
},
|
|
|
|
error: function(){
|
2017-01-21 00:05:28 +00:00
|
|
|
if (oraActive) {
|
2016-10-16 00:26:43 +00:00
|
|
|
activeOra.pause()
|
|
|
|
nativeLog.apply(nativeError, arguments)
|
|
|
|
activeOra.start()
|
2016-07-23 17:47:23 +00:00
|
|
|
} else {
|
2016-10-16 00:26:43 +00:00
|
|
|
nativeLog.apply(nativeError, arguments)
|
2016-07-23 17:47:23 +00:00
|
|
|
}
|
2016-05-19 17:27:09 +00:00
|
|
|
}
|
2016-05-19 17:45:31 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 00:05:28 +00:00
|
|
|
route(true)
|