-
Notifications
You must be signed in to change notification settings - Fork 939
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
RFC: 3.0 API & Ideas #370
Comments
#343 - Middleware use case |
@thebigredgeek I am not sure if this came up somewhere else of there is already a solution in place but it would be nice to be able to switch between Example: import createDebug from 'debug'
const debug = createDebug('app:upload')
Promise.reject(new Error('Something terrible happened O_O'))
.catch((err) => debug.error(err.message))
Promise.resolve({ status: 'ok' })
.then((data) => debug(data.status)) |
@kilianc Seems like that case could be solved via a combination of child instances and middleware: import debug, { StdoutMiddleware } from 'debug';
const appUploadLog = debug('app:upload');
const appUploadErrLog = appUploadLog
.child('error')
.replace(StdoutMiddleware, (data, next) => {
console.error.apply(console, data);
next()
}); |
Hi, sorry if I missed something but, does |
@ibc We are still considering |
@thebigredgeek, following @ibc's comment, i am a contributor to a plugin for an application. the applications manages all config and hands the plugin a config object at initialisation time. it is normal practice that users of the application turn logging on/off through the config object. so i needed to be able to individually enable/disable debug 'channels' at runtime. i extended @tehsenaus's excellent basically, i'm hoping that v3 will allow (either directly or via its own plugin middleware layer): var debug = require('debug')('myPlugin')
...
function myInit(config) {
debug.enable(config.debugEnabled)
} |
What @VBAssassin wrote is a very good idea. I've used this to great effect in a logging class I wrote for use in many projects I've worked on. It also helps mitigate the overhead in the case where logging is disabled, or that particular logger is disabled. |
Apologizes or enlighten me if this is already in: I often face the issue that debug instrumentation bogs down performance.
So i end up with Suggestion is to change the signature to evaluate (lazily) if passed a function
Currently it recognizes the arg as a function and outputs:
|
Couldn't it just internally check |
@jfseb Use the debuglog(" inspect this > %j", bitstuff); That way you're just passing in an argument to a noop function when debug is not enabled. Then the processing happens under the hood when debug is enabled. |
@TooTallNate works for this simple JSON case, but not sure about @VBAssassin's example |
My recommendation was actually a duplicate, thanks @PixnBits and @VBAssassin. |
@VBAssassin Can you not already do this?
IMO the above is more readable, and more efficient as you're not creating a closure. |
@tehsenaus your code is lack encapsulation, it requires to know about |
I like the simple syntax of the closure- I'm much more likely to use it.
And because it uses the same form as console.log() I don't have to
remember a special syntax.
…On 5/30/17 7:06 AM, Sean Micklethwaite wrote:
@VBAssassin <https://github.com/vbassassin> Can you not already do this?
|if ( debug.enabled ) { debug(mysql.format(sql,values)); } |
IMO the above is more readable, and more efficient as you're not
creating a closure.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#370 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC5InJQhkOLTUKoIn-7fGQXk6Qx4Xc4ks5r-_gcgaJpZM4LNeHb>.
|
@talkingtab how is it the same form as console.log? @StreetStrider can you comment on readability? As far as encapsulation goes, I think |
@tehsenaus, to be honest, I think closure got better readability too. But it depends on person itself (partly). 🤔 It's like |
I just mean they take the same arguments: |
@StreetStrider @tehsenaus Another way of writing this, given debug.enabled && debug(mysql.format(sql, values); That might be a little more friendly, visually, and it still ensures that whatever code is on the right side of |
debug simplicity come from the initial, user defined DEBUG env contract "What i care about".
Registering additional formaters should be part of debug API, yet, leaving the user choosing, very simply, what he desired (the same way he choose the namespaces he cares about) Is there anyone sharing this view ? |
Just throwing this out there - since this will be a major release I assume, the LTS schedule for Node should be closely followed. Right now, Node 5 is in LTS, which means es2015 should be safely distributable without the need for transpilation. |
@Qix- You mean Node 4? Also: this is transpiled for the frontend, as well as being available on the backend. It's safest and least problematic to stick to a widely-supported subset of JS when making code available for three platforms (Node, Electron, and front-end). |
@Qix- haha yeah I wish it was that simple. This lib is used in electron, browser, etc as well as Node. So probably not going to work out so well without transpilation :(. That said, because of the number of platforms we are supporting I do think there could be value in using a compiler step to normalize interfaces between environments. @TooTallNate |
@thebigredgeek I mean, I did remove the transpilation step by just rewriting the thing in ES5 code ;P |
@yamikuronue Node 4 is in maintenance LTS. Node 5 is currently the active LTS version. |
@qix meaning Node 4 still has support. My company is skipping 5 because 4 is still in support and we might as well go to 6 as we upgrade in anticipation of losing that support. So I'm hesitant to recommend the idea that 5 is safe to assume for a widely used utility. |
Oops you're right @yamikuronue - 5.x is skipped, 6.x is now active LTS. 4.x is still maintenance, which means versions of software that still work for 4.x should backport any major bugfixes to it. |
I think it would nice to be able specify my own color for a namespace or even a single call to log some output |
Hey everyone,
I figured it's time to start discussing the API for V3.
A few fundamental ideas to get started:
(Yes) Formal organized schema for CHANGELOG.md
(Yes) Dead-simple generated documentation
(Yes) Time locale configuration
(Yes) Stdout moved off of APIs that are pending removal (RFC: 3.0 stdout moved off of APIs that are pending removal #280)
(No) Ability to enable/disable debug instances
(Maybe) API to overwrite/set environment variables by key (How to use with AWS Lambda (ie. w/o env vars)? #277)
Any other ideas are welcome. I'd love to have a completed first pass draft by the end of next week.
The text was updated successfully, but these errors were encountered: