Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash - logging #93

Open
4 tasks
Notgnoshi opened this issue Aug 31, 2021 · 0 comments
Open
4 tasks

bash - logging #93

Notgnoshi opened this issue Aug 31, 2021 · 0 comments
Labels
bash new content New content to add to the site

Comments

@Notgnoshi
Copy link
Owner

Notgnoshi commented Aug 31, 2021


#!/bin/bash
function trace()
{
    logger -s "TRACE ${BASH_SOURCE[1]}:${BASH_LINENO[0]}:${FUNCNAME[1]}: $BASH_COMMAND"
}
set -o functrace
shopt -s extdebug
trap trace DEBUG

# dump set -x data to a file
# turns on with a filename as $1
# turns off with no params
# note that FD 4 should not be used elsewhere in the script
setx_output()
{
    if [[ $1 ]]; then
        exec 4>>"$1"
        BASH_XTRACEFD=4
        set -x
    else
        set +x
        exec 4>&-
    fi
}
@Notgnoshi Notgnoshi added new content New content to add to the site bash labels Aug 31, 2021
@Notgnoshi Notgnoshi changed the title bash - xtrace style logging to a file bash - logging Nov 21, 2021
@Notgnoshi Notgnoshi moved this to New Posts in Website Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bash new content New content to add to the site
Projects
Status: New Posts
Development

No branches or pull requests

1 participant