Bug 849917 - error messages shall be logged to stderr rather than to stdout
Summary: error messages shall be logged to stderr rather than to stdout
Keywords:
Status: NEW
Alias: None
Product: Red Hat Enterprise MRG
Classification: Red Hat
Component: qpid-tools
Version: Development
Hardware: Unspecified
OS: Unspecified
medium
low
Target Milestone: ---
: ---
Assignee: messaging-bugs
QA Contact: MRG Quality Engineering
URL:
Whiteboard:
Depends On:
Blocks: 1082102
TreeView+ depends on / blocked
 
Reported: 2012-08-21 08:34 UTC by Petr Matousek
Modified: 2024-01-19 19:11 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Clone Of:
: 1082102 (view as bug list)
Environment:
Last Closed:
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
proposed patch (3.78 KB, patch)
2014-03-28 13:47 UTC, Petr Matousek
eallen: review-
Details | Diff

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.


Note You need to log in before you can comment on or make changes to this bug.