xcode Cocoapods:关闭 MagicalRecord 日志
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15284067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cocoapods: turning MagicalRecord logging off
提问by Andres Kievsky
Turning MagicalRecord logging off requires a #define to be made before it is first included in the project, but in the case of a project managed by Cocoapods I have no access to add a #define in the Pods project. How do I turn logging off completely in this scenario?
关闭 MagicalRecord 日志需要在它首次包含在项目中之前进行 #define,但对于由 Cocoapods 管理的项目,我无权在 Pods 项目中添加 #define。在这种情况下如何完全关闭注销?
Took me a few hours to figure out a way to do it, posting here in the hope it will help others.
我花了几个小时才想出一种方法来做到这一点,在这里张贴希望它能帮助别人。
EDIT: this is not a duplicate as it discusses turning logging off under Cocoapods
编辑:这不是重复的,因为它讨论了在 Cocoapods 下关闭注销
回答by Andres Kievsky
You can use a post_install hook to modify pretty much any build setting. Just add this code to your Podfile:
您可以使用 post_install 挂钩来修改几乎任何构建设置。只需将此代码添加到您的 Podfile 中:
post_install do |installer|
target = installer.project.targets.find{|t| t.to_s == "Pods-MagicalRecord"}
target.build_configurations.each do |config|
s = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
s = [ '$(inherited)' ] if s == nil;
s.push('MR_ENABLE_ACTIVE_RECORD_LOGGING=0') if config.to_s == "Debug";
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s
end
end
Note that this will only disable logging in the debugconfiguration - logging is disabled by default in the releaseconfiguration.
请注意,这只会在调试配置中禁用日志记录- 默认情况下在发布配置中禁用日志记录。
回答by Cody A. Ray
In my case, I was building a library that depended on MagicalRecord. I didn't want my users to have to add a post_install in their Podfile to silence the noisy logging, so I added it to my podspec instead.
就我而言,我正在构建一个依赖于 MagicalRecord 的库。我不希望我的用户必须在他们的 Podfile 中添加 post_install 来消除嘈杂的日志记录,所以我将它添加到我的 podspec 中。
s.prefix_header_contents = '#define MR_ENABLE_ACTIVE_RECORD_LOGGING 0'
This automatically adds this #define
statement to Pods-prefix.pch, which silences MagicalRecord logging in projects that use my pod.
这会自动将此#define
语句添加到 Pods-prefix.pch,从而使使用我的 Pod 的项目中的 MagicalRecord 日志静音。
回答by Ivan Bruel
I updated ank's answer for those using the new cocoapods version alongside MagicalRecord 2.3.0:
我为那些使用新 cocoapods 版本和 MagicalRecord 2.3.0 的人更新了 ank 的答案:
post_install do |installer|
target = installer.pods_project.targets.find{|t| t.to_s == "MagicalRecord"}
target.build_configurations.each do |config|
s = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
s = [ '$(inherited)' ] if s == nil;
s.push('MR_LOGGING_DISABLED=1') if config.to_s == "Debug";
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s
end
end
Changes:
变化:
project
renamed topods_project
- Target
Pods-MagicalRecord
renamed toMagicalRecord
- Macro
MR_ENABLE_ACTIVE_RECORD_LOGGING
renamed toMR_LOGGING_DISABLED
and value changed from0
to1
project
重命名为pods_project
- 目标
Pods-MagicalRecord
重命名为MagicalRecord
- 宏
MR_ENABLE_ACTIVE_RECORD_LOGGING
重命名为MR_LOGGING_DISABLED
,值从 更改0
为1
回答by user3060339
You can switch off logging in Pod project!
您可以关闭 Pod 项目的登录!
Simply add Preprocessor Macros:
只需添加预处理器宏:
Just go into "Pods" (!!!) project.
Then find out Pods-MagicalRecord target.
Choose "Build Settings" tab
Find "Apple LLVM 6.1 Preprocessing" -> "Processor Macros"
Rollout "Processor Macros" and add to "Debug" schema: "MR_ENABLE_ACTIVE_RECORD_LOGGING=0"
只需进入“Pods”(!!!)项目。
然后找出 Pods-MagicalRecord 目标。
选择“构建设置”选项卡
找到“Apple LLVM 6.1 预处理”->“处理器宏”
推出“处理器宏”并添加到“调试”模式:“MR_ENABLE_ACTIVE_RECORD_LOGGING=0”
It`s all!
都是!
回答by blackjacx
For the development branch (version 2.3.0 and higher) of Magical Record logging seems to still not work correctly. When imported like this: pod 'MagicalRecord', :git => 'https://github.com/magicalpanda/MagicalRecord', :branch => 'develop'
对于开发分支(版本 2.3.0 及更高版本)的 Magical Record 日志记录似乎仍然无法正常工作。当这样导入时: pod 'MagicalRecord', :git => ' https://github.com/magicalpanda/MagicalRecord', :branch => 'develop'
I have no logging output on my Xcode console. But I altered the post_install script of the Cocoapod. The following should enable logging: https://gist.github.com/Blackjacx/e5f3d62d611ce435775e
我的 Xcode 控制台上没有日志输出。但是我修改了 Cocoapod 的 post_install 脚本。以下应该启用日志记录:https: //gist.github.com/Blackjacx/e5f3d62d611ce435775e
With that buildsetting included in GCC_PREPROCESSOR_DEFINITIONS logging of Magical Record can be controlled in 2.3.0++ by using [MagicalRecord setLoggingLevel:]
使用包含在 GCC_PREPROCESSOR_DEFINITIONS 日志记录中的构建设置,可以在 2.3.0++ 中使用 [MagicalRecord setLoggingLevel:] 进行控制