]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Adding possibility for logging messages
authorFrank Brehm <frank@brehm-online.com>
Tue, 2 Feb 2021 08:13:59 +0000 (09:13 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 2 Feb 2021 08:16:19 +0000 (09:16 +0100)
bin/start-openfortivpn
lib/functions.rc

index eaf4a56bf33f7f5e5b69340557b75772cdbd5ddc..5e762afd58a4be788de0e5630fd8526836962639 100755 (executable)
@@ -88,6 +88,8 @@ get_options() {
 
     check_for_root
 
+    LOGFILE="/var/log/$( basename $0 ).log"
+
 }
 
 #------------------------------------------------------------------------------
index 536c692ee2ca384872860572e999f2f40bdb6709..38e4ab3d8d4e2723d6035b1c7f31ab02d79595b8 100644 (file)
@@ -10,7 +10,7 @@ BLUE=""
 CYAN=""
 NORMAL=""
 
-VERSION="0.3.8"
+VERSION="0.3.9"
 
 STD_SHORT_OPTIONS="sdvhV"
 STD_LONG_OPTIONS="simulate,debug,verbose,nocolor,help,version"
@@ -30,6 +30,8 @@ DEBUG="n"
 DO_ASK="n"
 SIMULATE="n"
 
+LOGFILE=
+
 declare -a REMAINING_ARGS=()
 declare -a REMAINING_OPTS=()
 
@@ -266,22 +268,38 @@ debug() {
     if [[ "${VERBOSE}" != "y" ]] ; then
         return 0
     fi
-    echo -e " * [$(my_date)] [${BASE_NAME}:${CYAN}DEBUG${NORMAL}]: $@" >&2
+    local ts=$(my_date)
+    if [[ -n "${LOGFILE}" ]] ; then
+        echo "[${ts}] [${BASE_NAME}DEBUG]: $@" >>"${LOGFILE}"
+    fi
+    echo -e " * [${ts}] [${BASE_NAME}:${CYAN}DEBUG${NORMAL}]: $@" >&2
 }
 
 #------------------------------------------------------------------------------
 info() {
-    echo -e " ${GREEN}*${NORMAL} [$(my_date)] [${BASE_NAME}:${GREEN}INFO${NORMAL}] : $@" >&2
+    local ts=$(my_date)
+    if [[ -n "${LOGFILE}" ]] ; then
+        echo "[${ts}] [${BASE_NAME}INFO] : $@" >>"${LOGFILE}"
+    fi
+    echo -e " ${GREEN}*${NORMAL} [${ts}] [${BASE_NAME}:${GREEN}INFO${NORMAL}] : $@" >&2
 }
 
 #------------------------------------------------------------------------------
 warn() {
-    echo -e " ${YELLOW}*${NORMAL} [$(my_date)] [${BASE_NAME}:${YELLOW}WARN${NORMAL}] : $@" >&2
+    local ts=$(my_date)
+    if [[ -n "${LOGFILE}" ]] ; then
+        echo "[${ts}] [${BASE_NAME}WARN] : $@" >>"${LOGFILE}"
+    fi
+    echo -e " ${YELLOW}*${NORMAL} [${ts}] [${BASE_NAME}:${YELLOW}WARN${NORMAL}] : $@" >&2
 }
 
 #------------------------------------------------------------------------------
 error() {
-    echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASE_NAME}:${RED}ERROR${NORMAL}]: $@" >&2
+    local ts=$(my_date)
+    if [[ -n "${LOGFILE}" ]] ; then
+        echo "[${ts}] [${BASE_NAME}ERROR]: $@" >>"${LOGFILE}"
+    fi
+    echo -e " ${RED}*${NORMAL} [${ts}] [${BASE_NAME}:${RED}ERROR${NORMAL}]: $@" >&2
 }
 
 #------------------------------------------------------------------------------