简体   繁体   English

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

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

I'm building an installer using pkgbuild and productbuild . 我正在使用pkgbuildproductbuild构建安装程序。 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 . 默认情况下,所有日志都显示为/var/logs/install.log Is there any way to change this location for my app's installer logs? 有没有办法为我的应用程序的安装程序日志更改此位置?

There are two ways of installing apps in flat file format ( .pkg ) on MAC OS X: 在MAC OS X上有两种以平面文件格式( .pkg )安装应用程序的方法:

GUI 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 ) Installer.app (在El Capitan上它位于/System/Library/CoreServices/Installer.app)是GUI安装程序方法,它似乎没有任何选项来更改日志,但它确实有视图日志选项( 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. 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. 

Command 命令

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

I ended up solving this by adding the following function to the end of my postinstall script. 我最后通过在postinstall脚本的末尾添加以下函数来解决这个问题。 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. 它检测与当前安装相关的第一行install.log,并将该行的所有内容复制到install.log的末尾,并将其复制到单独的文件中。

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. 需要注意的是:如果同时发生多个安装,则可以将其他安装中的日志混入。此解决方案只捕获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"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM