Permalink
Browse files

More accurate stacktraces when calling a log method.

  • Loading branch information...
fabianishere committed Oct 7, 2012
1 parent 32dacb3 commit f790fc305b243e05ea952602d405df3d18a77975
Showing with 41 additions and 9 deletions.
  1. +26 −0 .npmignore
  2. +9 −4 src/main/kaffee/event/logevent.coffee
  3. +6 −5 src/main/kaffee/event/manager.coffee
View
@@ -0,0 +1,26 @@
+src
+README.markdown
+
+## Editors
+
+### Eclipse
+.classpath
+.project
+.settings
+
+### Netbeans
+nbproject
+
+### VIM
+.*.sw[a-p]
+
+### Intellij
+*.iml
+*.ipr
+*.iws
+.idea/
+
+# Mac
+.DS_Store
+
+
@@ -27,7 +27,7 @@ class LogEvent
###
The stacktrace of this {@link LogEvent}.
###
- stack: []
+ stack: null
###
The {@link EventManager} of this {@link LogEvent}.
@@ -42,14 +42,19 @@ class LogEvent
@param level The level of this {@link LogEvent}.
@param message The message of this {@link LogEvent}.
@param stack The stacktrace.
+ @param callee The arguments.callee variable to provide more accurate stacktraces.
###
- constructor: (manager, level, message, stack = null) ->
+ constructor: (manager, level, message, stack = null, callee = null) ->
this.manager = manager
this.level = level
this.message = message
this.time = Date.now()
- this.stack = message.stack if message.stack
- this.stack = stack if stack
+ this.stack = message.stack || stack
+ if not this.stack
+ err = new Error this.message
+ err.name = ""
+ Error.captureStackTrace(err, callee || arguments.callee);
+ this.stack = err.stack
###
Returns the {@link EventManager} of this {@link LogEvent}.
@@ -92,6 +92,7 @@ class EventManager
DEBUG : { name : 'debug', value : 1},
INFO : { name : 'info', value : 0 }
}
+
###
Logs a {@link LogEvent}.
@@ -108,8 +109,8 @@ class EventManager
@since 0.3.0
@param message The message to log.
###
- this.error = (message) ->
- event = new LogEvent(manager, this.Level.ERROR, message)
+ this.error = (message) ->
+ event = new LogEvent(manager, this.Level.ERROR, message, null, arguments.callee)
this.log event
manager.fire "#{ manager.getName() }:error", message
@@ -120,7 +121,7 @@ class EventManager
@param message The message to log.
###
this.warn = (message) ->
- event = new LogEvent(manager, this.Level.WARN, message)
+ event = new LogEvent(manager, this.Level.WARN, message, null, arguments.callee)
this.log event
manager.fire "#{ manager.getName() }:warn", message
@@ -131,7 +132,7 @@ class EventManager
@param message The message to log.
###
this.debug = (message) ->
- this.log new LogEvent(manager, this.Level.DEBUG, message)
+ this.log new LogEvent(manager, this.Level.DEBUG, message, null, arguments.callee)
manager.fire "#{ manager.getName() }:debug", message
###
@@ -141,7 +142,7 @@ class EventManager
@param message The message to log.
###
this.info = (message) ->
- this.log new LogEvent(manager, this.Level.INFO, message)
+ this.log new LogEvent(manager, this.Level.INFO, message, null, arguments.callee)
manager.fire "#{ manager.getName() }:info", message
this
) this

0 comments on commit f790fc3

Please sign in to comment.