【问题标题】:Is there a way to change the logging location of a pkg?有没有办法更改 pkg 的日志记录位置?
【发布时间】:2016-05-11 20:25:07
【问题描述】:

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

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

【问题讨论】:

  • 无法更改位置,因为它会记录系统上的所有安装任务。您可以创建一个 preinstall/postinstall 脚本来解析它以将您的安装日志也写入特定位置。

标签: macos logging installation pkgbuild productbuild


【解决方案1】:

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

图形界面

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

【讨论】:

  • 感谢 NulledPointer。它并不能完全解决我的问题,因为我想要用户手动运行安装程序时的日志。另外,它似乎没有打印出安装前和安装后脚本的输出。但这是朝着正确方向迈出的一步!
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-27
    • 2012-04-13
    • 2020-06-18
    • 2016-08-24
    • 1970-01-01
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    相关资源
    最近更新 更多