Skip to content

Commit

Permalink
Make Logger component compatible with Monolog 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin-Magmodules committed Mar 7, 2022
1 parent 4017739 commit 17afd74
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions Logger/PaazlLogger.php
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);
}
}
}

0 comments on commit 17afd74

Please sign in to comment.