summaryrefslogtreecommitdiff
path: root/lib/log.sh
blob: 8a0c611d849b5ec35048e5cd0a73cab8f5aff289 (plain) (blame)
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
function log() {
	local log_level=0
	local log_level_string=""

	case $1 in
		debug)
			log_level=0
			log_level_string="[DBG]"
			;;
		verbose)
			log_level=1
			log_level_string="[VRB]"
			;;
		info)
			log_level=2
			log_level_string="[INF]"
			;;
		warn)
			log_level=3
			log_level_string="[WRN]"
			;;
		error)
			log_level=4
			log_level_string="[ERR]"
			;;
	esac
	shift

	# set the log level to info if unset
	[[ -z "DOT_LOG_LEVEL" ]] && DOT_LOG_LEVEL=2

	# if this is too verbose, stop now
	[[ "$DOT_LOG_LEVEL" -gt "$level" ]] && return

	[[ -n "$_modulename" ]] && module="[$_modulename]: " || module=""
	[[ -n "$DOT_MODULE_NAME" ]] && module="[$DOT_MODULE_NAME]: "

	echo "$log_level_string $module$@"
}