-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Make Phalcon\Logger\Adapter compatible with PSR-3 #1873
Conversation
Apparently we cannot implement |
OK to merge :-) |
Make Phalcon\Logger\Adapter compatible with PSR-3
Great |
@phalcon Do you think it is worth adding this to Phalcon: https://github.com/sjinks/psr3logger My concern is that Phalcon\Logger cannot be used where Psr\Log\LoggerInterface is required — just because that interface is created after Phalcon is initialized and destroyed when the request finishes. However, when that interface is loaded from a PHP extension, we can use it safely. I was thinking about a php.ini option, say, What do you think? |
It's ok, it would not break existing applications unless developers are explicitly requiring those interfaces instead of using an autoloader. |
Guys, I've just recompiled Phalcon and my log device is now completely broken. I understand reasons for making it PSR-3 compatible, but this a drastic change. You'd veto a change because it may break existing code, but what about this one here? App\Log\Stub contains 3 abstract methods and must therefore be declared abstract or implement the remaining methods (Phalcon\Logger\Adapter::logInternal, Phalcon\Logger\AdapterInterface::getFormatter, Phalcon\Logger\AdapterInterface::close) What are those methods supposed to do? |
To give you more info. I have a class that acts as log stub: class Stub extends \Phalcon\Logger\Adapter
{
/**
* Sends/Writes an emergence message to the log
*
* @param string $message
* @return \Phalcon\Logger\Adapter
*/
public function emergence($message, array $context=null){ }
/**
* Sends/Writes a debug message to the log
*
* @param string $message
* @param ing $type
* @return \Phalcon\Logger\Adapter
*/
public function debug($message, array $context = NULL){ }
/**
* Sends/Writes an error message to the log
*
* @param string $message
* @return \Phalcon\Logger\Adapter
*/
public function error($message, array $context = NULL){ }
/**
* Sends/Writes an info message to the log
*
* @param string $message
* @return \Phalcon\Logger\Adapter
*/
public function info($message, array $context = NULL){ }
/**
* Sends/Writes a notice message to the log
*
* @param string $message
* @return \Phalcon\Logger\Adapter
*/
public function notice($message, array $context = NULL){ }
/**
* Sends/Writes a warning message to the log
*
* @param string $message
* @return \Phalcon\Logger\Adapter
*/
public function warning($message, array $context = NULL){ }
/**
* Sends/Writes an alert message to the log
*
* @param string $message
* @return \Phalcon\Logger\Adapter
*/
public function alert($message, array $context = NULL){ }
/**
* Logs messages to the internal loggger. Appends logs to the
*
* @param string $message
* @param int $type
* @return \Phalcon\Logger\Adapter
*/
public function log($type, $message, array $context = NULL){ }
} So now Phalcon complains about unimplemented abstract methods. How do I implement them? Thanks. |
@temuri416 those methods have nothing to do with PSR-3. PSR-3 changes were adding close() and getFormatter() were always there, nothing has changed: sjinks@32beceb#diff-91283c398e56077e0a3b0f0975719670L61 logInternal() is (and was) invoked by LoggerAdapter::commit() and log(). Are you sure you are not missing anything? |
Hmmmm. Can you see whether close() and getFormatter() were there in 1.2.4 branch? |
If you inherit from class Stub extends \Phalcon\Logger\Adapter
{
protected function logInternal($message, $type, $time, $context) {}
public function getFormatter() { return new \Phalcon\Logger\Formatter\Line(); } // return null; will probably work either
} |
Something isn't right then. I had the following class working fine under Phalcon 1.2.4: class Stub extends \Phalcon\Logger\Adapter
{
/**
* Sends/Writes an emergence message to the log
*
* @param string $message
* @return \Phalcon\Logger\Adapter
*/
public function emergence($message){ }
/**
* Sends/Writes a debug message to the log
*
* @param string $message
* @param ing $type
* @return \Phalcon\Logger\Adapter
*/
public function debug($message){ }
/**
* Sends/Writes an error message to the log
*
* @param string $message
* @return \Phalcon\Logger\Adapter
*/
public function error($message){ }
/**
* Sends/Writes an info message to the log
*
* @param string $message
* @return \Phalcon\Logger\Adapter
*/
public function info($message){ }
/**
* Sends/Writes a notice message to the log
*
* @param string $message
* @return \Phalcon\Logger\Adapter
*/
public function notice($message){ }
/**
* Sends/Writes a warning message to the log
*
* @param string $message
* @return \Phalcon\Logger\Adapter
*/
public function warning($message){ }
/**
* Sends/Writes an alert message to the log
*
* @param string $message
* @return \Phalcon\Logger\Adapter
*/
public function alert($message){ }
/**
* Logs messages to the internal loggger. Appends logs to the
*
* @param string $message
* @param int $type
* @return \Phalcon\Logger\Adapter
*/
public function log($message, $type=null){ }
} (as a side note, I added It was not supposed to log anything, I was using it as a substitute when I wanted to globally disable log devices. How could it have worked then if those abstract methods that were there in 1.2.4 are missing from my stub class? |
That's because of this one: #1852 In 1.2.4 Adapters never implemented AdapterInterface. |
|
Don't think so — it is only in 1.3.0
Perform cleanup if necessary. For example, for Phalcon\Logger\Adapter\File close() just closes the file. For Phalcon\Logger\Adapter\FirePhp it does nothing and just returns true.
Yes, you would want to implement |
ok, thanks for your time. I'll just update my Stub class, fix signatures, upgrade to 1.3.0 and stop thinking about it. Cheers. |
BTW, if you use |
This includes:
array $context = array()
)