Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[WIP] [Console] Add basic support for automatic console exception logging#19382

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@jameshalsall
Copy link
Contributor

@jameshalsalljameshalsall commentedJul 18, 2016
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes (still to write tests for new feature)
Fixed tickets#10895
LicenseMIT
Doc PR(TO DO)

This is a quick initial concept for automatic exception logging, it currently takes the 2 listeners outlined in the docs (http://symfony.com/doc/current/cookbook/console/logging.html) and brings them into the standard edition.

I'd like to get some feedback before writing tests and updating the docs in a separate PR.

TODO:

  • Confirm messaging
  • Write tests
  • Update docs in separate PR
  • Prevent console errors from writing to stderr

hason reacted with thumbs up emoji
@jameshalsall
Copy link
ContributorAuthor

ping@Tobion - be good to get your feedback on this before I do any more

$event->setExitCode(255);
}

$message = sprintf('Command `%s` exited with status code %d');

Choose a reason for hiding this comment

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

this looks something else than what the title of this PR suggests. moreover, I'm not sure it's forth logging a non zero status code: it's the command's responsibility to know if it's worth logging of not, don't you think?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

The idea of this PR is to add automatic exception logging "out of the box" with zero configuration. Maybe I'm misunderstanding but surely anything other than a 0 exit code would result in some kind of log entry, unless there's a fatal PHP error before Symfony kernel bootstraps

Copy link
Member

Choose a reason for hiding this comment

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

  1. something is missing in the sprintf
  2. I would add the current argument/options

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

updated

@jameshalsall
Copy link
ContributorAuthor

After thinking about this a little more, I still can't help but think this is not a good idea:

  1. Console exceptions are handled by the Logger service and written to stdout by default
  2. When the user passes verbosity flags to the command, e.g.-vvv, they would expect that this information is still written to stdout
  3. I don't think it offers much value to have an exception listener by default that writes tovar/log folder when they would be written to stdout as well

I was against this originally in#10895, but thought it might offer some value for people. Now I'm not so sure.

Curious to see what@Tobion thinks as he was the Symfony member who originally was for this change.

@jameshalsalljameshalsall changed the titleAdd basic support for automatic console exception logging[WIP] [Console] Add basic support for automatic console exception loggingJul 30, 2016

$message = sprintf('Command `%s` exited with status code %d');

$this->logger->warning($message);
Copy link
Member

Choose a reason for hiding this comment

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

I would puterror.

@lyrixx
Copy link
Member

👍
(We have the same code in one of our internal repository)

}

if ($exitCode > 255) {
$event->setExitCode(255);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Great point, I will remove this

@jameshalsalljameshalsallforce-pushed theautomatic-console-exception-logging branch from6382bf1 to6acd944CompareAugust 9, 2016 18:57
$exitCode
);

$this->logger->error(

Choose a reason for hiding this comment

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

We prefer single line here, same above. And in fact I think the intermediate $message is not required.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

👍 my bad

@jameshalsalljameshalsallforce-pushed theautomatic-console-exception-logging branch fromb8209e7 to2874431CompareAugust 17, 2016 15:47
$this->logger->error('Command `{command}` exited with status code {code}',array('command' =>implode('',$_SERVER['argv']),'code' =>$exitCode));
$input =newArgvInput(null,$event->getCommand()->getDefinition());

$this->logger->error('Command `{command}` exited with status code {code}',array('command' => (string)$input,'code' =>$exitCode));
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need the backtick ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Probably not, I'll remove them


$exception = $event->getException();

$this->logger->error($exception->getMessage(), array('exception' => $exception));
Copy link
Member

Choose a reason for hiding this comment

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

I'm sorry to be very picky, but the log message is not good. I prefer something like that:
'Exception thrown while running command: "%s". Message: "%s".

It's better because if the RDBMS goes down (for example), many commands or consumers will fail. So you will receive N time the exact same message. It's better to have N messages because all commands are different and you must know what command fail.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

No problem, I'll update this later

"symfony/process":"~2.8|~3.0",
"psr/log":"~1.0"
"psr/log":"~1.0",
"phpunit/phpunit":"~4.0"
Copy link
Member

Choose a reason for hiding this comment

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

We never add phpunit dependency in symfony.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Not sure why that's showing, I reverted that change last night - was committed by mistake

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I saw that after commenting. Thanks.

@fabpot
Copy link
Member

@jameshalsall What's the status of this PR?

@jameshalsall
Copy link
ContributorAuthor

I will finish this off soon :)

James Halsall

Sent from
https://polymail.io/

On Wed, 14 Sep 2016 at 22:55 Fabien Potencier

<
mailto:Fabien Potenciernotifications@github.com

wrote:

a, pre, code, a:link, body { word-wrap: break-word !important; }

https://github.com/jameshalsall
What's the status of this PR?

You are receiving this because you were mentioned.

Reply to this email directly,
#19382 (comment)
, or
https://github.com/notifications/unsubscribe-auth/AAeg3Hf0DrRtq-6gSJR7pksk02gbyXRMks5qqG1IgaJpZM4JO_W1
.

@chalasr
Copy link
Member

It would be great to see this happen.

@jameshalsall
Copy link
ContributorAuthor

I'll pick this up again this week, had forgotten about it.

@chalasr
Copy link
Member

Finished in#21003, thanks@jameshalsall

@fabpot
Copy link
Member

Closing in favor of#21003

@fabpotfabpot closed thisJan 15, 2017
fabpot added a commit that referenced this pull requestJan 23, 2017
…eshalsall, chalasr)This PR was merged into the 3.3-dev branch.Discussion----------[Console][FrameworkBundle] Log console exceptions| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#10895| License       | MIT| Doc PR        |symfony/symfony-docs#7373Continues#19382, fixing some issues including:- ability to display the input string for any `InputInterface` implementation (cast to string if possible, use the command name otherwise)- if the input can be casted as string, cleanup the result (from `command "'command:name' --foo=bar" ` to `command "command:name --foo=bar"`)- made `ExceptionLister::$logger` private instead of protected-  changed methods name from `onKernel*` to `onConsole*` (e.g. `onConsoleException`) and removed unnecessary doc blocks- Added more testsLog for an exception:> [2016-12-22 00:34:42] app.ERROR: Exception thrown while running command: "cache:clear -vvv". Message: "An error occured!" {"exception":"[object] (RuntimeException(code: 0): An error occured! at /Volumes/HD/Sites/tests/sf-demo-3.2/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:61)","command":"cache:clear -vvv","message":"An error occured!"} []Commits-------919041c Add Console ExceptionListener9896547 Add basic support for automatic console exception logging
@nicolas-grekasnicolas-grekas modified the milestones:3.x,3.3Mar 24, 2017
@haroldiedema
Copy link

Exit codes are used to communicate with the processes that spawned a process (e.g symfony command). In our case, we use exit codes to communicate back to bash processes to indicate what a spawned process did.

Now our 'error'-logs are being spammed for no reason sinceexit code 3 isNOT an error.

In short: An exit code other than0 isn't necessarily an error. This commit makes the assumption that it is.

@chalasr
Copy link
Member

@haroldiedema Would you mind to open a PR for changing the log level?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

10 participants

@jameshalsall@lyrixx@fabpot@chalasr@haroldiedema@nicolas-grekas@hason@Nicofuma@javiereguiluz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp