client9/shlib

logging functionality

開放

#10 建立於 2018年3月8日

 (0 則留言) (0 個反應) (0 位負責人)Shell (40 個分叉)github user discovery
enhancementhelp wanted

倉庫指標

星標
 (430 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Much of the code uses echo as way of returning results or a partial result in a pipe.

Other times echo is used as a logging mechanism, and inconsistently.

Here are two examples of the later:

uname_os_check.sh:  echo "$0: uname_os_check: internal error '$(uname -s)' got converted to '$os' which is not a GOOS value. Please file bug at https://github.com/client9/shlib"
untar.sh:      echo "Unknown archive format for ${tarball}"

Both also go to stdout, not stderr.

Better would be to have a function that does logging.

Thinking

log_error
log_info
log_debug
log_prefix 

The last one would be a function that would emit a common prefix. A function so smart people could completely over-ride it and add a date or whatever, but by default it would be:

log_prefix() {
  echo $0  or nothing ""
}

Also need some way of setting the level. Will need to see what syslog and friends do.

n

貢獻者指南