Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Implemented logging structure #304

Merged
merged 2 commits into from
Jan 16, 2018
Merged

Implemented logging structure #304

merged 2 commits into from
Jan 16, 2018

Conversation

everton-rosario
Copy link
Contributor

@everton-rosario everton-rosario commented Jan 12, 2018

Calls to Transformer have now stored all logging messages:

        $json_file = file_get_contents(__DIR__ . '/simple-rules.json');

        $instant_article = InstantArticle::create();
        $transformer = new Transformer();
        $transformer->loadRules($json_file);

        $html_file = file_get_contents(__DIR__ . '/simple.html');

        TransformerLog::setLevel(TransformerLog::DEBUG);
        $transformer->transformString($instant_article, $html_file);
        $result = $transformer->getLogs();

"symfony/css-selector": "2.8.* || ^3.0",
"facebook/graph-sdk": "~5.0",
"apache/log4php": "2.3.0"
"symfony/css-selector": "2.8.*",
Copy link

Choose a reason for hiding this comment

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

Can we upgrade this to latest one(i guess 4.0.3) if no dependency with this version(2.8.*)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyone is able to upgrade it, but we cannot move to 3.2 and up since it is not php 5.4 compatible.
We need to re-think the need of keeping php 5.4 compatibility

/**
* @var string[] $logs The log messages generated during the transformation process.
*/
private $logs = ['Possible log levels: OFF, ERROR, INFO or DEBUG'];
Copy link

Choose a reason for hiding this comment

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

How about WARN or FATAL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Warnings are all ready to be accessed from $transformer->getWarnings().

Fatals I see as the Exception handling being the best approach.

README.md Outdated
@@ -82,7 +82,7 @@ If you are encountering problems, the following tips may help in troubleshooting

- If content is missing from your transformed article, more likely than not there isn't a **Transformer Rule** matching an element in your source markup. See how to configure appropriate rules for your content in the [Transformer Rules documentation](https://developers.facebook.com/docs/instant-articles/sdk/transformer-rules).

- Set the `threshold` in the [configuration of the Logger](https://logging.apache.org/log4php/docs/configuration.html#PHP) to `DEBUG` to expose more details about the items processed by the Transformer.
- Set the `threshold` in the transformer Logger level to `DEBUG` to expose more details about the items processed by the Transformer. `$transformer->setLogLevel(Transformer::LOG_DEBUG);`
Copy link

Choose a reason for hiding this comment

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

Just Curious, What will be the advantage of using Logger implemented within the same code, instead of using the log4php library which already has lot of functionality.

@@ -73,8 +73,6 @@ public static function fromLevel($level, $message)
if ($validLevel) {
return new self($level, $message);
} else {
\Logger::getLogger('facebook-instantarticles-client')
->info('Unknown message level "$level". Are you using the last SDK version?');
Copy link

Choose a reason for hiding this comment

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

Will this file functions will be used over Transformer.php implementations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No.
All the package /Client is on SDK for making it easier to call all APIs for the IA ingestion. See more here.

Copy link
Contributor

@mburak mburak left a comment

Choose a reason for hiding this comment

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

I'd put all the logging methods/logic in a different class 'logger' or something similar just as a matter of separation of concerns. And then inject that class in the transformer and use it. What do you think?

*[x] Implemented a simple internal logging structure.
*[x] Removed log4php
*[x] Fixed #302
*[x] Fixed #245
*[x] Fixed #240

Calls to Transformer have now stored all logging messages:
```
        $json_file = file_get_contents(__DIR__ . '/simple-rules.json');

        $instant_article = InstantArticle::create();
        $transformer = new Transformer();
        $transformer->loadRules($json_file);

        $html_file = file_get_contents(__DIR__ . '/simple.html');

        $transformer->setLogLevel(Transformer::LOG_DEBUG);
        $transformer->transformString($instant_article, $html_file);
        $result = $transformer->getLogs();
```
@everton-rosario
Copy link
Contributor Author

Hey @mburak , good call on moving it away from Transformer class.

Check the new commit with this in place: e954e7e

@mburak
Copy link
Contributor

mburak commented Jan 16, 2018

hey @everton-rosario, it still looks a little bit coupled for me. What if instead of having the logs being added (that logic) in the Tranformer class we do that in the TransformerLog class (and maybe TranformerLogger is a better naming?).

So instead of having this:
$this->addLog( TransformerLog::INFO, 'Possible log levels: OFF, ERROR, INFO or DEBUG. To change it call method TransformerLog::setLevel("DEBUG").' );

we could have something like this:
TransformerLogger::logInfo($this->logs, 'Possible log levels: OFF, ERROR, INFO or DEBUG. To change it call method TransformerLog::setLevel("DEBUG").' );

so in this case we leave all the logging logic on the TransformerLogger class. I'm also adding an abstraction here so we don't use the different enums for each level and we just have a different method for each level logging.
What do you think?

Copy link
Contributor

@diegoquinteiro diegoquinteiro left a comment

Choose a reason for hiding this comment

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

<3

(consider @mburak's comments, though)

@everton-rosario
Copy link
Contributor Author

@mburak This is not a Logger tool. It was intended and built only for transformer, thats why I coupled it to the Transformer instance.
If we handle it as a Logger tool, we will have all transformations altogether into same log.

Here, with this simple structure, we have a log structure that isolates only transformation debug info, to improve depuration on the transformer.

Since it has all logging about transformation only, users of the SDK can optionally use their own logging system to output the transformation Log that occurred if they intend to, leaving it as optional.

Also I don't see this logging system being used to anything else but Transformation debug.

@mburak
Copy link
Contributor

mburak commented Jan 16, 2018

@everton-rosario gotcha. We could still handle each transformation in different logs even when having a decoupled logger. You pass the log array to the logger so the transformer still keeps the log state.
Anyway, I understand that's not the intention of this. Go for it!

@everton-rosario
Copy link
Contributor Author

Issue filed so we can treat it evenly not only for the logs, but also for the warnings:
#306

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

Successfully merging this pull request may close these issues.

5 participants