-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple.sh
More file actions
executable file
·44 lines (34 loc) · 1.53 KB
/
Copy pathsimple.sh
File metadata and controls
executable file
·44 lines (34 loc) · 1.53 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
#!/bin/sh
# shellcheck disable=SC2034
set -eu
# You can copy and paste the sixlogger function directly in your script
# or source it from another file
script_dir="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
# shellcheck disable=SC1091
. "${script_dir}/../src/sixlogger.sh"
# You can alias the `sixlogger` function to a shorter name if you want:
# alias log=sixlogger
# log info "Hello world"
sixlogger info "Info message"
sixlogger warn "Warn message"
sixlogger error "Error messages go to 'stderr'"
sixlogger fatal "Fatal messages also go to 'stderr'"
sixlogger debug "You won't be able to see this message!"
# Showing debug messages
SIXLOGGER_DEBUG=true # or set `DEBUG=true`
sixlogger debug "This is a debug message ;)"
# Or change the default color for a specific loglevel
sixlogger warn "Default color for 'warn' is yellow"
SIXLOGGER_COLOR_WARN='\033[1;36m' # Cyan
sixlogger warn "Changed color!"
# You can also disable the colored text output
SIXLOGGER_NO_COLOR=true # or set `NO_COLOR=true` (https://no-color.org/)
sixlogger info "Non-colored..."
sixlogger fatal "...text output"
SIXLOGGER_NO_COLOR=false
# Be careful, the `sixlogger` function exits with an error if loglevel is unknown
sixlogger asdf "This message will be discarded" || last_command_status_code="$?" # preventing script from exiting
sixlogger error "Last command exited with status code '${last_command_status_code}'"
# We can disable that behaviour by setting `E_SIXLOGGER_UNKNOWN_LOGLEVEL=0`
E_SIXLOGGER_UNKNOWN_LOGLEVEL=0
sixlogger asdf "The message will still be discarded..."