Skip to content
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

Initial work on moving the Processor for messages to a separate class #21

Open
wants to merge 1 commit into
base: v2_future
Choose a base branch
from

Conversation

terwey
Copy link
Contributor

@terwey terwey commented Nov 15, 2017

Currently in Flexilog the AbstractHandler took care of a lot of things, and some Handlers also were not generic enough to be easily put to use for specific tasks.
The introduction of a Processor should allow this to be easily extendable depending on the task.

As an example I've included a cleaned up FileHandler and a new LogfileHandler.

@terwey terwey requested review from m038, 0bp and r4ndsen November 15, 2017 17:04
@terwey terwey self-assigned this Nov 15, 2017
if (is_null($processor)) {
$this->processor = new \Productsup\Flexilog\Processor\DefaultProcessor();
} else {
$this->processor = $processor;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->processor = $processor ?? new \Productsup\Flexilog\Processor\DefaultProcessor;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make the entire codebase PHP7 minimum, since this feature didn't exist before. http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op

Currently the codebase is PHP5.6 compatible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

if (is_null($processor)) {
    $processor = new \Productsup\Flexilog\Processor\DefaultProcessor();
}
$this->processor = $processor;

Copy link
Contributor

@m038 m038 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at my questions and remarks.

@@ -30,9 +33,20 @@
*
* @param string $minimalLevel the minimal severity of the LogLevel to start logging with
* @param integer $verbose the Verbosity of the Log
* @param array $additionalParameters optional additional parameters required for the Handler
* @param \Productsup\Flexilog\Processor $processor the Processor to be used for the Handler, if none supplied
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\Productsup\Flexilog\Processor can be replaced with ProcessorInterface

public function __construct($minimalLevel = 'debug',
$verbose = 0,
array $additionalParameters = array(),
ProcessorInterface $processor = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PSR-2 Compliant would be:

public function __construct(
    $minimalLevel = 'debug',
    $verbose = 0,
    array $additionalParameters = array(),
    ProcessorInterface $processor = null
) {

if (is_null($processor)) {
$this->processor = new \Productsup\Flexilog\Processor\DefaultProcessor();
} else {
$this->processor = $processor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

if (is_null($processor)) {
    $processor = new \Productsup\Flexilog\Processor\DefaultProcessor();
}
$this->processor = $processor;

/**
* Abstract Handler to simplify the implementation of a Handler Interface
*/
abstract class AbstractHandler implements HandlerInterface
{
protected $logger = null;
protected $processor = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docblock:

/**
 * @var ProcessorInterface
 **/

* @return HandlerInterface $this
*/
public function setLogger(\Productsup\Flexilog\Logger $logger)
public function setProcessor(\Productsup\Flexilog\Processor $processor)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docblock.

It the property $processor now a Processor or a ProcessorInterface? Big difference imo.

*/
abstract class AbstractProcessor implements ProcessorInterface
{
protected $handler = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add:

/**
 * @var \Productsup\Flexilog\Handler
 **/

*
* @param string $level
* @param string $message
* @param array $context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing:

@return string

*
* @param string $level
* @param string $contextKey
* @param string $contextObject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing @return in docblock

}

/**
* Return a separator between the Message and the Context if applicable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing @return in docblock.

{
// build a replacement array with braces around the context keys
$replace = array();
foreach ($context as $key => $val) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe context preparation should take place automatically inside this method? Or indicate that $context should actually be a preparedContext, since that handles most data types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants