[英]Is it possible to pause the chrome debugger on every console.log statement executed by the JavaScript code?
[英]Log to a file from Javascript code executed with no console window
从 javascript 登录:
global.log('my message')
要检查事物,包括可能具有循环引用的对象,请定义此函数:
const inspect = (function() {
function replace_circular_references(show_private_keys) {
let fullpaths = new Map(), cleanpaths= new Map(), rootobject = null
return function(key, value) {
let decycled; {
if (!show_private_keys && key.startsWith('_')) return undefined
let path = fullpaths.get(this) + (
Array.isArray(this) ? `[${key}]` : `.${key}` )
let is_complex = value === Object(value)
if (is_complex) fullpaths.set(value, path)
let cleanpath = cleanpaths.get(value) || ''
if (!cleanpath && is_complex)
cleanpaths.set(value, path.replace(/undefined\.\.?/, ''))
decycled = cleanpath ?
`${cleanpath[0] == '[' ? '(this)' : '(this).'}${cleanpath}`
: value
if (rootobject === null) rootobject = value
else if (decycled === rootobject) { decycled = "(this)" }
}
return decycled
}
}
return function (nameofthing, thing, show_private_keys=true, fold=null) {
try {
let thingrepr; {
thingrepr = JSON.stringify(
thing, replace_circular_references(show_private_keys), '\t'
).replace(
/"([^\n"]+)"[:] /g, "$1: " // prettify keys
).replace(
/"(\(this\)[^\n"]*)"/g, "$1" // prettify circular refs
)
if (fold !== null) { // maybe fold away some things
for (const key of fold) {
thingrepr = thingrepr.replace(
new RegExp(`^([ ]*)${key}: [{][^]*?\\n\\1[}]`, 'gm'),
"$1" + key + ": {...}"
).replace(
new RegExp(`^([ ]*)${key}: \\[[^]*?\\n\\1\\]`, 'gm'),
"$1" + key + ": [...]"
)
}
}
}
global.log(`\n${nameofthing} = ${thingrepr}`)
} catch (error) {
global.log(`${nameofthing} = (oops, can not do that)`)
global.log(error)
global.log(error.message)
}
}
})()
并像这样使用它:
inspect('myobject', myobject)
或者像这样,隐藏以下划线开头的键:
inspect('myobject', myobject, false)
或者像这样,折叠您不感兴趣的特定键:
inspect('myobject', myobject, true, ['key1', 'key2', ...])
要查看记录的消息,请使用控制台或 GUI(或两者)。
tail -f ~/.xsession-errors
或者,在 Cinnamon 3.8.8 之前:
tail -f ~/.cinnamon/glass.log
按ctrl
+ c
中止记录。
要重新加载小程序:
dbus-send --session --dest=org.Cinnamon.LookingGlass -- \
type=method_call /org/Cinnamon/LookingGlass \
org.Cinnamon.LookingGlass.ReloadExtension \
string:'your-applet-uuid' \
string:'APPLET'
其中your-applet-uuid
是metadata.json中uuid
键的值。
从另一个控制台运行此命令是最简单的,因此您不必中止日志记录。
Cinnamon 也有 Melange-Cinnamon 调试器。 打开它:
Win key
+ L
。Alt
+ F2
→ 输入 "lg" → Enter
。日志记录发生在日志选项卡下。
要重新加载小程序的代码,请在扩展选项卡下找到它,右键单击 →重新加载代码。
要重新加载 Cinnamon 并执行其他操作,请使用“操作”按钮。
调试器有一个小错误,有时在记录长内容时滚动条会消失。 要取回它,请按ctrl
+ Home
和ctrl
+ End
。
要使调试器窗口位于后台,请右键单击其标题栏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.