Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add ability to "eject" a set of debug logs #549

Closed
karimsa opened this issue Feb 28, 2018 · 4 comments
Closed

Feature request: Add ability to "eject" a set of debug logs #549

karimsa opened this issue Feb 28, 2018 · 4 comments
Labels
awaiting-response This issue or pull request is awaiting a user's response feature This proposes or provides a feature or enhancement question This issue asks a question or requests usage support

Comments

@karimsa
Copy link

karimsa commented Feb 28, 2018

The current pattern of explicitly enabling debug logs via the DEBUG= environment variable works well for server environments. But when using the debug module in a test environment or with a CLI, it is helpful to be able to "eject" a set of debug logs into either a log file or to send them remotely to a bug tracker.

A good example of this is how npm runs silently (usually), but on failure, it generates a npm-debug.log file in the working directory with its hidden debug log messages. It would be nice to have this as a built-in feature in debug rather than implementing it in each individual use case.

I could possibly open a PR for this after some discussion around the API/design - if this seems like a feature that you would like to have in debug

@Qix-
Copy link
Member

Qix- commented Jun 20, 2018

Could you better explain what you mean by this? You mean you want to redirect certain namespaces to different places (e.g. a file)?

@Qix- Qix- added feature This proposes or provides a feature or enhancement awaiting-response This issue or pull request is awaiting a user's response question This issue asks a question or requests usage support labels Jun 20, 2018
@karimsa
Copy link
Author

karimsa commented Jun 20, 2018

Yeah, pretty much. Something like this:

https://github.com/hoppjs/hopp/blob/master/packages/hopp/src/utils/log.js#L86

https://github.com/hoppjs/hopp/blob/master/packages/hopp/src/utils/log.js#L127

But pushing into an array is a terrible idea (unless there is a max size).

@karimsa
Copy link
Author

karimsa commented Jun 20, 2018

The equivalent of something like this:

const debug = require('debug')('my-app')
const fs = require('fs')

const logFile = fs.createReadStream('my-app-debug.log')
debug.log = msg => logFile.write(`${msg}\n`)

But there are a few issues with this:

  • Can't redirect logs that don't belong to this logger
    • i.e. every module in our app currently creates different namespaces but following the pattern foko:... so I'd like to be able to just say foko:* -> log-file in a single place instead of doing this per-file.
    • also want to be able to redirect logs from other 3rd party namespaces like nightmare

Perhaps something along these lines:

const createDebugger = require('debug')
const debug = createDebugger('my-app')

createDebugger.stream(['my-app:*', 'nightmare'])
  .pipe(fs.createReadStream('my-app-debug.log'))

@Qix-
Copy link
Member

Qix- commented Dec 18, 2018

See #556 :)

@Qix- Qix- closed this as completed Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-response This issue or pull request is awaiting a user's response feature This proposes or provides a feature or enhancement question This issue asks a question or requests usage support
Development

No branches or pull requests

2 participants