editor: refactoring the way document properties are kept
[fnpeditor.git] / src / fnpjs / logging / handlers.js
1 define(function() {
2     
3 'use strict';
4
5
6 return {
7     console: function(record) {
8         /* global console */
9         var level = record.level,
10             method;
11         if(console) {
12             if(level === 'warning') {
13                 level = 'warn';
14             }
15             method = (typeof console[level] === 'function') ? level : 'log';
16             console[method](record.message);
17         }
18     },
19     raven: function(record) {
20         /* global window */
21         if(!window.Raven) {
22             return;
23         }
24
25         var ravenData = {
26             level: record.level,
27             logger: record.loggerName,
28             tags: {}
29         };
30
31         Object.keys(record.data || {})
32             .filter(function(key) {return key !== 'exception';})
33             .forEach(function(key) {
34                 ravenData.tags[key] = record.data[key];
35             });
36
37         if(record.data && record.data.exception) {
38             window.Raven.captureException(record.data.exception, ravenData);
39         } else {
40             window.Raven.captureMessage(record.message, ravenData);
41         }
42     }
43 };
44
45 });