# read messages from arguments or from stdin

msg() {
  local src="$1" type="$2"
  shift 2
  if [ "$type" = "info" -a $verbose -eq 0 -o \
       "$type" = "debug" -a "${dsrc/$src}" != "${dsrc}" -o \
       "$type" = "warning" -o "$type" = "error" ]; then
    :
  else
    return
  fi

  local ts=`date "+%Y%m%d-%T"`

  if [ -n "$1" ]; then
    # take message from $@
    put_msg "$src" "$type" "$ts" "$@"
  else
    # read messages from stdin
    local line
    while read line; do
      put_msg "$src" "$type" "$ts" "$line"
    done
  fi
}

# print message to stderr

put_msg() {
  local src="$1" type="$2" ts="$3"
  shift 3
  echo -e "[$ts] [$type] [$src] $@" >&2
}