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
push/pop() context #6
Conversation
withContext(context) creates new
Added withContext() method to the pull request, so now it's also possible to do it like this:
|
This looks interesting. Need some time to examine it. |
Now pop() can receive `amount`, so: - `logger.pop()` as well as `logger.pop(0)` equals to `logger.pop(1)` - `logger.pop(-1)` equals to `logger.pop().pop().pop()`, when `logger` had three contexts registered
I have improved test to be more visual. Also I have improved |
Ok, lots of prep coming for NodeConf on our end. Will try to get this merged in before then. |
Ok. Now it really works as expected ;)) |
+1, also great for contextual information, such as associating user id / tracker with log statements for the same request. e.g.
results in
this way it is easy to filter, even if concurrent requests mingle and have overlapping log lines. Today, we just pass |
This shoud be rewritten. I agree about push/pop is not the best naming. IMHO the API should be like this: // sync style
var ctx_logger = logger.context('foobar');
// async style (if callback given)
logger.context('foobar', function (logger) {
// logger is context'ed logger here
}); |
I actually like the push/pop syntax a lot more. Either one would be good, but there something missing from the I'd love to start using this! |
Well, probably you're right. Basically I'm not against any name :)) so even if it will be push/pop then, probably it will be even more nicer: //
// no block style, modify current logger's context
//
logger.push('a');
logger.debug('foobar');
// -> debug: [a] foobar
logger.push('b');
logger.debug('foobar');
// -> debug: [a - b] foobar
logger.pop();
logger.debug('foobar');
// -> debug: [a] foobar
//
// with block style, clone logger with new context
//
logger.push('c', function (logger) {
setTimeout(function () {
logger.debug('foobar');
// -> debug: [a - c] foobar
}, 10000);
});
logger.debug('foobar');
// -> debug: [a] foobar @indexzero if you're OK with proposal, I'll be glad to update refactor and resend pull request |
I'm not a fan of this API, but considering that I cant come up with a better naming convention and the value of the feature it makes sense. It should, however, be consistent with Javascript. It is not |
With all respect, I must disagree. We are pushing new value to the end of the context. And then poping one last value out. Anyway this names were chosen not just because I like pushing'n'popping :)) but because this feature was "inspired" by |
IMHO, shift/unshift is for arrays only - push/pop is more "natural" for loger object. Anyway, nobody prohibits you to make alises, if methods name is a principal question. |
This proposal adds a diagnostic context. Which in fact is some kind of array of breadcrumbs. In context of method naming conventions:
Everytime we add new nested level - means we get deeper, so I really thing that
|
@indexzero can you please clarify your current position? Because I would like to fix my pull request in order to accelerate it's merge in ;)) as we wait almost one year now :)) |
Sorry guys. Been swamped with work at Nodejitsu. I don't like inconsistent semantics, but I agree that //
// no block style, modify current logger's context
//
logger.prefix('a');
logger.debug('foobar');
// -> debug: [a] foobar
logger.prefix('b');
logger.debug('foobar');
// -> debug: [a - b] foobar
logger.unprefix();
logger.debug('foobar');
// -> debug: [a] foobar
//
// with block style, clone logger with new context
//
logger.prefix('c', function (logger) {
setTimeout(function () {
logger.debug('foobar');
// -> debug: [a - c] foobar
}, 10000);
});
logger.debug('foobar');
// -> debug: [a] foobar |
If it's a big deal to have prefix/unprefix (btw by it's nature it should be I believe that we must think about programmers. And I believe 100% of programmers (at least those who wasn't jailed in visual programming world of D bemole) will easily recognize push/pop :)) So I really think that having push/pop with prefix/unprefix aliases to them will be the best way. |
group / ungroup, offered by alampros, is also nice. |
@indexzero, please, implement the way you like (method names etc) so rest of us will be able to start using it and bind our own aliases in worst case. |
indexzeeeeroooooooo !!! we are missing you :) |
+1 to the functionality. Bring it on whatever you call it. |
All, serious work at Nodejitsu is taking up my time this week. I know I owe some action here. I will get to it this weekend. |
+1 |
I'm sorry to do this, but I'm going to close this pull request unmerged because, well, it's a year old. Again: I'm sorry. If you would like to try again against the current codebase, I'll do my very best to handle it in a timely manner. |
@jesusabdullah I really need something like this, so I will implement it. But I would need to know what the preferred api is now, so it really gets merged and doesn't rot for a year. |
@dignifiedquire It should look like #208. @clintandrewhall is a hero |
I know this issue was closed quite some time ago, but still - was this feature implemented somehow? This is a great idea with the prefixes I would love to use in my projects. |
@lobodpav Check the previously-mentioned pull request...? |
Well, I can do that, but this branch is quite an old one, isn't it? Was mainly wondering if this will ever became a part of a stable release. |
This patch gives ability to push and then pop context. e.g.:
will produce something like: