forked from deanrather/bash-logger
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexamples.sh
More file actions
executable file
·65 lines (56 loc) · 1.9 KB
/
examples.sh
File metadata and controls
executable file
·65 lines (56 loc) · 1.9 KB
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
#!/bin/bash
#--------------------------------------------------------------------------------------------------
# Bash Logger
# Copyright (c) Dean Rather
# Licensed under the MIT license
# https://github.com/deanrather/bash-logger
#--------------------------------------------------------------------------------------------------
# Including the logger functions
source bash-logger.sh
# Regular Usage
INFO "Info log with default configurations"
DEBUG "Debug log with default configurations"
# Overwriting default configurables
echo # newline
export LOGFILE=~/my-bash-logger.log
export LOG_DATE_FORMAT='+%c'
export LOG_FORMAT='%LEVEL %DATE -- %MESSAGE'
NOTICE "Configurations changed"
DEBUG "example debug log"
NOTICE "example notice log"
WARNING "example warning log"
# re-source to overwrite config changes
echo
source bash-logger.sh
NOTICE "Configurations Reset"
DEBUG "example debug log"
NOTICE "example notice log"
WARNING "example warning log"
# Overwriting log function behavior (eg. don't exit on errors)
echo # newline
INFO "Changing default log behavior"
ERROR() { LOG_HANDLER_DEFAULT "$FUNCNAME" "$@"; }
CRITICAL() { LOG_HANDLER_DEFAULT "$FUNCNAME" "$@"; }
ALERT() { LOG_HANDLER_DEFAULT "$FUNCNAME" "$@"; }
EMERGENCY() { LOG_HANDLER_DEFAULT "$FUNCNAME" "$@"; }
NOTICE "default logging behavior overwritten"
# Example of all log levels
echo # newline
DEBUG "Example Debug log"
INFO "Example Info log"
NOTICE "Example Notice log"
WARNING "Example Warning log"
ERROR "Example Error log"
CRITICAL "Example Critical log"
ALERT "Example Alert log"
EMERGENCY "Example Emergency log"
# Overwriting default log behavior (eg. adding another echo)
echo # newline
INFO "Adding additional default behavior"
LOG_HANDLER_DEFAULT() {
local formatted_log="$(FORMAT_LOG "$@")"
LOG_HANDLER_COLORTERM "$1" "$formatted_log"
LOG_HANDLER_LOGFILE "$1" "$formatted_log"
echo "logged to logfile"
}
NOTICE "test notice log"