Skip to content

[Console] allow the console logging handler to work and prevent propagation only when interactive #58715

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

Open
dkarlovi opened this issue Oct 30, 2024 · 8 comments · May be fixed by #59955 or symfony/monolog-bundle#504
Labels

Comments

@dkarlovi
Copy link
Contributor

dkarlovi commented Oct 30, 2024

Description

Let's assume this setup

monolog:
    handlers:
        console:
            type: console
            interactive_only: true # this is new
        logstash:
            type: stream
            path: "php://stderr"
            formatter: 'monolog.formatter.logstash'

Now let's assume we're running some command meant for non-interactive use, like messenger:consume, see #57776.

When running the command using logging interactively (user running the command and watching the output) currently, you'll get both the command output, console output and the logstash JSON, which is creating a giant mess of output.

What would be better is to allow the logger to know if there's a user watching the output (command is in an interactive shell or not) and then:

  1. output console and skip logstash (prevent bubble) when interactive
  2. skip console and only output logstash when not interactive

This would mean the logging is adjusted to the current runtime better automatically.

Example

No response

@dkarlovi
Copy link
Contributor Author

/cc @ro0NL IIRC we spoke about this in several other issues?

@dkarlovi
Copy link
Contributor Author

IMO the described feature would serve a similar purpose without needing to do any special setup per environment or custom handlers, just with config like shown.

@dkarlovi
Copy link
Contributor Author

That's precisely what the interactive / non interactive thing is meant to signal: has user or not.

@stof
Copy link
Member

stof commented Oct 30, 2024

if you don't configure your cron with -n, it is still probably running in non-interactive mode due to the way the command is launched (unless your cron launches the command in a tty, but then, what does it do to provide input during interaction ?)

@dkarlovi
Copy link
Contributor Author

@ro0NL yes, this would be opt-in since it's a new minor feature, otherwise it would be a BC break, no?

@dkarlovi
Copy link
Contributor Author

BTW I've checked this and the issue is, ConsoleHandler takes OutputInterface, but we need the InputInterface too because that's where isInteractive() is.

private ?OutputInterface $output = null,

The idea might be to add it as the last arg and make it nullable and wire it up only if interactive_only: true is set, this would be the opt-in. Does that make sense?

@dkarlovi
Copy link
Contributor Author

@stof (I'm pinging you because you seem to be the Monolog Bundle guy), assuming I want to work on this, am I right to understand this would be two separate PRs?

  1. monorepo PR, add support for injecting InputInterface to ConsoleHandler
  2. Monolog bundle PR, add support to configure injecting it to opt in

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