Skip to content

Commit

Permalink
Add function to echo to stderr (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
yorinasub17 authored Oct 22, 2021
1 parent 607e5f5 commit e570b32
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion modules/bash-commons/src/log.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#!/usr/bin/env bash

# Echo to stderr. Useful for printing script usage information.
function echo_stderr {
>&2 echo "$@"
}

# Log the given message at the given level. All logs are written to stderr with a timestamp.
function log {
local -r level="$1"
local -r message="$2"
local -r timestamp=$(date +"%Y-%m-%d %H:%M:%S")
local -r script_name="$(basename "$0")"
>&2 echo -e "${timestamp} [${level}] [$script_name] ${message}"
echo_stderr -e "${timestamp} [${level}] [$script_name] ${message}"
}

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

0 comments on commit e570b32

Please sign in to comment.