log-editor v0.1.0
log-editor
Fan of using console.log to debugger? Use your editor to inspect the log instead of scrolling the congested terminal.
- console.log(largeObject)
+ console.logEditor(largeObject)Install
Only works in Node.js environment.
npm i -D log-editorAdd the following statement at the very beginning of your script:
// inject to `console`
import 'log-editor/console'Then use console.logEditor instead of console.log whenever you want to see the result in editor. It will launch the corresponsing editor powered by launch_editor.
console.logEditor(largeObject)or directly import without injection
import { logEditor } from 'log-editor'Options
Named log
Pass a second argument to specify the key. When calling same key for multiple times, the same temp file will be used and overrides the previous content.
console.logEditor(largeObject, 'foo')To accumulate the result of multiple calls, setting the override to false.
console.logEditor('message 1', 'key', { override: false })
console.logEditor('message 2', 'key', { override: false })File Extension
By default, log-editor will use log or json as the temp file's extension. You can change it by passing extension in the options so your editor could provide proper syntax hightlight for you.
const code = `import 'log-editor'`
console.logEditor(code, 'code', { extension: 'ts' })
console.logEditor({ foo: 'bar' }) // will auto infer to use `json` as extension
console.logEditor('bar') // will use `log` as extensionSponsors
License
MIT License © 2021 Anthony Fu