@@ -20,7 +20,7 @@ class RollbarServiceProvider extends ServiceProvider
20
20
public function boot ()
21
21
{
22
22
// Don't boot rollbar if it is not configured.
23
- if (! getenv ( ' ROLLBAR_TOKEN ' ) and ! $ this ->app [ ' config ' ]-> get ( ' services.rollbar ' ) ) {
23
+ if ($ this ->stop () === true ) {
24
24
return ;
25
25
}
26
26
@@ -51,35 +51,49 @@ public function boot()
51
51
public function register ()
52
52
{
53
53
// Don't register rollbar if it is not configured.
54
- if (! getenv ( ' ROLLBAR_TOKEN ' ) and ! $ this ->app [ ' config ' ]-> get ( ' services.rollbar ' ) ) {
54
+ if ($ this ->stop () === true ) {
55
55
return ;
56
56
}
57
57
58
58
$ app = $ this ->app ;
59
59
60
60
$ this ->app ->singleton ('Rollbar\RollbarLogger ' , function ($ app ) {
61
-
61
+
62
62
$ defaults = [
63
63
'environment ' => $ app ->environment (),
64
64
'root ' => base_path (),
65
65
];
66
66
$ config = array_merge ($ defaults , $ app ['config ' ]->get ('services.rollbar ' , []));
67
67
$ config ['access_token ' ] = getenv ('ROLLBAR_TOKEN ' ) ?: $ app ['config ' ]->get ('services.rollbar.access_token ' );
68
-
68
+
69
69
if (empty ($ config ['access_token ' ])) {
70
70
throw new InvalidArgumentException ('Rollbar access token not configured ' );
71
71
}
72
-
72
+
73
73
\Rollbar \Rollbar::init ($ config );
74
-
74
+
75
75
return Rollbar::logger ();
76
76
});
77
77
78
78
$ this ->app ->singleton ('Rollbar\Laravel\RollbarLogHandler ' , function ($ app ) {
79
-
79
+
80
80
$ level = getenv ('ROLLBAR_LEVEL ' ) ?: $ app ['config ' ]->get ('services.rollbar.level ' , 'debug ' );
81
81
82
82
return new RollbarLogHandler ($ app ['Rollbar\RollbarLogger ' ], $ app , $ level );
83
83
});
84
84
}
85
+
86
+ /**
87
+ * Check if we should prevent the service from registering
88
+ *
89
+ * @return boolean
90
+ */
91
+ public function stop ()
92
+ {
93
+ $ level = getenv ('ROLLBAR_LEVEL ' ) ?: $ this ->app ->config ->get ('services.rollbar.level ' , null );
94
+ $ token = getenv ('ROLLBAR_TOKEN ' ) ?: $ this ->app ->config ->get ('services.rollbar.token ' , null );
95
+ $ hasToken = empty ($ token ) === false ;
96
+
97
+ return $ hasToken === false || $ level === 'none ' ;
98
+ }
85
99
}
0 commit comments