function log {
    if [ -z "$LOGFILE" ]; then
	return
    fi

    local date=`date "+%Y-%m-%d %H:%M:%S"`

    mkdir -p `dirname $LOGFILE` &>/dev/null
    if [ "$1" = "-n" ]; then
	echo -n $2
	echo -n $2 >>$LOGFILE
	return
    fi
    if [ "$1" = "-emptylinetologfile" ]; then
	if [ -s "$LOGFILE" ]; then
	    echo >>$LOGFILE
	fi
	return
    fi
    if [ "$1" = "-start" ]; then
        echo -n "$date | $2"
	echo -n "$date | $2" >>$LOGFILE
	return
    fi
    if [ "$1" = "-done" ]; then
	echo "done"
	echo "done" >>$LOGFILE
	return
    fi
    if [ "$1" = "" ]; then
	echo
	echo >>$LOGFILE
	return
    fi
    echo "$date | $1"
    echo "$date | $1" >>$LOGFILE
}
