Skip to content

Instantly share code, notes, and snippets.

@reikind
Created January 17, 2013 13:51

Revisions

  1. reikind created this gist Jan 17, 2013.
    56 changes: 56 additions & 0 deletions show_log.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    #!/bin/bash

    usage() {

    cat << EOT
    usage $0 [OPTIONS]
    OPTIONS
    -h show this usage
    -q not show log message (without error message)
    EOT
    }

    # if it is not empty, does not show log
    QUIET=

    ## log function ##
    log() {
    test -z "$QUIET" && echo "$*"
    }

    debug() {
    log "DEBUG $*"
    }

    info() {
    log "INFO $*"
    }

    warn() {
    log "WARN $*"
    }

    err() {
    # output to STDERR
    echo "ERR $*" 1>&2
    }

    while getopts "hq" option; do
    case $option in
    q)
    QUIET=1
    ;;
    \?)
    echo "wrong option."
    usage
    exit 1
    ;;
    h)
    usage
    exit 0
    ;;
    esac
    done
    shift $(($OPTIND - 1))