-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: upgrade monolog/monolog to v3 #332
base: master
Are you sure you want to change the base?
Changes from 3 commits
0f42ac0
cd1c19e
85fd840
d31f59e
5aef419
def765d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use flake |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ log/html.log | |
composer.lock | ||
/.php-cs-fixer.cache | ||
.phpunit.result.cache | ||
.direnv |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
description = "Dev environment"; | ||
|
||
outputs = { self, nixpkgs }: | ||
let pkgs = nixpkgs.legacyPackages.x86_64-linux; | ||
in { | ||
defaultPackage.x86_64-linux = | ||
pkgs.mkShell { | ||
buildInputs = with pkgs; [ | ||
(php82.withExtensions | ||
({ all, ... }: with all; [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if @j0k3r wants to include Nix packaging. I could continue to maintain it for the time being as I use something like this locally. It might be sufficient to use And make the PHP version parametric: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you can maintain it, I'm ok. |
||
bz2 | ||
curl | ||
dom | ||
filter | ||
fileinfo | ||
gd | ||
iconv | ||
imagick | ||
intl | ||
mbstring | ||
openssl | ||
pdo | ||
pdo_mysql | ||
pdo_sqlite | ||
session | ||
sodium | ||
sqlite3 | ||
tidy | ||
tokenizer | ||
xdebug | ||
xmlwriter | ||
# yaml | ||
zip | ||
zlib | ||
]) | ||
) | ||
php82Packages.composer | ||
libjpeg | ||
libpng | ||
libyaml | ||
jtojnar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]; }; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
namespace Graby\Monolog\Formatter; | ||
|
||
use Monolog\Formatter\HtmlFormatter; | ||
use Monolog\Level; | ||
use Monolog\LogRecord; | ||
|
||
/** | ||
* Formats incoming records into an HTML table. | ||
|
@@ -18,32 +20,32 @@ class GrabyFormatter extends HtmlFormatter | |
/** | ||
* Formats a log record. | ||
* | ||
* @param array $record A record to format | ||
* @param LogRecord $record A record to format | ||
* | ||
* @return string The formatted record | ||
*/ | ||
public function format(array $record): string | ||
public function format(LogRecord $record): string | ||
{ | ||
$output = '<table cellspacing="1" width="100%" class="monolog-output">'; | ||
|
||
$output .= $this->addRowWithLevel($record['level'], 'Time', $record['datetime']->format($this->dateFormat)); | ||
$output .= $this->addRowWithLevel($record['level'], 'Message', (string) $record['message']); | ||
$output .= $this->addRowWithLevel($record->level, 'Time', $record->datetime->format($this->dateFormat)); | ||
$output .= $this->addRowWithLevel($record->level, 'Message', $record->message); | ||
|
||
if ($record['context']) { | ||
if ($record->context) { | ||
$embeddedTable = '<table cellspacing="1" width="100%">'; | ||
foreach ($record['context'] as $key => $value) { | ||
$embeddedTable .= $this->addRowWithLevel($record['level'], $key, $this->convertToString($value)); | ||
foreach ($record->context as $key => $value) { | ||
$embeddedTable .= $this->addRowWithLevel($record->level, $key, $this->convertToString($value)); | ||
} | ||
$embeddedTable .= '</table>'; | ||
$output .= $this->addRowWithLevel($record['level'], 'Context', $embeddedTable, false); | ||
$output .= $this->addRowWithLevel($record->level, 'Context', $embeddedTable, false); | ||
} | ||
if ($record['extra']) { | ||
if ($record->extra) { | ||
$embeddedTable = '<table cellspacing="1" width="100%">'; | ||
foreach ($record['extra'] as $key => $value) { | ||
$embeddedTable .= $this->addRowWithLevel($record['level'], $key, $this->convertToString($value)); | ||
foreach ($record->extra as $key => $value) { | ||
$embeddedTable .= $this->addRowWithLevel($record->level, $key, $this->convertToString($value)); | ||
} | ||
$embeddedTable .= '</table>'; | ||
$output .= $this->addRowWithLevel($record['level'], 'Extra', $embeddedTable, false); | ||
$output .= $this->addRowWithLevel($record->level, 'Extra', $embeddedTable, false); | ||
} | ||
|
||
return $output . '</table>'; | ||
|
@@ -61,18 +63,18 @@ protected function convertToString($data): string | |
/** | ||
* Creates an HTML table row with background cellon title cell. | ||
* | ||
* @param int $level Error level | ||
* @param Level $level Error level | ||
* @param string $th Row header content | ||
* @param string $td Row standard cell content | ||
* @param bool $escapeTd false if td content must not be html escaped | ||
*/ | ||
private function addRowWithLevel(int $level, string $th, string $td = ' ', bool $escapeTd = true): string | ||
private function addRowWithLevel(Level $level, string $th, string $td = ' ', bool $escapeTd = true): string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not work with Monolog 2, will it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least there is a specific build to run on lower deps, so it's checked https://github.com/j0k3r/graby/actions/runs/5375860418/jobs/9752256955?pr=332#step:4:115 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I'm getting this error, I think I have monolog 2 installed.
|
||
{ | ||
$th = htmlspecialchars($th, \ENT_NOQUOTES, 'UTF-8'); | ||
if ($escapeTd) { | ||
$td = '<pre>' . htmlspecialchars($td, \ENT_NOQUOTES, 'UTF-8') . '</pre>'; | ||
} | ||
|
||
return "<tr style=\"padding: 4px;spacing: 0;text-align: left;\">\n<th style=\"background:" . $this->logLevels[$level] . "\" width=\"100px\">$th:</th>\n<td style=\"padding: 4px;spacing: 0;text-align: left;background: #eeeeee\">" . $td . "</td>\n</tr>"; | ||
return "<tr style=\"padding: 4px;spacing: 0;text-align: left;\">\n<th style=\"background:" . $this->getLevelColor($level) . "\" width=\"100px\">$th:</th>\n<td style=\"padding: 4px;spacing: 0;text-align: left;background: #eeeeee\">" . $td . "</td>\n</tr>"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason you are bumping readability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of
psr/log
, it's detailed in the PR descriptionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because readability 1x only supports psr/log 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I try 2.0.2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can put
^2.0
it'll be enough for thepsr/log
v3