-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from hirokinoue/logging
処理の進行がわかるログを出力する
- Loading branch information
Showing
3 changed files
with
59 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Hirokinoue\DependencyVisualizer; | ||
|
||
use Monolog\Formatter\LineFormatter; | ||
use Monolog\Handler\NullHandler; | ||
use Monolog\Handler\StreamHandler; | ||
use Monolog\Logger as MonologLogger; | ||
|
||
final class Logger | ||
{ | ||
private static ?MonologLogger $logger = null; | ||
|
||
public static function initialize(bool $enable): void | ||
{ | ||
self::$logger = new MonologLogger('dependency visualizer'); | ||
if ($enable) { | ||
$handler = new StreamHandler(getcwd() . '/app.log'); | ||
$handler->setFormatter(new LineFormatter(null, null, true)); | ||
self::$logger->pushHandler($handler); | ||
} else { | ||
self::$logger->pushHandler(new NullHandler()); | ||
} | ||
} | ||
|
||
/** | ||
* @param mixed[] $context | ||
*/ | ||
public static function info(string $message, array $context = []): void | ||
{ | ||
if (self::$logger === null) { | ||
return; | ||
} | ||
self::$logger->info($message, $context); | ||
} | ||
|
||
/** | ||
* @param mixed[] $context | ||
*/ | ||
public static function error(string $message, array $context = []): void | ||
{ | ||
if (self::$logger === null) { | ||
return; | ||
} | ||
self::$logger->error($message, $context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters