Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add configuration for new HttpCodeActivationStrategy #221

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

Merged
merged 2 commits into from
Apr 4, 2018

Conversation

simshaun
Copy link
Contributor

Dependent upon symfony/symfony#23707

This PR introduces configuration to integrate a new HttpCodeActivationStrategy, offering an easy way to ignore specific HTTP status codes.

@simshaun
Copy link
Contributor Author

Note: Travis failure seems to be unrelated:

HHVM is no longer supported on Ubuntu Precise. Please consider using Trusty with `dist: trusty`.

@xabbuh
Copy link
Member

xabbuh commented Jul 31, 2017

You need to update the schema definition too.

@simshaun
Copy link
Contributor Author

Thanks. Added

@@ -316,6 +317,7 @@ public function getConfigTreeBuilder()
->prototype('array')
->fixXmlConfig('member')
->fixXmlConfig('excluded_404')
->fixXmlConfig('excluded_http_code')
Copy link

Choose a reason for hiding this comment

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

excluded_http_codes

Copy link
Member

Choose a reason for hiding this comment

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

No, this is exactly what we want. The singular named excluded-http-code XML element node will be transformed into a list names excluded_http_codes.

@simshaun
Copy link
Contributor Author

Per discussion on the related symfony/symfony PR, this strategy now supports a URL blacklist per status code.

I really struggled with making the Configuration tree work with both YAML and XML. I ended up just normalizing the two into a common format that the new activation strategy understands.

It now supports:

YAML:

excluded_http_codes: [403, 404, { 400: ['^/foo', '^/bar'] }]

XML:

<monolog:excluded-http-code code="403" />
<monolog:excluded-http-code code="404" />
<monolog:excluded-http-code code="400">
  <monolog:url>^/foo</monolog:url>
  <monolog:url>^/bar</monolog:url>
</monolog:excluded-http-code>

fabpot added a commit to symfony/symfony that referenced this pull request Apr 4, 2018
… for ignoring specific HTTP codes (simshaun, fabpot)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[Monolog Bridge][DX] Add a Monolog activation strategy for ignoring specific HTTP codes

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #9712
| License       | MIT
| Doc PR        | symfony/symfony-docs#8235

This PR introduces a Monolog activation strategy that makes it easy to ignore specific HTTP codes. e.g. Stopping logs from being flooded with 403s, 404s, and 405s.

Relevant Symfony integration PR on symfony/monolog-bundle: symfony/monolog-bundle#221

Commits
-------

6fc1cc3 added some validation
c11a8eb Add a Monolog activation strategy for ignoring specific HTTP codes
if (is_array($value)) {
return isset($value['code'])
? $value
: array('code' => key($value), 'url' => current($value));
Copy link
Member

Choose a reason for hiding this comment

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

should be urls (as I've changed the convention in the Symfony related PR)

Copy link
Member

Choose a reason for hiding this comment

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

should be on one line

@@ -336,6 +336,14 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
));
$container->setDefinition($handlerId.'.not_found_strategy', $activationDef);
$activation = new Reference($handlerId.'.not_found_strategy');
} elseif (!empty($handler['excluded_http_codes'])) {
$activationDef = new Definition('Symfony\Bridge\Monolog\Handler\FingersCrossed\HttpCodeActivationStrategy', array(
Copy link
Member

Choose a reason for hiding this comment

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

we should probably throw an exception is the class does not exist (perhaps even in the config builder)?

@fabpot fabpot force-pushed the http-code-activation-strategy branch 3 times, most recently from 60ae22a to 9e34b50 Compare April 4, 2018 06:44
@fabpot fabpot force-pushed the http-code-activation-strategy branch from 9e34b50 to 30a70a2 Compare April 4, 2018 06:50
@fabpot
Copy link
Member

fabpot commented Apr 4, 2018

Thank you @simshaun.

@fabpot fabpot merged commit 30a70a2 into symfony:master Apr 4, 2018
fabpot added a commit that referenced this pull request Apr 4, 2018
…mshaun, fabpot)

This PR was merged into the 3.x-dev branch.

Discussion
----------

Add configuration for new HttpCodeActivationStrategy

Dependent upon symfony/symfony#23707

This PR introduces configuration to integrate a new `HttpCodeActivationStrategy`, offering an easy way to ignore specific HTTP status codes.

Commits
-------

30a70a2 tweaked code
61a78a6 Add configuration for new HttpCodeActivationStrategy
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request May 15, 2018
…n, javiereguiluz)

This PR was merged into the 4.1 branch.

Discussion
----------

Document new Monolog HTTP code exclusion feature

I'm submitting PRs on symfony/symfony and symfony/monolog-bundle that introduces an easy way of excluding specific HTTP codes from Monolog.

This PR documents that new feature, pending its acceptance.

Pending PRs:
symfony/symfony#23707
symfony/monolog-bundle#221

Commits
-------

30cc7d4 Added the versionadded directive
c8c19f2 Update to Symfony 4 paths
e19bca2 Fix indentation
17cb416 Update configuration format to support URL blacklist
c9f6ee5 Fix title underline length
a3b6a01 Document new Monolog HTTP code exclusion feature
@soullivaneuh
Copy link

@fabpot This bundle seems to be outside the Symfony roadmap. Do you have a defined date for the next release? Thanks.

@lyrixx
Copy link
Member

lyrixx commented Jun 4, 2018

@soullivaneuh It has been released this morning 🎉

@soullivaneuh
Copy link

Thanks for the info @lyrixx! 👍

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.

6 participants