editor: automatically convert pasted urls to attachments to a proper links with ...
[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, msg;
11         if(console) {
12             if(level === 'warning') {
13                 level = 'warn';
14             }
15             method = (typeof console[level] === 'function') ? level : 'log';
16             if(record.data && record.data.exception && record.data.exception.stack) {
17                 msg = record.data.exception.stack;
18             } else {
19                 msg = record.message;
20             }
21             console[method](msg);
22         }
23     },
24     raven: function(record) {
25         /* global window */
26         if(!window.Raven) {
27             return;
28         }
29
30         var ravenData = {
31             level: record.level,
32             logger: record.loggerName,
33             tags: {}
34         };
35
36         Object.keys(record.data || {})
37             .filter(function(key) {return key !== 'exception';})
38             .forEach(function(key) {
39                 ravenData.tags[key] = record.data[key];
40             });
41
42         if(record.data && record.data.exception) {
43             window.Raven.captureException(record.data.exception, ravenData);
44         } else {
45             window.Raven.captureMessage(record.message, ravenData);
46         }
47     }
48 };
49
50 });