当您将 OS_ACTIVITY_MODE 设置为disable
,您可以禁用有权访问此环境变量的进程(例如模拟器)的所有日志输出。
当您将该值设置为info
or debug
它启用相应的日志记录模式,除非它是disabled在某些日志类别的日志记录首选项中。
因此,为了仅启用某个日志类别,您必须enableOS_ACTIVITY_MODE,即设置为info
or debug
或者保留默认值,然后disable记录所有其他类别。
有关如何执行此操作的更多信息,请参阅日志的手册页,输入man log
在控制台中。
获取模拟器当前的日志首选项:
在控制台中输入:xcrun simctl spawn booted log config --status
这基本上意味着:申请log config -status
到所有启动的模拟器。
这可能会将以下内容打印到您的控制台:
System mode = INFO STREAM_LIVE PRIVATE_DATA
获取特定类别和子系统的状态
xcrun simctl spawn booted log config --status --subsystem com.mycompany.myapp --category network
这可能会将以下内容打印到控制台:
Mode for 'com.mycompany.myapp(network)' INFO PERSIST_DEFAULT
Get Help
如需帮助,请使用工具xcrun simctl
and log
有漂亮的手册页和帮助页。
例如:
类型log config --help
进入控制台,它打印:
usage: log config [options] --mode <modes>
or: log config [options] --status
or: log config [options] --reset
description:
Read or configure settings for the logging system. Configuration
can act system-wide; or on a subsystem, category, or process level.
options:
--category <name> Get/set settings for a given category
--mode <modes> Enable given modes
--process <pid> | <name> Get/set settings for a given process
--reset Reset settings to defaults
--status Show current settings
--subsystem <name> Get/set settings for a given subsystem
modes:
Modes can be specified as a comma-separated list of key:value pairs.
Valid keys and their values are:
level off | default | info | debug
persist off | default | info | debug
stream live | default
设置特定子系统和类别的日志级别
xcrun simctl spawn booted log config --mode "level:debug" --subsystem com.mycompany.myapp --category network
再次获取此 sybsystem 的状态,并将打印类别:
Mode for 'com.mycompany.myapp(network)' DEBUG PERSIST_DEFAULT