[arch-projects] [netctl][PATCH] beautify error output

Dave Reisner d at falconindy.com
Wed Oct 23 11:13:50 EDT 2013


On Wed, Oct 23, 2013 at 02:06:49PM +0200, Jouke Witteveen wrote:
> Also: tag error messages as systemd error messages when the messages are
> not directed to the terminal.
> 
> Signed-off-by: Jouke Witteveen <j.witteveen at gmail.com>
> ---
>  src/lib/globals | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/src/lib/globals b/src/lib/globals
> index a2a281f..66f3cee 100644
> --- a/src/lib/globals
> +++ b/src/lib/globals
> @@ -15,7 +15,11 @@ report_notice() {
>  }
>  
>  report_error() {
> -    echo "$*"
> +    echo "$*" | if [[ -t 2 ]]; then
> +        (tput bold; tput setaf 1; cat; tput sgr0) >&2

Useless subshell. { cmd; cmd; } >&2 is what you want.

> +    else
> +        systemd-cat -t "$(basename "$0")" -p err

I don't really understand the need for this. If stderr isn't a
terminal, isn't it reasonable to assume that this is being called by the
daemon (which was already started by systemd?) You can just log to
stderr and it'll be collected by the journal. Morever, logging in this
manner will explicitly disconnect them from the daemon. The -t flag for
systemd-cat just adds a SYSLOG_IDENTIFIER field. You can never find
these messages with a _SYSTEMD_UNIT filter despite them having what
*appears* to be a relationship to the caller.

> +    fi
>  }
>  
>  report_debug() {
> @@ -23,7 +27,7 @@ report_debug() {
>  }
>  
>  exit_error() {
> -    report_error "$@" >&2
> +    report_error "$@"
>      exit 1
>  }
>  
> -- 
> 1.8.4.1
> 


More information about the arch-projects mailing list