Skip to content

Commit

Permalink
Improved loggers & added sentry logger
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaplet committed Jul 8, 2024
1 parent aee3ed4 commit 0afbbc7
Show file tree
Hide file tree
Showing 7 changed files with 582 additions and 148 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"lcobucci/jwt": "^4.2",
"aws/aws-sdk-php": "^3.289.0",
"phpstan/phpstan": "^1.8",
"siketyan/yarn-lock": "^1.0"
"siketyan/yarn-lock": "^1.0",
"sentry/sentry": "^4.8"
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse -l 8 src/ router/ --memory-limit 1G",
Expand Down
217 changes: 216 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 32 additions & 17 deletions src/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,29 @@

namespace Megio;

use Megio\Debugger\JsonLogstashLogger;
use Nette\DI\Compiler;
use Nette\Neon\Neon;
use Megio\Debugger\Logger;
use Megio\Extension\Extension;
use Megio\Helper\Path;
use Nette\Bridges\DITracy\ContainerPanel;
use Nette\DI\Container;
use Nette\DI\ContainerLoader;
use Symfony\Component\Dotenv\Dotenv;
use Tracy\Debugger;
use Tracy\ILogger;

class Bootstrap
{
protected bool $invokedLogger = false;

public function projectRootPath(string $rootPath): Bootstrap
{
/** @var string $realPath */
$realPath = realpath($rootPath);
Path::setProjectPath($realPath);
return $this;
}

/**
* @param string $configPath
* @param float $startedAt
* @return Container
*/
public function configure(string $configPath, float $startedAt): Container
{
// Load .env

// Load environment variables
$_ENV = array_merge(getenv(), $_ENV);
$envPath = Path::wwwDir() . '/../.env';

Expand All @@ -40,18 +34,39 @@ public function configure(string $configPath, float $startedAt): Container
$dotenv->loadEnv($envPath);
}

date_default_timezone_set($_ENV['APP_TIME_ZONE']);

return $this;
}

public function logger(ILogger $logger): Bootstrap
{
// Setup debugger
Debugger::setLogger(new Logger(Path::logDir()));
Debugger::enable($_ENV['APP_ENV_MODE'] === 'develop' ? Debugger::Development : Debugger::Production, Path::logDir());
Debugger::enable($_ENV['APP_ENVIRONMENT'] === 'develop' ? Debugger::Development : Debugger::Production, Path::logDir());
Debugger::$strictMode = E_ALL;
Debugger::setLogger($logger);

if (array_key_exists('TRACY_EDITOR', $_ENV) && array_key_exists('TRACY_EDITOR_MAPPING', $_ENV)) {
Debugger::$editor = $_ENV['TRACY_EDITOR'];
Debugger::$editorMapping = ['/var/www/html' => $_ENV['TRACY_EDITOR_MAPPING']];
}

$this->invokedLogger = true;

return $this;
}

/**
* @param string $configPath
* @param float $startedAt
* @return Container
*/
public function configure(string $configPath, float $startedAt): Container
{
if ($this->invokedLogger === false) {
$this->logger(new JsonLogstashLogger());
}

date_default_timezone_set($_ENV['APP_TIME_ZONE']);

// Create DI container
$container = $this->createContainer($configPath);
$container->parameters['startedAt'] = $startedAt;
Expand All @@ -74,7 +89,7 @@ public function configure(string $configPath, float $startedAt): Container
*/
protected function createContainer(string $configPath): Container
{
$loader = new ContainerLoader(Path::tempDir() . '/di', $_ENV['APP_ENV_MODE'] === 'develop');
$loader = new ContainerLoader(Path::tempDir() . '/di', $_ENV['APP_ENVIRONMENT'] === 'develop');

/** @var Container $class */
$class = $loader->load(function (Compiler $compiler) use ($configPath) {
Expand Down
Loading

0 comments on commit 0afbbc7

Please sign in to comment.