1

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

默认情况下,看起来所有日志都转到/var/logs/install.log. 有什么方法可以更改我的应用程序安装程序日志的这个位置吗?

4

2 回答 2

0

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

图形用户界面

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

命令行

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

 -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

于 2016-05-12T04:05:23.503 回答
0

我最终通过在我的安装后脚本末尾添加以下函数来解决这个问题。它检测与当前安装相关的 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"
}
于 2016-06-22T16:12:41.947 回答