summaryrefslogtreecommitdiff
path: root/include/logger.sh
blob: b8806e1c09c54371d268bb54a5afa91a39cc62bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash

function logger
{
    local logfile="$1"
    if [[ $logfile != *.log ]]; then
        echo "logger: log file is missing .log prefix, '$logfile'"
        exit 1
    fi

    shift

    # Bash magic: return this exit value for the first pipe command
    echo "Writing log: $logfile"
    set -o pipefail
    "$@" 2>&1 | tee $logfile
    retval=$?
    set +o pipefail

    return $retval
}