#!/bin/bash

showHelp=0

valApp="$0"
valLid="0"
valFacility="user"
valSeverity="info"
valMsg="-"

while [ "$1" != "" ]; do
	case "$1" in
	  -h | --help | --usage)
		showHelp="1"
		;;
	  -n | --process-name)
		shift
		valApp="$1"
		;;
	  -i | --process-id)
		shift
		valLid="$1"
		;;
	  -f | --facility-level)
		shift
		valFacility="$1"
		;;
	  -s | --severity-level)
		shift
		valSeverity="$1"
		;;
	  -o | --options)
		shift
		valApp="$1"
		shift
		valFacility="$1"
		shift
		valSeverity="$1"
		;;
	  *)
		valMsg="$1"
		;;
	esac
	shift
done

if [ "$showHelp" == "1" ]; then
	echo "Usage: logit [OPTIONS <values>] MESSAGE"
	echo "       lecho [OPTIONS <values>] MESSAGE"
	echo "Put message into log file, syslog, stdout, etc., as is conditioned in conf file."
	echo " "
	echo "Common options:"
	echo "  -n <val>, --process-name <val>"
	echo "     Name of process/script/application from which is LogIt called."
	echo "  -i <val>, --process-id <val>"
	echo "     If several instances of process are running, log messages can be tagged"
	echo "     with numerical ID for better tracing."
	echo "  -f <val>, --facility-level <val>"
	echo "     Keyword of facility level. Available facility levels are included in table"
	echo "     below."
	echo "  -s <val>, --severity-level <val>"
	echo "     Keyword of severity level. Available severity levels are included in table"
	echo "     below."
	echo "  -o <val1> <val2> <val3>, --options <val1> <val2> <val3>"
	echo "     Shortcut for -n, -f and -s options. Command 'lecho -o app user debug Hello'"
	echo "     is identical with 'lecho -n app -f user -s debug Hello'."
	echo " "
	echo "General options:"
	echo "  -h, --help, --usage"
	echo "     This help."
	echo " "
	echo " ===============================  ==============================="
	echo " | Facility levels:            |  | Severity levels:            |"
	echo " |=============================|  |=============================|"
	echo " | No.: | Level keyword:       |  | Code: | Level keyword:      |"
	echo " |------|----------------------|  |-------|---------------------|"
	echo " |    0 | kern                 |  |     0 | emerg               |"
	echo " |    1 | user                 |  |     1 | alert               |"
	echo " |    3 | daemon               |  |     2 | crit                |"
	echo " |    4 | auth                 |  |     3 | err                 |"
	echo " |   10 | authpriv             |  |     4 | warning             |"
	echo " |   15 | cron                 |  |     5 | notice              |"
	echo " ===============================  |     6 | info                |"
	echo "                                  |     7 | debug               |"
	echo "                                  ==============================="
	echo " "
	echo "(c) 2014 LUnet Studio, http://LUnet.Studio"
	exit
fi


python3 /opt/logit/inc/logit.pyc "$valApp" "$valLid" "$valFacility" "$valSeverity" "$valMsg"
