Bug 849917

Summary: error messages shall be logged to stderr rather than to stdout
Product: Red Hat Enterprise MRG Reporter: Petr Matousek <pematous>
Component: qpid-toolsAssignee: messaging-bugs <messaging-bugs>
Status: NEW --- QA Contact: MRG Quality Engineering <mrgqe-bugs>
Severity: low Docs Contact:
Priority: medium    
Version: DevelopmentCC: jross
Target Milestone: ---Keywords: Improvement
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
: 1082102 (view as bug list) Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1082102    
Attachments:
Description Flags
proposed patch eallen: review-

Description Petr Matousek 2012-08-21 08:34:59 UTC
Description of problem:

Exceptions and error messages are logged to stdout instead of stderr.
The stream stdout is buffered. This can produce unexpected results, especially with debugging output. 

Version-Release number of selected component (if applicable):
qpid-tools-0.14-5

How reproducible:
100%

Steps to Reproduce:
1. run management tools without broker running
2. realize that the error message was logged to stdout
  
Actual results:
Exceptions and error messages are logged to stdout

Expected results:
Exceptions and error messages are logged to stderr

Additional info:

# service qpidd status
qpidd is stopped
# qpid-config 2>/dev/null
Failed: error: (111, 'Connection refused')
# service qpidd start
Starting Qpid AMQP daemon:                                 [  OK  ]
# qpid-config -a amqps://localhost:5671 --ssl-certificate=cert.pem 2>/dev/null
Failed: Exception: Client authentication not supported by this version.

Comment 3 Petr Matousek 2014-03-28 13:47:51 UTC
Created attachment 879838 [details]
proposed patch

note: the patch also removes extra trailing spaces

Comment 5 Ernie 2014-03-28 14:54:22 UTC
Comment on attachment 879838 [details]
proposed patch

This works well for qpid-config. We'll need to make similar changes to the other python tools.

You might consider using the new print function syntax:
from __future__ import print_function
and adding a function:
def print_stderr(str):
    print(str, file=sys.stderr)

and then calling print_stderr() whenever you explicity want to print to stderr. 
The pros of doing this are
- It is future-proof in that it is the recommended way for python 2.x and 3.x
- Calling a function named print_stderr is self-documenting

The big con of doing this is that all print statements would need to be changed to print functions. 

See http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function

Comment 6 Justin Ross 2014-03-28 15:41:27 UTC
(In reply to Ernie from comment #5)
> Comment on attachment 879838 [details]
> proposed patch
> 
> This works well for qpid-config. We'll need to make similar changes to the
> other python tools.
> 
> You might consider using the new print function syntax:
> from __future__ import print_function
> and adding a function:
> def print_stderr(str):
>     print(str, file=sys.stderr)
> 
> and then calling print_stderr() whenever you explicity want to print to
> stderr. 
> The pros of doing this are
> - It is future-proof in that it is the recommended way for python 2.x and 3.x
> - Calling a function named print_stderr is self-documenting
> 
> The big con of doing this is that all print statements would need to be
> changed to print functions. 
> 
> See http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function

Unfortunately, I don't think we can use print_function.  It appears to have become available in python 2.6, and el5 is python 2.4.

Comment 7 Justin Ross 2014-03-28 16:07:58 UTC
(In reply to Justin Ross from comment #6)
> (In reply to Ernie from comment #5)
> > Comment on attachment 879838 [details]
> > proposed patch
> > 
> > This works well for qpid-config. We'll need to make similar changes to the
> > other python tools.
> > 
> > You might consider using the new print function syntax:
> > from __future__ import print_function
> > and adding a function:
> > def print_stderr(str):
> >     print(str, file=sys.stderr)
> > 
> > and then calling print_stderr() whenever you explicity want to print to
> > stderr. 
> > The pros of doing this are
> > - It is future-proof in that it is the recommended way for python 2.x and 3.x
> > - Calling a function named print_stderr is self-documenting
> > 
> > The big con of doing this is that all print statements would need to be
> > changed to print functions. 
> > 
> > See http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function
> 
> Unfortunately, I don't think we can use print_function.  It appears to have
> become available in python 2.6, and el5 is python 2.4.

Eeks, my mistake.  This is targeted for versions of RHEL > 5, so Ernie's advice stands.

Comment 8 Petr Matousek 2014-03-28 16:43:43 UTC
Actually it shall be addressed in both 2.x and 3.x, so leaving this bug tracking 2.x defect and cloning for 3.x.