librenms-librenms/app/Providers/AppServiceProvider.php
Tony Murray eeb3d58f5b Improved Logging and Debugging (#8870)
Use Log facility when Laravel is booted.
Update init.php so we can easily boot Laravel for CLI scripts. (and just Eloquent, but that may go away)
Move all debug setup into set_debug() function and use that across all scripts.
Log Laravel database queries.
Send debug output to librenms log file when enabling debug in the webui.
Allow for colorized Log CLI output. (currently will leave % tags in log file output)

** Needs testing and perhaps tweaking still.

DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
2018-07-13 23:08:00 +01:00

84 lines
2.6 KiB
PHP

<?php
namespace App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use LibreNMS\Config;
use LibreNMS\Exceptions\DatabaseConnectException;
include_once __DIR__ . '/../../includes/dbFacile.php';
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
* @throws DatabaseConnectException caught by App\Exceptions\Handler and displayed to the user
*/
public function boot()
{
// connect legacy db, only if configured
//FIXME this is for auth right now, remove later
$db_config = config('database.connections')[config('database.default')];
if (!empty($db_config['database'])) {
dbConnect(
$db_config['host'],
$db_config['username'],
$db_config['password'],
$db_config['database'],
$db_config['port'],
$db_config['unix_socket']
);
}
// load config
Config::load();
// direct log output to librenms.log
Log::getMonolog()->popHandler(); // remove existing errorlog logger
Log::useFiles(Config::get('log_file', base_path('logs/librenms.log')), 'error');
// Blade directives (Yucky because of < L5.5)
Blade::directive('config', function ($key) {
return "<?php if (\LibreNMS\Config::get(($key))): ?>";
});
Blade::directive('notconfig', function ($key) {
return "<?php if (!\LibreNMS\Config::get(($key))): ?>";
});
Blade::directive('endconfig', function () {
return "<?php endif; ?>";
});
Blade::directive('admin', function () {
return "<?php if (auth()->check() && auth()->user()->isAdmin()): ?>";
});
Blade::directive('endadmin', function () {
return "<?php endif; ?>";
});
// Development service providers
if ($this->app->environment() !== 'production') {
if (class_exists(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class)) {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
if (config('app.debug') && class_exists(\Barryvdh\Debugbar\ServiceProvider::class)) {
$this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
}
}
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}