-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Code's file name, function, line number from where logging was done #200
Comments
this request has already been made, by me and other guys, and i understand, that is a little overkilling because each log request is necessary to call Error stack |
Then probably we can enable/disable this with a flag, default being disabled. |
yes, i guess is possible, but ho knows, if will be available any time soon |
@SoulRaven - I guess getting data from the req would be considered equally evil? e.g. like connect.logger |
i think is evil in some way, because on each log event, a Error object/stack must be created. |
Ummm - the req object already exists though. :-S |
Are there any updates? |
I'm also waiting for updates.. |
Waiting for this feature too... |
👍 |
1 similar comment
👍 |
Here's what I'm using (with Winston) in the meantime: gLineInfo: (prefix='') ->
stack = new Error().stack
# console.log stack.split('\n')[2]
[file, line] = stack.split('\n')[2].split ':'
[func, file] = file.split ' ('
[func, file] = ['??', func] unless file # sometimes the function isn't specified
[func, file] = [func.split(' ').pop(), path.basename(file)]
[junk, func] = func.split('.')
func = junk unless func
func = if func is '??' or func is '<anonymous>' then ' (' else " (<#{func}> "
prefix + func + file + ':' + line + ')' Example usage from DNSChain: @log.error gLineInfo("exception in handler"), {q:q, result:result} |
Ah, and here's some example usage plus corresponding output from DNSChain's dns.coffee L200: @log.warn gLineInfo('oldDNS timeout'), {err:err} Produces:
|
+1 |
User should be able to customize the format. Ideally something like http://www.slf4j.org/nlog4j/api/org/apache/log4j/PatternLayout.html, or at least activate filename, linenumber and functionname independently (or based on log severity). |
It should behave like |
+1 |
7 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
2 similar comments
+1 |
+1 |
For anyone else wanting this functionality, I've created a public gist which shows how you can wrap winston to do it yourself. |
+1 |
Hi, is there any plan to add this to winson? |
the support of line number & file name really make much sense in my current project. |
+1 |
1 similar comment
+1 |
There is no plan to add this to A PR would be welcome for this IFF:
Until such PR is made I am locking this issue to avoid further +1s. If you wanted to leave a +1 apologies, but your +1 has already been heard. It is clear many folks want this feature, but I think most of those folks don't understand the perf side effects of the implementation details. |
It will be really helpful to have some standard logging metadata like file name, line number and perhaps function from which the .log method was called. Something similar to what we have in https://github.com/baryon/tracer
This is how they are doing it in tracer: https://github.com/baryon/tracer/blob/master/lib/console.js
Basically using the Error object to get the stack trace and these details out of it. Not sure if this is the best way.
ps: more than willing to contribute if you guys think this is useful
The text was updated successfully, but these errors were encountered: