On Wed, Oct 23, 2013 at 5:13 PM, Dave Reisner <d@falconindy.com> wrote:
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@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.
Indeed, that's what was meant.
+ 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.
Unfortunately, systemd does not classify output on stderr as errors. As a result, netctl errors are not formatted as such in the journal. Many problems people seem to be having with netctl are related to their inability to correctly parse the journal. I hoped to give some more guidance this way. Are there other ways to add the error identifier?
+ fi }
report_debug() { @@ -23,7 +27,7 @@ report_debug() { }
exit_error() { - report_error "$@" >&2 + report_error "$@" exit 1 }
-- 1.8.4.1