-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrace_logger.sh
More file actions
executable file
·36 lines (34 loc) · 1.19 KB
/
trace_logger.sh
File metadata and controls
executable file
·36 lines (34 loc) · 1.19 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
#!/bin/bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#
# Copyright 2015 Joyent, Inc.
#
#
# If TRACE is set in the environment, enable xtrace. Additionally,
# assuming the current shell is bash version 4.1 or later, more advanced
# tracing output will be emitted and some additional features may be used:
#
# TRACE_LOG Send xtrace output to this file instead of stderr.
# TRACE_FD Send xtrace output to this fd instead of stderr.
# The file descriptor must be open before the shell
# script is started.
#
if [[ ${TRACE:-off} != off ]]; then
if [[ ${BASH_VERSINFO[0]} -ge 4 && ${BASH_VERSINFO[1]} -ge 1 ]]; then
PS4=
PS4="${PS4}"'[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: '
PS4="${PS4}"'${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
export PS4
if [[ ${TRACE_LOG:-none} != none ]]; then
exec 4>>"${TRACE_LOG}"
export BASH_XTRACEFD=4
elif [[ ${TRACE_FD:-none} != none ]]; then
export BASH_XTRACEFD=${TRACE_FD}
fi
fi
set -o xtrace
fi