Skip to content

Commit 9ac14d2

Browse files
committed
Initial commit for Rollbar integration
1 parent 2692a52 commit 9ac14d2

File tree

5 files changed

+95
-6
lines changed

5 files changed

+95
-6
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"ext-mcrypt": "*",
5050
"ext-memcached": "*",
5151
"ext-pdo": "*",
52-
"php-64bit": ">=5.5.0"
52+
"php-64bit": ">=5.5.0",
53+
"rollbar/rollbar": "^0.18.2"
5354
}
5455
}

composer.lock

Lines changed: 52 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

etc/config.sample.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,9 @@
4747
"secret": "google-provided-value",
4848
"sitekey": "google-provided-value",
4949
"url": "https://www.google.com/recaptcha/api/siteverify"
50+
},
51+
"rollbar": {
52+
"access_token": null,
53+
"environment": "local"
5054
}
5155
}

src/libraries/Logger.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,52 @@
22

33
namespace BNETDocs\Libraries;
44

5-
use \CarlBennett\MVC\Libraries\Logger as LoggerMVCLib;
5+
use \BNETDocs\Libraries\Exceptions\QueryException;
66
use \CarlBennett\MVC\Libraries\Common;
77
use \CarlBennett\MVC\Libraries\DatabaseDriver;
8-
use \BNETDocs\Libraries\Exceptions\QueryException;
8+
use \CarlBennett\MVC\Libraries\Logger as LoggerMVCLib;
99
use \InvalidArgumentException;
1010
use \PDO;
1111
use \PDOException;
12+
use \Rollbar;
1213
use \RuntimeException;
1314

1415
class Logger extends LoggerMVCLib {
1516

16-
protected static $event_types = null;
17+
protected static $event_types = null;
18+
protected static $rollbar_available = false;
19+
20+
public static function initialize() {
21+
parent::initialize();
22+
if (Common::$config->rollbar->access_token) {
23+
self::$rollbar_available = true;
24+
25+
$rollbar_handle_exceptions = false;
26+
$rollbar_handle_errors = true;
27+
$rollbar_handle_fatal = true;
28+
29+
Rollbar::init(
30+
[
31+
'access_token' => Common::$config->rollbar->access_token,
32+
'environment' => Common::$config->rollbar->environment,
33+
],
34+
$rollbar_handle_exceptions,
35+
$rollbar_handle_errors,
36+
$rollbar_handle_fatal
37+
);
38+
}
39+
}
40+
41+
public static function logException(Exception $exception) {
42+
parent::logException($exception);
43+
if (self::$rollbar_available) {
44+
Rollbar::report_exception($exception);
45+
}
46+
}
1747

1848
public static function &getAllEvents() {
1949
$event_log = [];
50+
// TODO
2051
return $event_log;
2152
}
2253

src/main.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ function main() {
4141

4242
date_default_timezone_set('UTC');
4343

44+
// This must come after GlobalErrorHandler::createOverrides() because this
45+
// will call Rollbar::init() which will create its own error handlers for
46+
// Application Performance Monitoring (APM) purposes.
4447
Logger::initialize();
4548

4649
Common::$config = json_decode(file_get_contents(

0 commit comments

Comments
 (0)