@@ -26,66 +26,153 @@ function Rollbar(options, client) {
26
26
}
27
27
}
28
28
29
+ var _instance = null ;
30
+ Rollbar . init = function ( options , client ) {
31
+ if ( _instance ) {
32
+ return _instance . global ( options ) . configure ( options ) ;
33
+ }
34
+ _instance = new Rollbar ( options , client ) ;
35
+ return _instance ;
36
+ } ;
37
+
38
+ function handleUninitialized ( maybeCallback ) {
39
+ var message = 'Rollbar is not initialized' ;
40
+ logger . error ( message ) ;
41
+ if ( maybeCallback ) {
42
+ maybeCallback ( new Error ( message ) ) ;
43
+ }
44
+ }
45
+
29
46
Rollbar . prototype . global = function ( options ) {
30
47
this . client . global ( options ) ;
31
48
return this ;
32
49
} ;
50
+ Rollbar . global = function ( options ) {
51
+ if ( _instance ) {
52
+ return _instance . global ( options ) ;
53
+ } else {
54
+ handleUninitialized ( ) ;
55
+ }
56
+ } ;
33
57
34
58
Rollbar . prototype . configure = function ( options ) {
35
59
var oldOptions = this . options ;
36
60
this . options = _ . extend ( true , { } , oldOptions , options ) ;
37
61
this . client . configure ( options ) ;
38
62
return this ;
39
63
} ;
64
+ Rollbar . configure = function ( options ) {
65
+ if ( _instance ) {
66
+ return _instance . configure ( options ) ;
67
+ } else {
68
+ handleUninitialized ( ) ;
69
+ }
70
+ } ;
40
71
41
72
Rollbar . prototype . log = function ( ) {
42
73
var item = this . _createItem ( arguments ) ;
43
74
var uuid = item . uuid ;
44
75
this . client . log ( item ) ;
45
76
return { uuid : uuid } ;
46
77
} ;
78
+ Rollbar . log = function ( ) {
79
+ if ( _instance ) {
80
+ return _instance . log . apply ( _instance , arguments ) ;
81
+ } else {
82
+ var maybeCallback = _getFirstFunction ( arguments ) ;
83
+ handleUninitialized ( maybeCallback ) ;
84
+ }
85
+ } ;
47
86
48
87
Rollbar . prototype . debug = function ( ) {
49
88
var item = this . _createItem ( arguments ) ;
50
89
var uuid = item . uuid ;
51
90
this . client . debug ( item ) ;
52
91
return { uuid : uuid } ;
53
92
} ;
93
+ Rollbar . debug = function ( ) {
94
+ if ( _instance ) {
95
+ return _instance . debug . apply ( _instance , arguments ) ;
96
+ } else {
97
+ var maybeCallback = _getFirstFunction ( arguments ) ;
98
+ handleUninitialized ( maybeCallback ) ;
99
+ }
100
+ } ;
54
101
55
102
Rollbar . prototype . info = function ( ) {
56
103
var item = this . _createItem ( arguments ) ;
57
104
var uuid = item . uuid ;
58
105
this . client . info ( item ) ;
59
106
return { uuid : uuid } ;
60
107
} ;
108
+ Rollbar . info = function ( ) {
109
+ if ( _instance ) {
110
+ return _instance . info . apply ( _instance , arguments ) ;
111
+ } else {
112
+ var maybeCallback = _getFirstFunction ( arguments ) ;
113
+ handleUninitialized ( maybeCallback ) ;
114
+ }
115
+ } ;
61
116
62
117
Rollbar . prototype . warn = function ( ) {
63
118
var item = this . _createItem ( arguments ) ;
64
119
var uuid = item . uuid ;
65
120
this . client . warn ( item ) ;
66
121
return { uuid : uuid } ;
67
122
} ;
123
+ Rollbar . warn = function ( ) {
124
+ if ( _instance ) {
125
+ return _instance . warn . apply ( _instance , arguments ) ;
126
+ } else {
127
+ var maybeCallback = _getFirstFunction ( arguments ) ;
128
+ handleUninitialized ( maybeCallback ) ;
129
+ }
130
+ } ;
68
131
69
132
Rollbar . prototype . warning = function ( ) {
70
133
var item = this . _createItem ( arguments ) ;
71
134
var uuid = item . uuid ;
72
135
this . client . warning ( item ) ;
73
136
return { uuid : uuid } ;
74
137
} ;
138
+ Rollbar . warning = function ( ) {
139
+ if ( _instance ) {
140
+ return _instance . warning . apply ( _instance , arguments ) ;
141
+ } else {
142
+ var maybeCallback = _getFirstFunction ( arguments ) ;
143
+ handleUninitialized ( maybeCallback ) ;
144
+ }
145
+ } ;
75
146
76
147
Rollbar . prototype . error = function ( ) {
77
148
var item = this . _createItem ( arguments ) ;
78
149
var uuid = item . uuid ;
79
150
this . client . error ( item ) ;
80
151
return { uuid : uuid } ;
81
152
} ;
153
+ Rollbar . error = function ( ) {
154
+ if ( _instance ) {
155
+ return _instance . error . apply ( _instance , arguments ) ;
156
+ } else {
157
+ var maybeCallback = _getFirstFunction ( arguments ) ;
158
+ handleUninitialized ( maybeCallback ) ;
159
+ }
160
+ } ;
82
161
83
162
Rollbar . prototype . critical = function ( ) {
84
163
var item = this . _createItem ( arguments ) ;
85
164
var uuid = item . uuid ;
86
165
this . client . critical ( item ) ;
87
166
return { uuid : uuid } ;
88
167
} ;
168
+ Rollbar . critical = function ( ) {
169
+ if ( _instance ) {
170
+ return _instance . critical . apply ( _instance , arguments ) ;
171
+ } else {
172
+ var maybeCallback = _getFirstFunction ( arguments ) ;
173
+ handleUninitialized ( maybeCallback ) ;
174
+ }
175
+ } ;
89
176
90
177
Rollbar . prototype . handleUncaughtException = function ( message , url , lineno , colno , error , context ) {
91
178
var item ;
@@ -193,6 +280,13 @@ Rollbar.prototype.wrap = function(f, context) {
193
280
return f ;
194
281
}
195
282
} ;
283
+ Rollbar . wrap = function ( f , context ) {
284
+ if ( _instance ) {
285
+ return _instance . wrap ( f , context ) ;
286
+ } else {
287
+ handleUninitialized ( ) ;
288
+ }
289
+ } ;
196
290
197
291
/* Internal */
198
292
@@ -277,6 +371,15 @@ Rollbar.prototype._createItem = function(args) {
277
371
return item ;
278
372
} ;
279
373
374
+ function _getFirstFunction ( args ) {
375
+ for ( var i = 0 , len = args . length ; i < len ; ++ i ) {
376
+ if ( _ . isFunction ( args [ i ] ) ) {
377
+ return args [ i ] ;
378
+ }
379
+ }
380
+ return undefined ;
381
+ }
382
+
280
383
/* global __NOTIFIER_VERSION__:false */
281
384
/* global __DEFAULT_BROWSER_SCRUB_FIELDS__:false */
282
385
/* global __DEFAULT_LOG_LEVEL__:false */
0 commit comments