Skip to content

Logging - Don't require psr/log for cv-lib. Fix STDERR/STDOUT routing.#169

Merged
totten merged 7 commits intocivicrm:masterfrom
totten:master-psr-oops-nm
Jul 13, 2023
Merged

Logging - Don't require psr/log for cv-lib. Fix STDERR/STDOUT routing.#169
totten merged 7 commits intocivicrm:masterfrom
totten:master-psr-oops-nm

Conversation

@totten
Copy link
Member

@totten totten commented Jul 13, 2023

This is a multi-prong update to logging. There are two major themes:

Don't require psr/log

In discussion about civix using cv-lib, we found that some environments have contention over the substance of psr/log. (cv-lib may load its copy of psr/log before the UF starts, and UF's may have different expectations for the version of psr/log.) And the reality is that psr/log has several major versions in the wild.

So as a defensive move, it's better if cv-lib doesn't have any specific expectations about psr/log.

Cleanup STDERR/STDOUT distinction

When you enable verbose output (cv -vvv), cv has been a bit confused about which information should go to STDOUT and which to STDERR.

Since cv (and cv-lib) are intended to be used in many kinds of scripts (including scripts with structured output - JSON, SQL, PHP, etc), it's bad default to send any logs to STDOUT. The verbose logs should go to STDERR.

SO there are a few patches to make that change.

totten added 7 commits July 13, 2023 02:03
Before: Errors go to STDERR. Notices and debug msgs go to STDOUT.

After: All of them go to STDERR.

Comment:

* If you come from a logging POV, the old policy probably *sounds* right.
  You're just taking a log-taxonomy of 8 buckets and mapping into the
  log-taxonomy of 2 buckets. (Buckets are important - they help you decide
  if something is important enough to look at!)

* If you come from a Unix scripting POV, this is insane. Sure, by default, they
  both display to the console-user. The difference is comes when you chain
  together commands. STDOUT goes to the next command, but STDERR stays with
  the console-user.

* In Unix POV, the question should be: "What is the primary output-format of my program?"
    * Ex: Suppose your command reads a database and outputs some JSON. Then...
      do not, ever, for the love of god, send the general activity logs to
      STDERR -- even if there are errors! It'll munge the JSON document!
    * Ex: Suppose your command is a small network service, and you output a
      request-log. Great - send that to STDOUT. It'll be easy for anyone
      to record the log (`./my-program > my.log`). But then do not, for the
      love of god, send any errorlogs to STDERR - they will not go the logfile!
    * Ex: Suppose your command is interactive - you print some lines, then
      ask for input, then print lines. Back+forth. But in this case,
      there is no real difference STDERR and STDOUT -- they're displayed
      as a single stream to the console-user.
@totten
Copy link
Member Author

totten commented Jul 13, 2023

civibot, test this please

@totten
Copy link
Member Author

totten commented Jul 13, 2023

Most tests are passing. The failure appears to be random network I/O issues (e.g. Could not resolve host: github.com). When I re-ran, it just flip-flopped somethings with (different) random network I/O issues. So... I don't think the test-suite is finding any problems in the code.

@totten totten merged commit 9d50c00 into civicrm:master Jul 13, 2023
@totten totten deleted the master-psr-oops-nm branch July 13, 2023 11:54
@demeritcowboy
Copy link
Contributor

This works for me to resolve the drupal 10 problem in totten/civix#300. Thanks @totten.

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.

2 participants