better placement of the comment tutorial
[fnpeditor.git] / src / fnpjs / logging / handlers.js
index 966af4e..a85645a 100644 (file)
@@ -4,23 +4,45 @@ define(function() {
 
 
 return {
-    raven: function(msg, level, data) {
+    console: function(record) {
+        /* global console */
+        var level = record.level,
+            method, msg;
+        if(console) {
+            if(level === 'warning') {
+                level = 'warn';
+            }
+            method = (typeof console[level] === 'function') ? level : 'log';
+            if(record.data && record.data.exception && record.data.exception.stack) {
+                msg = record.data.exception.stack;
+            } else {
+                msg = record.message;
+            }
+            console[method](msg);
+        }
+    },
+    raven: function(record) {
         /* global window */
         if(!window.Raven) {
             return;
         }
 
-        var ravenData = {};
+        var ravenData = {
+            level: record.level,
+            logger: record.loggerName,
+            tags: {}
+        };
 
-        if(data.exception) {
-            window.Raven.captureException(data.exception);
-        } else {
-            Object.keys(data || {}).forEach(function(key) {
-                ravenData[key] = data[key];
+        Object.keys(record.data || {})
+            .filter(function(key) {return key !== 'exception';})
+            .forEach(function(key) {
+                ravenData.tags[key] = record.data[key];
             });
-            ravenData.tags = ravenData.tags || {};
-            ravenData.tags.level = level;
-            window.Raven.captureMessage(msg, ravenData);
+
+        if(record.data && record.data.exception) {
+            window.Raven.captureException(record.data.exception, ravenData);
+        } else {
+            window.Raven.captureMessage(record.message, ravenData);
         }
     }
 };