antfu / log-editor

🐞 Use your editor to inspect the log instead of scrolling the congested terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

log-editor

NPM version

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-editor

Add 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 the editor you are using, 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 extension

Sponsors

License

MIT License Β© 2021 Anthony Fu

About

🐞 Use your editor to inspect the log instead of scrolling the congested terminal

License:MIT License


Languages

Language:TypeScript 100.0%