- Notifications
You must be signed in to change notification settings - Fork 28
Add default logger #18
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
Conversation
there was a missing term in the equation we were using
Adding an actual |
and move the logging interface into Main
… add-default-logger
OK, moved to Issue for this PR #17 |
Nb. Great work you're doing on this, even though I think you're not even using the library yourself! 💯 |
No, I won't be using it myself, it's just an experiment. I'm thinking of moving the Python binding (which I do use) to this model, so it's a try-out. |
What about Not sure about convention in PSR, but can't E.g.: namespace Vips; /** * Log a debug message. * * @param string $name The method creating the messages. * @param array $arguments The method arguments. * * @return void */ function debug(string $name, array $arguments): void { $logger = Config::getLogger(); if ($logger) { $logger->debug($name, $arguments); } } /** * Log an error message. * * @param string $message The error message. * @param \Exception $exception The exception. * * @return void */ function error(string $message, \Exception $exception): void { $logger = Config::getLogger(); if ($logger) { $logger->error($message, ['exception' => $exception]); } } |
I think everything has to be inside a class for autoload to work, hence the apparently useless |
helps phpdoc not flop about horribly on the Image class
since Image.php works now
I guess you're right, than maybe wrap them [ |
OK, I've added that as another idea on #14 |
src/Image.php Outdated
{ | ||
return self::$logger; | ||
} | ||
|
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.
We could remove these unused lines, because they are defined in Vips\Main
now.
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.
Ooop! Drat, I was sure I'd done that, thanks.
src/Logger.php Outdated
| ||
namespace Jcupitt\Vips; | ||
| ||
use \Psr\Log\LoggerInterface; |
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.
Nitpick: drop the first \
:
use Psr\Log\LoggerInterface;
namespace Jcupitt\Vips; | ||
| ||
use \Psr\Log\LoggerInterface; | ||
|
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.
We could import also the LoggerTrait
here, like: use Psr\Log\LoggerTrait;
src/Logger.php Outdated
{ | ||
// Use the LoggerTrait so that we only have to implement the generic | ||
// log method. | ||
use \Psr\Log\LoggerTrait; |
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.
If we imported the LoggerTrait
, then we can just use: use LoggerTrait;
.
src/Logger.php Outdated
* @version Release:0.9.0 | ||
* @link https://github.com/jcupitt/php-vips | ||
*/ | ||
class Logger implements LoggerInterface |
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 rename to DebugLogger
.
src/Main.php Outdated
| ||
namespace Jcupitt\Vips; | ||
| ||
use \Psr\Log\LoggerInterface; |
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.
Nitpick: drop the first \
:
use Psr\Log\LoggerInterface;
src/Image.php Outdated
'arguments' => $arguments | ||
]); | ||
} | ||
Main::debug($name, array_merge(['instance' => $instance], $arguments)); |
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.
We could use: Main::debug($name, ['instance' => $instance, 'arguments' => $arguments)]);
instead of the array_merge
.
Some general comments added. I think it's fine to move the logic of the logger to a separate class. Not sure how we should name this class (perhaps Instead of Overall, I like the idea of making a one-liner to enable debug output. |
OK, all comments covered, I think. |
@kleisauke I'm pro- |
OK, left it as |
add a thing to make a simple debug logger to Image ... this makes it a one-liner to enable debug output
Perhaps this should be a separate class? It seems a bit stange to make an anon class in a member function like this, and phpcs hates it. @kleisauke, do you know what php typically does for this kind of thing?