Change logging from stdout to stderr

Created on 28 November 2021, over 3 years ago
Updated 16 June 2025, 17 days ago

Problem/Motivation

When logging to stdout it clashes with drush's messages and creates invalid JSON.
Ran into the problem running:
drush locale-check
An got the output:

  Unable to decode output into JSON: Syntax error

  {"message":"Translation file not found: https:\/\/ftp.drupal.org\/files\/translations\/9.x\/drupal\/drupal-9.2.7.da.po.","message_id":"dplcms_local619f7705a8be44.68761442","sit
  e_id":"dplcms_local","canonical":"dplcms_local","method":"GET","tags":null,"type":"drupal","subtype":"locale","severity":"Notice","request_uri":"http:\/\/dpl-cms.docker\/","ref
  erer":"","uid":0,"username":"","client_ip":"127.0.0.1","link":null,"code":0,"trunc":"","@version":1,"@timestamp":"2021-11-25T11:44:05.691Z"}{
      "0": {
          "files": [
              "drupal",
              "config_filter",
              "config_ignore",
              "jsonlog",
              "openid_connect",
              "purge",
              "redis",
              "varnish_purge",
              "dpl_cms"
          ]
      },
      "drush_batch_process_finished": true
  }

Steps to reproduce

Proposed resolution

Same problem is described in this issue:
https://github.com/drush-ops/drush/issues/4790#issuecomment-932729614

I tried to change the log output from `php://stdout? to `php://stderr` and it fixes the problem.
Plus it is still catched by our Promtail/Loki setup

Remaining tasks

Look at coming patch and considered if it is a valid solution.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇩🇰Denmark miksan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇲Armenia murz Yerevan, Armenia

    The actual source of this specific issue is the Drupal Core issue 🐛 [warning] No configuration objects have been updated. Needs work that got reverted for some reason.

    But the general issue with this - is that the stdout output can be mixed with any output, which causes the JSON parsing issues in many Drush commands.

    Actually, this happens not only with JSON-formatted logs, but for any log style that outputs to stdout (for example, by this module: https://www.drupal.org/project/log_stdout ).

    But for non-json output this issue in most cases doesn't produce the fatal error, because Drush tries to remove non-json output using this trick:

          $result = $process->getOutputAsJson();
    

    that uses under the hood the function Consolidation\SiteProcess\ProcessBase::getOutputAsJson()
    which uses a trick to remove non-json prefixes and suffixes in the function ProcessBase::removeNonJsonJunk().

    This is why it doesn't cause errors on non-json-formatted logs in most cases, until the log record doesn't have the { symbol.

Production build 0.71.5 2024