Skip to content

Commit

Permalink
style: format file
Browse files Browse the repository at this point in the history
  • Loading branch information
mastudillot committed Jun 2, 2024
1 parent 94bc7b3 commit e5734a8
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions plugin/shared/Helpers/PluginLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use Monolog\Formatter\LineFormatter;
use Transbank\Plugin\Model\LogConfig;

final class PluginLogger implements ILogger {
final class PluginLogger implements ILogger
{

const CACHE_LOG_NAME = 'transbank_log_file_name';

Expand All @@ -21,7 +22,8 @@ final class PluginLogger implements ILogger {
* output format : "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"
* @param Throwable $e
*/
public function __construct(LogConfig $config) {
public function __construct(LogConfig $config)
{
$this->config = $config;

$logFilePath = $this->getLogFilePath();
Expand All @@ -34,8 +36,11 @@ private function initializeLogger(string $logFilePath)
$output = "%datetime% > %level_name% > %message% %context% %extra%\n";
$formatter = new LineFormatter($output, $dateFormat);

$stream = new RotatingFileHandler($logFilePath,
100, Logger::DEBUG);
$stream = new RotatingFileHandler(
$logFilePath,
100,
Logger::DEBUG
);
$stream->setFormatter($formatter);

$this->logger = new Logger('transbank');
Expand All @@ -56,11 +61,13 @@ private function getLogFilePath(): string
return $logDir . $logFileName;
}

public function getLogger(){
public function getLogger()
{
return $this->logger;
}

public function getConfig(){
public function getConfig()
{
return $this->config;
}

Expand All @@ -81,7 +88,7 @@ public function logError($msg)

public function getInfo()
{
$files = glob($this->config->getLogDir().'/*.log');
$files = glob($this->config->getLogDir() . '/*.log');
if (!$files) {
return [
'dir' => $this->config->getLogDir(),
Expand All @@ -94,7 +101,7 @@ public function getInfo()
arsort($files);

$logs = [];
foreach($files as $key=>$value) {
foreach ($files as $key => $value) {
$logs[] = [
"filename" => basename($key),
"modified" => $value
Expand All @@ -114,7 +121,7 @@ public function getLogDetail($filename, $replaceNewline = false)
if ($filename == '') {
return [];
}
$fle = $this->config->getLogDir().'/'.$filename;
$fle = $this->config->getLogDir() . '/' . $filename;
$content = file_get_contents($fle);
if ($replaceNewline && $content !== false) {
$content = str_replace("\n", '#@#', $content);
Expand Down

0 comments on commit e5734a8

Please sign in to comment.