diff --git a/src/Config/ActivityPubConfigBuilder.php b/src/Config/ActivityPubConfigBuilder.php index 92a43b0..6d3a2e6 100644 --- a/src/Config/ActivityPubConfigBuilder.php +++ b/src/Config/ActivityPubConfigBuilder.php @@ -4,9 +4,8 @@ namespace ActivityPub\Config; use ActivityPub\Objects\ContextProvider; use ActivityPub\Objects\IdProvider; +use ActivityPub\Utils\Logger; use Exception; -use Monolog\Handler\ErrorLogHandler; -use Monolog\Logger; use Psr\Log\LoggerInterface; /** @@ -296,10 +295,9 @@ class ActivityPubConfigBuilder * This config parameter can be used to customize the log level and log destination via the PSR-3 LoggerInterface * specification. * - * Default: a Monolog Logger that prints all messages of level Info or higher to the SAPI logging handler. - * See https://github.com/Seldaek/monolog. + * Default: a logger that prints all messages of level Info or higher to the SAPI logging handler. * - * @param LoggerInterface $logger A PSR3 LoggerInterface instance + * @param LoggerInterface $logger A PSR-3 LoggerInterface instance * @return ActivityPubConfigBuilder The builder instance */ public function setLogger( LoggerInterface $logger ) @@ -313,9 +311,7 @@ class ActivityPubConfigBuilder */ private function getDefaultLogger() { - $logger = new Logger( 'ActivityPub-PHP' ); - $logger->pushHandler( new ErrorLogHandler( ErrorLogHandler::SAPI ) ); - return $logger; + return new Logger( 'ActivityPub-PHP' ); } } diff --git a/src/Utils/Logger.php b/src/Utils/Logger.php new file mode 100644 index 0000000..2fae711 --- /dev/null +++ b/src/Utils/Logger.php @@ -0,0 +1,154 @@ +monoLogger = new MonoLogger( 'ActivityPub-PHP' ); + $this->monoLogger->pushHandler( new ErrorLogHandler(ErrorLogHandler::SAPI, $level ) ); + } + + /** + * System is unusable. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function emergency( $message, array $context = array() ) + { + $this->monoLogger->emergency( $message, $context ); + } + + /** + * Action must be taken immediately. + * + * Example: Entire website down, database unavailable, etc. This should + * trigger the SMS alerts and wake you up. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function alert( $message, array $context = array() ) + { + $this->monoLogger->alert( $message, $context ); + } + + /** + * Critical conditions. + * + * Example: Application component unavailable, unexpected exception. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function critical( $message, array $context = array() ) + { + $this->monoLogger->critical( $message, $context ); + } + + /** + * Runtime errors that do not require immediate action but should typically + * be logged and monitored. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function error( $message, array $context = array() ) + { + $this->monoLogger->error( $message, $context ); + } + + /** + * Exceptional occurrences that are not errors. + * + * Example: Use of deprecated APIs, poor use of an API, undesirable things + * that are not necessarily wrong. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function warning( $message, array $context = array() ) + { + $this->monoLogger->warning( $message, $context ); + } + + /** + * Normal but significant events. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function notice( $message, array $context = array() ) + { + $this->monoLogger->notice( $message, $context ); + } + + /** + * Interesting events. + * + * Example: User logs in, SQL logs. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function info( $message, array $context = array() ) + { + $this->monoLogger->info( $message, $context ); + } + + /** + * Detailed debug information. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function debug( $message, array $context = array() ) + { + $this->monoLogger->debug( $message, $context ); + } + + /** + * Logs with an arbitrary level. + * + * @param mixed $level + * @param string $message + * @param array $context + * + * @return void + */ + public function log( $level, $message, array $context = array() ) + { + $this->monoLogger->log( $level, $message, $context ); + } +} \ No newline at end of file