Is there a way to change the logging location of a pkg?

3.1k Views Asked by At

I'm building an installer using pkgbuild and productbuild. I'd like to be able to collect the install logs from my users in the case that anything goes wrong. It'd be nice if those logs were not mixed in with everything else they've installed.

By default it looks like all logs go to /var/logs/install.log. Is there any way to change this location for my app's installer logs?

2

There are 2 best solutions below

0
On BEST ANSWER

I ended up solving this by adding the following function to the end of my postinstall script. It detects the first line of install.log that's relevant to the current installation, and copies everything from that line to the end of install.log into a separate file.

One caveat: if multiple installations are happening simultaneously, it's possible to get logs from the other installation mixed in. This solution simply captures a time-bounded snapshot of install.log, but doesn't separate the logs from multiple installations.

function export_log {
    NOW=`date "+%Y-%m-%d-%H-%M-%S"`
    LOG_NAME="install_log_$NOW.log"

    # Interactive install logs start with a line "<AppName> x.x.x Installation Log". Silent install logs start with a line 
    # "Product archive /path/to/pkg/folder".

    # Must include something like \d in this expression and the pkg filename, that won't match this line itself when it's printed in the log
    STARTING_LINE_OF_LAST_INSTALL=`egrep '(<AppName> \d+\.\d+\.\d+ Installation Log)|(Product archive.*path/to/pkg/folder/\d+.\d+\.\d+/)' /var/log/install.log | tail -n 1`

    # Copy the rest of the log from that line on, up to 10000 lines.
    fgrep --after-context=10000 "$STARTING_LINE_OF_LAST_INSTALL" /var/log/install.log > "$LOGGING_DIR/$LOG_NAME"
}
1
On

There are two ways of installing apps in flat file format (.pkg) on MAC OS X:

GUI

Installer.app (On El Capitan it is located in /System/Library/CoreServices/Installer.app) is GUI installer method which doesn't seem to have any option to change the logs but it does have view logs option (Command+L)

Command Line

installer is command line that has -dumplog that can be used to dump logs to stdout that can be redirected to a file.

 -dumplog
         Detailed log information is always sent to syslog using the LOG_INSTALL facility (and will wind up in /var/log/install.log).  -dumplog additionally writes this log to
         standard error output.

Command

installer -dumplog -pkg InstallMe.pkg -target / > install.log 2>&1