Created
November 14, 2023 22:04
-
-
Save brunerd/fdfa35eff0d59d128f36464687dee228 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# jamflog - Copyright (c) 2021 Joel Bruner, Licensed under the MIT License | |
# a way to log to stdout and /var/log/jamf.log (or elsewhere) and have it match Jamf's log style | |
function jamflog(){ | |
[ -n "${-//[^x]/}" ] && { local xTrace=1; set +x; } &>/dev/null | |
local logFile="${2:-/var/log/jamf.log}" | |
#if it exists but we cannot write to the log or it does not exist, unset and tee simply echoes | |
[ -e "${logFile}" -a ! -w "${logFile}" ] && unset logFile | |
#this will tee to jamf.log in the jamf log format: <Day> <Month> DD HH:MM:SS <Computer Name> ProcessName[PID]: <Message> | |
builtin echo "$(/bin/date +'%a %b %d %H:%M:%S') ${jamflog_myComputerName:="$(/usr/sbin/scutil --get ComputerName)"} ${jamflog_myName:="$(/usr/bin/basename "${0%.*}")"}[${myPID:=$$}]: ${1}" | /usr/bin/tee -a "${logFile}" 2>/dev/null | |
[ "${xTrace:-0}" = 1 ] && { set -x; } &>/dev/null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment