Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Sep 2020 15:33:40 -0700
From:      David Christensen <dpchrist@holgerdanske.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Error message output
Message-ID:  <8b426d6f-6ebe-d1a7-13af-69cffbcb6222@holgerdanske.com>
In-Reply-To: <20200921132139.286b5bda.freebsd@edvax.de>
References:  <20200920191108.22864e5c.freebsd@edvax.de> <528b2c90-18c4-9e95-a150-67344154c66c@holgerdanske.com> <20200921132139.286b5bda.freebsd@edvax.de>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
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
> 
> or
> 
> 	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/ 
option control.


Truly sophisticated programs use a logging management layer.  For 
example, in Perl:

     https://metacpan.org/pod/Log::Log4perl


David



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?8b426d6f-6ebe-d1a7-13af-69cffbcb6222>