Support for custom logger function#1468
Conversation
|
Guys, please, have a look at this. This pull request doesn't have tests. If the way I do the task is ok, I'll add some tests. |
|
My one concern would be what happens when multiple modules overwrite The other thing is, since the constants are not being exported, any custom logger would have to make a copy of those constants in their own project. |
|
I guess the first problem could be solved by making process._logger property non-writable. Good point about exporting the constants, I'll do it. I've actually thought about the whole thing from an embedder's point of view (and C++ part has enum for them). So, in this case, the fact that it is possible to redefine the whole set of console logging functions with just replacing console._logger, is an unexpected benefit. |
|
Why not monkey-patch |
|
I need it on a low level. I've done it mostly because I need to replace all |
|
@mscdex process._logger is readonly now, and I've set logger function types as readonly properties of process._logger, so there's no constant duplication now. |
|
@hoho Now I'm more confused. How is someone supposed to be able to override it at all now? |
|
@mscdex it's actually supposed to be used with It's just when I use io.js as a library, I want to customize all the logging (including raw fprintf calls, like, for example |
|
Hi @hoho! I was wondering what you'd think about taking a higher level view of the logger. I'm not a big fan of the enums ( // node.h
typedef int (*node_logger)(FILE* stream, const char* fmt, ...);
NODE_EXTERN void SetLogger(node_logger logger);
NODE_EXTERN void Log(FILE* stream, const char* fmt, ...);
// node.cc
// somewhere in main?
node::SetLogger(fprintf);
node::Log(stderr, "foo %d\n", 42);I'm unsure how to interact with |
|
@brendanashworth, thanks for your reply. From my point of view, just The fact that people monkey-patch something might be a signal that they are missing some logger extensibility options. I wasn't aiming to fix that though. This thing is for embedding. I link with io.js statically and it is just a part of my application. That's why I want to have full control over the output (from both internal |
|
@hoho forgive the high level / low level wording in that respect, low level would probably better describe what I intended. I agree monkey patching means that too.
Don't get me wrong, I like what you're doing here and would like to see this merged for embedders - it seems very useful. I just think it overreaches a little bit where it doesn't need to. As a foot note, this PR will eventually need to be rebased and re-submitted as a PR to the |
|
Well, I guess I can monkey-patch console.log by myself separately in my project. |
|
@hoho ... is this still something you'd like to pursue? If so, it would need to be updated and rebased on master.. and I think there are still quite a few "Do we really want to do this" kind of questions. |
|
Yeah, I'm still into it. Just had several pretty busy months. I'll try to update the PR on holidays. About «do we really want to do this» — having |
|
ping @hoho for the holidays :) |
|
Happy new year, everybody :). |
|
@hoho could you submit a new pull request so that it correctly targets the master branch? |
|
@brendanashworth sure, I'll close this one as soon as the new one is ready. |
|
I've created pre pull request: #4523. |
It is useful to have the ability to redefine logger function (especially for an embedder).
To achieve that, process._logger method and C++ logging function are added.
This change is designed to avoid affecting the current behaviour (unless you've set the custom logger up).