Follow-up from #638536: Return a non-zero exit status on errors ...

dmitrig01 says drush make is just calling drush_log('foo', 'error'). To be a good CLI citizen, when drush is logging 'error', it should write it to stderr, not stdout.

CommentFileSizeAuthor
#12 drush-log-to-stderr.patch1.51 KBgreg.1.anderson

Comments

moshe weitzman’s picture

I'll let adrian chime in here. Meanwhile, an equivalent way to log errors that is more clear is drush_set_error('foo')

moshe weitzman’s picture

FYI, nothing goes to stdout except errors unless you have an elevated debug level. are you running with --verbose (-v) or --debug (-d)?

dww’s picture

Regardless of -v or -d, errors belong in stderr. That's how UNIX has worked for decades, for good reason. ;) Otherwise, you can't pipe things into each other or the payload gets mixed in with the errors/warnings.

dmitrig01’s picture

I did mean drush_set_error

moshe weitzman’s picture

Assigned: Unassigned » adrian

comments?

greg.1.anderson’s picture

I agree that stderr should be preferred to stdout for all log, error and debug messages.

anarcat’s picture

Issue tags: +drush-3.0

I agree everything should go to stderr, but if things are going to stdout now (which i find odd), Aegir will need some patching.

I think this change should be done before 3.0 gets shipped.

JacobSingh’s picture

I need this too..

How should this be implemented? Should we output exactly the same format? It's not very parsable, but perhaps that doesn't matter?

for now, I just chucked this in my drush_log

if ($error || $type == 'failed') {
    // write to stderr
    fwrite(STDERR, "$type: $message \n");
    return;
  }

But obviously, we should do better.

Best,
J

torotil’s picture

Component: Code » PM (dl, en, up ...)

+1 for dumping errors into stderr. What's the problem with in implementing this?

moshe weitzman’s picture

Title: drush_log('foo', 'error') should be written to stderr, not stdout » drush_log() should write to stderr, not stdout
Version: All-Versions-2.1 »
Component: PM (dl, en, up ...) » Base system (internal API)
Assigned: adrian » Unassigned
Issue tags: -drush-3.0

No problem. Someone needs to contribute a patch.

greg.1.anderson’s picture

Assigned: Unassigned » greg.1.anderson

Yeah, I've got this working; I'll post a patch later.

greg.1.anderson’s picture

Title: drush_log() should write to stderr, not stdout » drush_log() should write to stderr, not stdout, and $green should actually be green.
Status: Active » Needs review
StatusFileSize
new1.51 KB

Switching drush_log to stderr required only a couple trivial changes. As an added bonus, this patch also fixes a typo in $green. Previously, $green rendered as yellow. Adjusted per http://rtfm.etla.org/xterm/ctlseq.html; "32: Set foreground color to Green", "33 Set foreground color to Yellow".

moshe weitzman’s picture

Looks good to me. Could we add some docs about how to use this. Maybe a script in examples? Otherwise, a link to STDERR usage somewhere on the internets.

I'd love some +1 from the Aegir folks.

owen barton’s picture

Looks good to me too - basically we just want drush_print output (i.e. content, not log output) to go to stdout by default, which I think is what this does. I agree $handle usage could use some docs.

greg.1.anderson’s picture

Status: Needs review » Fixed

I did a couple more tests to convince myself that the output and data structures in backend invoke were not affected, and as I had presumed, it came out unchanged. Committed with an additional comment for $handle in drush_print.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.