-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
52 lines (42 loc) · 1.47 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
$config = parse_ini_file(__DIR__ . '/config.ini.dist');
if (is_file(__DIR__ . '/config.ini')) {
$config = array_merge($config, parse_ini_file(__DIR__ . '/config.ini'));
}
if (!is_file(__DIR__ . '/vendor/autoload.php')) {
return; // not initialized
}
$autoload = require __DIR__ . '/vendor/autoload.php';
switch ($config['transport']) {
case 'udp':
$transport = new Gelf\Transport\UdpTransport($config['host'], $config['port']);
break;
case 'http':
$transport = new Gelf\Transport\HttpTransport($config['host'], $config['port'], $config['path']);
break;
default:
return; // bad config
}
$publisher = new Gelf\Publisher($transport);
$logger = new Gelf\Logger($publisher);
$getContext = function(array $context = array()) {
$context['application_name'] = 'php';
if (getenv('PHP_POOL')) {
$context['pool'] = getenv('PHP_POOL');
}
if (getenv('SERVER_NAME')) {
$context['http_host'] = getenv('SERVER_NAME');
} elseif (!empty($_SERVER['SERVER_NAME'])) {
$context['http_host'] = $_SERVER['SERVER_NAME'];
}
if (!empty($_SERVER['REQUEST_URI'])) {
$context['uri'] = $_SERVER['REQUEST_URI'];
}
return $context;
};
foreach (array('error_handler', 'exception_handler', 'fatal_handler') as $handler) {
if (!empty($config[$handler])) {
require __DIR__ . "/handlers/${handler}.php";
}
}
unset($logger, $publisher, $transport, $config, $autoload, $getContext);