Thread: BUG #11477: psql -L no stderr

BUG #11477: psql -L no stderr

From
hans@matfyz.cz
Date:
The following bug has been logged on the website:

Bug reference:      11477
Logged by:          Hans Ginzel
Email address:      hans@matfyz.cz
PostgreSQL version: 9.4beta2
Operating system:   Centos 6.5
Description:

Hello!

Command
psql -L logfile
logs only stdout (formated with stars) but not stderr.

Command
psql -L logfile 2>logfile
logs also warnings/errors but does not write them to terminal.

Command
psql 1>&2 |tee logfile
writes both to terminal and file but without stars formatting.

I am sorry, but log without errors logging is NOT a log file. I consider not
logging stderr to logfile when -L is specified as a bug.

Please add coppying also stderr to logfile when -L.

Thank you
HG

Re: BUG #11477: psql -L no stderr

From
Bruce Momjian
Date:
On Tue, Sep 23, 2014 at 02:45:46PM +0000, hans@matfyz.cz wrote:
> The following bug has been logged on the website:
>
> Bug reference:      11477
> Logged by:          Hans Ginzel
> Email address:      hans@matfyz.cz
> PostgreSQL version: 9.4beta2
> Operating system:   Centos 6.5
> Description:
>
> Hello!
>
> Command
> psql -L logfile
> logs only stdout (formated with stars) but not stderr.
>
> Command
> psql -L logfile 2>logfile
> logs also warnings/errors but does not write them to terminal.
>
> Command
> psql 1>&2 |tee logfile
> writes both to terminal and file but without stars formatting.
>
> I am sorry, but log without errors logging is NOT a log file. I consider not
> logging stderr to logfile when -L is specified as a bug.
>
> Please add coppying also stderr to logfile when -L.

The documentation says:

       -L filename
       --log-file=filename
           Write all query output into file filename, in addition to the normal output destination.

There is no mention of errors being logged here.  Logging is more than
logging of errors.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +

Re: BUG #11477: psql -L no stderr

From
David G Johnston
Date:
Bruce Momjian wrote
>> I am sorry, but log without errors logging is NOT a log file. I consider
>> not
>> logging stderr to logfile when -L is specified as a bug.
>>
>> Please add coppying also stderr to logfile when -L.
>
> The documentation says:
>
>        -L filename
>        --log-file=filename
>            Write all query output into file filename, in addition to the
> normal output destination.
>
> There is no mention of errors being logged here.  Logging is more than
> logging of errors.

For further emphasis:

Under \o

"Query results" includes all tables, command responses, and notices obtained
from the database server, as well as output of various backslash commands
that query the database (such as \d), but not error messages.


Though playing with it a bit I'll agree that the functionality seems
artificially constrained.  Unfortunately, simply changing the behavior
doesn't seem like it is something that would obtain sufficient support for
the backward compatibility break.

Would something like the below work?

psql -L filename.txt -L -c "SELECT 1 = 'txt'";

The idea being you can specify a plain "-L" flag a second time and it will
redirect stderr to the same location specified in the first flag.

Being able to supervise a script but have it completely captured in the
activity log makes sense.  I guess setting ECHO to 'queries' and simply
redirecting all output to a file would be the current imposed solution but
the -L option has the nice property of cleanly setting off the "input" query
from that query's output.

I don't get why notices and warnings would be considered "query output"
while the error message resulting from a failed query would not.  I need
more than "its documented" to really convince me that this isn't an
incomplete feature - which while not a technical bug is arguably a usage
one.

I haven't thought through all possible use-cases/combination for/of terminal
& file output but taken in isolation the goal stated here makes sense and is
not currently possible - at best you get your complete file but lose the
ability to view the errors on the terminal.  Am I missing something?

David J.



--
View this message in context: http://postgresql.1045698.n5.nabble.com/BUG-11477-psql-L-no-stderr-tp5820153p5821492.html
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.