2017-04-22 22:49:49 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
var websocket = null
|
2017-04-22 22:49:49 +00:00
|
|
|
|
2017-04-26 22:01:48 +00:00
|
|
|
var logger = (function () { // eslint-disable-line no-unused-vars
|
2017-05-02 14:17:36 +00:00
|
|
|
const sep = '\n/* ### NEXT TESTCASE ############################## */'
|
2017-05-02 14:26:49 +00:00
|
|
|
const color = {
|
2017-06-10 05:06:31 +00:00
|
|
|
red: '\u{1b}[1;31m',
|
|
|
|
green: '\u{1b}[1;32m',
|
|
|
|
clear: '\u{1b}[0m'
|
2017-04-25 22:21:31 +00:00
|
|
|
}
|
2017-04-25 17:59:34 +00:00
|
|
|
if (utils.platform.isWindows) {
|
2017-05-02 14:26:49 +00:00
|
|
|
color.red = ''
|
|
|
|
color.green = ''
|
|
|
|
color.clear = ''
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function console (msg) {
|
2017-04-22 22:49:49 +00:00
|
|
|
if (websocket) {
|
2017-04-25 22:21:31 +00:00
|
|
|
websocket.send(msg)
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2017-04-25 15:22:15 +00:00
|
|
|
if (typeof window === 'undefined') {
|
2017-05-02 19:32:03 +00:00
|
|
|
print(msg) // eslint-disable-line no-undef
|
2017-04-22 22:49:49 +00:00
|
|
|
} else if (window.dump) {
|
2017-04-25 22:21:31 +00:00
|
|
|
window.dump(msg)
|
2017-04-22 22:49:49 +00:00
|
|
|
} else if (window.console && window.console.log) {
|
2017-04-25 22:21:31 +00:00
|
|
|
window.console.log(msg)
|
2017-04-22 22:49:49 +00:00
|
|
|
} else {
|
2017-04-25 22:21:31 +00:00
|
|
|
throw new Error('Unable to run console logger.')
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function dump (msg) {
|
|
|
|
console(msg)
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-28 00:16:34 +00:00
|
|
|
function dumpln (msg) {
|
|
|
|
dump(msg + '\n')
|
|
|
|
}
|
|
|
|
|
2017-06-13 18:25:22 +00:00
|
|
|
function log (msg) {
|
2017-06-28 00:16:34 +00:00
|
|
|
dumpln('/*L*/ ' + utils.script.safely(msg))
|
2017-06-13 18:25:22 +00:00
|
|
|
}
|
|
|
|
|
2017-06-28 00:16:34 +00:00
|
|
|
function info (msg) {
|
|
|
|
dumpln('/*L*/ /* ' + msg + ' */')
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function error (msg) {
|
|
|
|
dumpln(color.red + msg + color.clear)
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-10 11:04:47 +00:00
|
|
|
function ok (msg) { // eslint-disable-line no-unused-vars
|
2017-06-10 06:35:35 +00:00
|
|
|
dumpln(color.green + msg + color.green)
|
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function JSError (msg) {
|
2017-06-15 16:41:03 +00:00
|
|
|
error('/* ERROR: ' + msg + ' */')
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function comment (msg) {
|
2017-07-07 15:24:09 +00:00
|
|
|
dumpln('/*L*/ // ' + msg)
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function separator () {
|
|
|
|
dumpln(color.green + sep + color.clear)
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function traceback () {
|
|
|
|
error('===[ Traceback ]')
|
2017-04-22 22:49:49 +00:00
|
|
|
try {
|
2017-04-25 22:21:31 +00:00
|
|
|
throw new Error()
|
2017-04-22 22:49:49 +00:00
|
|
|
} catch (e) {
|
2017-04-25 22:21:31 +00:00
|
|
|
dump(e.stack || e.stacktrace || '')
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2017-06-10 04:09:20 +00:00
|
|
|
error('================')
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
console: console,
|
|
|
|
dump: dump,
|
2017-06-13 18:25:22 +00:00
|
|
|
log: log,
|
2017-06-28 00:16:34 +00:00
|
|
|
info: info,
|
2017-04-22 22:49:49 +00:00
|
|
|
error: error,
|
|
|
|
JSError: JSError,
|
|
|
|
dumpln: dumpln,
|
|
|
|
comment: comment,
|
|
|
|
separator: separator,
|
|
|
|
traceback: traceback
|
2017-04-25 22:21:31 +00:00
|
|
|
}
|
|
|
|
})()
|