-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Logger component compatible with Monolog 2.0
- Loading branch information
1 parent
4017739
commit 17afd74
Showing
1 changed file
with
30 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,54 @@ | ||
<?php | ||
/** | ||
* Copyright © 2019 Paazl. All rights reserved. | ||
* Copyright © Paazl. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Paazl\CheckoutWidget\Logger; | ||
|
||
use Magento\Framework\Serialize\Serializer\Json; | ||
use Monolog\Logger; | ||
|
||
/** | ||
* Class PaazlLogger | ||
* | ||
* @package Paazl\CheckoutWidget\Logger | ||
* DebugLogger logger class | ||
*/ | ||
class PaazlLogger extends Logger | ||
{ | ||
|
||
/** | ||
* @var Json | ||
*/ | ||
private $json; | ||
|
||
/** | ||
* DebugLogger constructor. | ||
* | ||
* @param Json $json | ||
* @param string $name | ||
* @param array $handlers | ||
* @param array $processors | ||
*/ | ||
public function __construct( | ||
Json $json, | ||
string $name, | ||
array $handlers = [], | ||
array $processors = [] | ||
) { | ||
$this->json = $json; | ||
parent::__construct($name, $handlers, $processors); | ||
} | ||
|
||
/** | ||
* @param string $type | ||
* @param mixed $data | ||
*/ | ||
public function add($type, $data) | ||
{ | ||
if (is_array($data)) { | ||
$this->addInfo($type . ': ' . json_encode($data)); | ||
} elseif (is_object($data)) { | ||
$this->addInfo($type . ': ' . json_encode($data)); | ||
if (is_array($data) || is_object($data)) { | ||
$this->addRecord(static::INFO, $type . ': ' . $this->json->serialize($data)); | ||
} else { | ||
$this->addInfo($type . ': ' . $data); | ||
$this->addRecord(static::INFO, $type . ': ' . $data); | ||
} | ||
} | ||
} |