#!/bin/sh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/bin/cdat/helpers/mlog.sh 1.2 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2010,2011 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)89    1.2  src/bos/usr/bin/cdat/helpers/mlog.sh, cdat, bos720 7/14/11 19:56:24
#
# Framework helper to log messages from collect scripts.
#

# Check usage
[ $# -lt 2 ] && {
    echo "Usage: mlog Level String ..." 1>&2
    exit 1
}

# Check environment
[ -z "$CDAT_DEST_DIR" ] && {
    echo "Bad environment" 1>&2
    exit 1
}

level=$1
shift

if [ $level -lt 0 ]; then
    # Message goes to stderr and errors.txt
    echo "$*" | tee -a "$CDAT_DEST_DIR/errors.txt" 1>&2
else
    # Message goes to stderr
    echo "$*" 1>&2
fi
