Error message output
dpchrist at holgerdanske.com
Mon Sep 21 22:33:45 UTC 2020
On 2020-09-21 04:21, Polytropon wrote:
> On Sun, 20 Sep 2020 22:12:24 -0700, David Christensen wrote:
>> On 2020-09-20 10:11, Polytropon wrote:
>>> I have a general question. Is it still considered useful to
>>> output error messages of a script to standard error?
> What about form?
> echo "the error message" > /dev/stderr
> echo "the error message" >&2
> WHich one is considered better form, leaving aside the "amount of
> symbols needed"?
"It depends". The former is dependent upon the system having a
/dev/stderr. The latter is dependent upon the shell having redirection
(which all Bourne-compatible shells should?). Both seem to work on
FreeBSD, Debian, macOS, and Cygwin (Windows 7). But, that is likely to
be untrue on every system. And, is it possible to have a situation
where you have already redirect stderr and yet the script needs to emit
an error message? Without a compelling reason either way, I have tended
to use the latter; but the former is starting to look more idiot-proof.
> I'm primarily interested in what currently the consensus is
> about good form and style, common approach and accepted ways
> of doing things. I could keep spamming the system log with
> progress messages, but that wouldn't be nice, would it? ;-)
My ideal would be to put "less important" messages into a
program-specific log(s) and to put "important" messages into both
program-specific logs and the system log. Again, under configuration/
Truly sophisticated programs use a logging management layer. For
example, in Perl:
More information about the freebsd-questions