-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyslog.lib.sh
executable file
·68 lines (58 loc) · 1.8 KB
/
syslog.lib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
################################################################################
# syslog.lib.sh - Bash library functions related to syslog
################################################################################
#
# Copyright (C) 2013 stepping stone GmbH
# Bern, Switzerland
# http://www.stepping-stone.ch
#
# Authors:
# Christian Affolter <[email protected]>
#
# Licensed under the EUPL, Version 1.1.
#
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://www.osor.eu/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
################################################################################
# The path to the lib directory.
# The default value only works if not sourced or executed from within $PATH
LIB_DIR=${LIB_DIR:="$(readlink -f ${0%/*})"}
LOGGER_CMD="${LOGGER_CMD:="/usr/bin/logger"}"
if ! test -x "${LOGGER_CMD}"; then
LOGGER_CMD="/bin/logger"
if ! test -x "${LOGGER_CMD}"; then
echo "Missing logger command: '${LOGGER_CMD}'" >&2
exit 1
fi
fi
function syslog ()
{
local message="$1"
local tag="$2"
local level="$3"
local facility="$4"
if [ -z "$tag" ]; then
tag="$0" # default to script name
fi
if [ -z "$level" ]; then
level='info'
fi
if [ -z "${facility}" ]; then
facility='user'
fi
${LOGGER_CMD} -t "${tag}" -p "${facility}.${level}" "$message"
}