Action_Logger.php
2 weeks ago
Admin.php
2 weeks ago
Canonical_Formatter.php
2 weeks ago
File_Logger.php
2 weeks ago
Logger.php
2 weeks ago
Monolog_Logger.php
2 weeks ago
Null_Logger.php
2 weeks ago
Service_Provider.php
2 weeks ago
Monolog_Logger.php
54 lines
| 1 | <?php |
| 2 | /** |
| 3 | * An extension of the base Monolog logger to add our need to replace the instance, and global, loggers. |
| 4 | * |
| 5 | * @since 4.9.16 |
| 6 | * |
| 7 | * @package Tribe\Log |
| 8 | */ |
| 9 | |
| 10 | namespace Tribe\Log; |
| 11 | |
| 12 | use Monolog\Logger; |
| 13 | |
| 14 | /** |
| 15 | * Class Monolog_Logger |
| 16 | * |
| 17 | * @since 4.9.16 |
| 18 | * |
| 19 | * @package Tribe\Log |
| 20 | */ |
| 21 | class Monolog_Logger extends Logger { |
| 22 | /** |
| 23 | * @since 4.9.16 |
| 24 | */ |
| 25 | const DEFAULT_CHANNEL = 'default'; |
| 26 | |
| 27 | /** |
| 28 | * Resets the global channel to the default one. |
| 29 | * |
| 30 | * @since 4.9.16 |
| 31 | * |
| 32 | * @return bool Whether the channel reset |
| 33 | */ |
| 34 | public function reset_global_channel() { |
| 35 | return $this->set_global_channel( static::DEFAULT_CHANNEL ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Clones this logger and replaces it in the `tribe` container. |
| 40 | * |
| 41 | * @since 4.9.16 |
| 42 | * |
| 43 | * @param string $channel The new logger name, also referred to as "channel" (hence the method name). |
| 44 | * |
| 45 | * @return bool Whether the channel change was successful or not. |
| 46 | */ |
| 47 | public function set_global_channel( $channel ) { |
| 48 | $new = $this->withName( $channel ); |
| 49 | tribe_register( Logger::class, $new ); |
| 50 | tribe_register( 'monolog', $new ); |
| 51 | |
| 52 | return $channel === tribe( 'monolog' )->getName(); |
| 53 | } |
| 54 | } |