有没有办法更改pkg的日志记录位置?

时间:2016-05-11 20:25:08

标签: macos logging installer pkgbuild productbuild

我正在使用pkgbuildproductbuild构建安装程序。我希望能够在出现任何问题时从我的用户那里收集安装日志。如果这些日志没有与他们安装的其他东西混合在一起,那就太好了。

默认情况下,所有日志都显示为/var/logs/install.log。有没有办法为我的应用程序的安装程序日志更改此位置?

2 个答案:

答案 0 :(得分:0)

在MAC OS X上以平面文件格式(.pkg)安装应用程序的方法有两种:

GUI

Installer.app(在El Capitan上,它位于/System/Library/CoreServices/Installer.app中)是GUI安装程序方法,它似乎没有任何选项来更改日志,但它确实有视图日志选项(Command+L

命令行

installer是具有-dumplog的命令行,可用于将日志转储到可以重定向到文件的stdout。

 -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.

命令

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

答案 1 :(得分:0)

我最后通过在postinstall脚本的末尾添加以下函数来解决这个问题。它检测与当前安装相关的第一行install.log,并将该行的所有内容复制到install.log的末尾,并将其复制到单独的文件中。

一个警告:如果同时发生多个安装,则可以将其他安装中的日志混入。此解决方案只捕获install.log的有时间限制的快照,但不会将日志与多个安装分开。

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"
}