Skip to content

Commit e570b32

Browse files
authored
Add function to echo to stderr (#41)
1 parent 607e5f5 commit e570b32

File tree

1 file changed

+6
-1
lines changed
  • modules/bash-commons/src

1 file changed

+6
-1
lines changed

modules/bash-commons/src/log.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
#!/usr/bin/env bash
22

3+
# Echo to stderr. Useful for printing script usage information.
4+
function echo_stderr {
5+
>&2 echo "$@"
6+
}
7+
38
# Log the given message at the given level. All logs are written to stderr with a timestamp.
49
function log {
510
local -r level="$1"
611
local -r message="$2"
712
local -r timestamp=$(date +"%Y-%m-%d %H:%M:%S")
813
local -r script_name="$(basename "$0")"
9-
>&2 echo -e "${timestamp} [${level}] [$script_name] ${message}"
14+
echo_stderr -e "${timestamp} [${level}] [$script_name] ${message}"
1015
}
1116

1217
# Log the given message at INFO level. All logs are written to stderr with a timestamp.

0 commit comments

Comments
 (0)