如何激活OS X 10.6上的launchd日志logging?
我添加了一个不正常启动的新守护进程(状态为1
)。
我想debugging的问题,但我无法findlaunchd
日志,他们不在/var/log/launchd.log
。
我find了解决scheme
sudo launchctl log level debug
之后
tail -f /var/log/system.log
假设你正在尝试logging你的进程而不是自己启动,如果你在启动的plist文件中包含以下几行:
<key>StandardOutPath</key> <string>/path/to/logfile.log</string> <key>StandardErrorPath</key> <string>/path/to/another_logfile.log</string>
并重新加载进程,则脚本内部的任何日志logging或打印都将在运行时捕获到这两个文件中的一个中。 虽然旋转文件似乎取决于你。 正如你所期望的那样,如果你在两个实例中都使用相同的文件,它将把错误和stdoutlogging到同一个地方。
在OS X 10.11(El Capitan)上,如果您不想使用@peterbuild议的文件系统选项,则可以使用sudo launchctl debug <service-target> --stdout --stderr
启用一次性日志logging。
在当前的launchctl
实现中有许多东西是不同的, <service-target>
launchctl
。 例如,假设我在~/Library/LaunchAgents/dev.localmon.plist
configuration了一个本地服务,该服务具有“label” dev.localmon
。 它的<service-target>
是gui/$UID/dev.localmon
,其中$UID
是你的用户ID,由于你在CLI上运行这个ID,你的shell将为你插入。
因此,假设我的dev.localmon
服务在启动时崩溃了,我可以调用以下命令让launchctl
在下次启动服务时将进程的stdout和stderr launchctl
到我的shell中:
sudo launchctl debug gui/$UID/dev.localmon --stdout --stderr
因为这个打开和准备好的TTY挂起,去另一个terminal并运行:
launchctl start dev.localmon # start is a legacy command and doesn't use the fancy new service-target notation
然后,回到第一个terminal,你应该看到输出。 (奇怪的是,当服务进程死亡时,它不closures,所以你必须按Ctrl-C。)
顺便说一句,一旦你修复你的configuration文件与任何path或环境之前打破了服务,你仍然必须使用旧的launchctl unload ~/Library/LaunchAgents/dev.localmon.plist && launchctl load ~/Library/LaunchAgents/dev.localmon.plist
两步,因为文档的声明uncache
子命令具有以下作用:
命令尚未执行。
Yay对于苹果公司发布后的发布策略:“快速行动,打破事情”