Not sure what to think about this new system.
"The unified logging system stores messages in memory and in a data store, rather than writing to text-based log files."
We've been using tee
to output to /Library/Logs
, so we get display and output to a file:
# echo $(date) | tee /Library/Logs/date.log
Fri Feb 3 03:18:55 PST 2017
# cat /Library/Logs/date.log
Fri Feb 3 03:18:55 PST 2017
Easier than fishing for something that Apple is making tougher to find.
https://en.wikipedia.org/wiki/Tee_(command)
@c.kay We write everything to our own client-side log, which we then upload to the JSS via the API as needed.
Here's a snippet from our "functions.sh" which we write client-side (i.e., /path/to/client-side/functions.sh) and is then source
'd in all our other scripts:
#!/bin/sh
####################################################################################################
#
# LOGGING
#
####################################################################################################
# Variables
logFile="/var/log/com.company.division.log"
# Check for / create logFile
if [ ! -f "${logFile}" ]; then
# logFile not found; Create logFile
/usr/bin/touch "${logFile}"
fi
function ScriptLog() { # Re-direct logging to the log file ...
exec 3>&1 4>&2 # Save standard output and standard error
exec 1>>"${logFile}" # Redirect standard output to logFile
exec 2>>"${logFile}" # Redirect standard error to logFile
NOW=`date +%Y-%m-%d %H:%M:%S`
/bin/echo "${NOW}" " ${1}" >> ${logFile}
}
function jssLog() { # Re-direct logging to the JSS
ScriptLog "${1}"
exec 1>&3 2>&4
/bin/echo >&1 ${1}
}
Then, in all our other scripts we include …
source /path/to/client-side/functions.sh
… and …
ScriptLog "Comment to write to client-side log goes inside these quotes"
… and / or …
jssLog "Comment to write back to the JSS script results goes inside these quotes"
Clear as mud?