Skip to content

Commit

Permalink
Logger: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jul 3, 2023
1 parent ac91979 commit 601f64e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 306 deletions.
98 changes: 0 additions & 98 deletions src/Logger/AbstractLogger.php

This file was deleted.

19 changes: 7 additions & 12 deletions src/Logger/FileLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@

namespace Nettrine\DBAL\Logger;

use stdClass;
use Psr\Log\AbstractLogger;
use Stringable;

final class FileLogger extends AbstractLogger
{

/** @var string */
private $file;

public function __construct(string $file)
public function __construct(
private string $file
)
{
$this->file = $file;
}

public function stopQuery(): stdClass
public function log($level, Stringable|string $message, array $context = []): void
{
$query = parent::stopQuery();

file_put_contents($this->file, sprintf('[%s ms] %s', $query->ms, $query->sql) . "\n", FILE_APPEND);

return $query;
file_put_contents($this->file, sprintf('[%s] %s {%s}', date('d.m.Y H:i:s'), $message, json_encode($context)) . "\n", FILE_APPEND);
}

}
128 changes: 0 additions & 128 deletions src/Logger/ProfilerLogger.php

This file was deleted.

46 changes: 0 additions & 46 deletions src/Logger/PsrLogger.php

This file was deleted.

22 changes: 0 additions & 22 deletions src/Logger/TracyDumpLogger.php

This file was deleted.

22 changes: 22 additions & 0 deletions src/Logger/TracyLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace Nettrine\DBAL\Logger;

use Psr\Log\AbstractLogger;
use Stringable;
use Tracy\Debugger;
use Tracy\Dumper;

class TracyLogger extends AbstractLogger
{

public function log($level, Stringable|string $message, array $context = []): void
{
Debugger::barDump(
['message' => $message, 'context' => $context],
'DBAL',
[Dumper::TRUNCATE => 10000]
);
}

}

0 comments on commit 601f64e

Please sign in to comment.