This is an automated email from the ASF dual-hosted git repository.
jianhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git
The following commit(s) were added to refs/heads/master by this push:
new d857f37 Log scan switch (#2524)
d857f37 is described below
commit d857f37123f682d15c023b657afb528fb91794b0
Author: wqyfavor <[email protected]>
AuthorDate: Tue Jun 11 10:06:38 2019 +0800
Log scan switch (#2524)
* [iOS] Support scan to redirect log to console. For release version,
original NSLog may be blocked.
* [iOS] Support scan to redirect log to console. For release version,
original NSLog/printf may be blocked.
---
ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 12 +++
ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m | 1 +
.../WeexSDK/Sources/Manager/WXComponentManager.mm | 2 +-
.../WeexSDK/Sources/Module/WXConsoleLogModule.h | 27 +++++
.../WeexSDK/Sources/Module/WXConsoleLogModule.m | 118 +++++++++++++++++++++
ios/sdk/WeexSDK/Sources/Utility/WXLog.h | 2 +
ios/sdk/WeexSDK/Sources/Utility/WXLog.m | 8 +-
7 files changed, 167 insertions(+), 3 deletions(-)
diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
index 6ad3da8..ce5cded 100644
--- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
+++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
@@ -270,6 +270,10 @@
74EF31C31DE6935600667A07 /* WXURLRewriteTests.m in Sources */ =
{isa = PBXBuildFile; fileRef = 74EF31C21DE6935600667A07 /* WXURLRewriteTests.m
*/; };
74F7BFF51DC782EC004D0871 /* testRootView.js in Resources */ =
{isa = PBXBuildFile; fileRef = 74F7BFF41DC782EC004D0871 /* testRootView.js */;
};
74FD6E041C7C0E9600DBEB6D /* WXScrollerProtocol.h in Headers */
= {isa = PBXBuildFile; fileRef = 74FD6E031C7C0E9600DBEB6D /*
WXScrollerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 7704894822AA358500E7606F /* WXConsoleLogModule.h in Headers */
= {isa = PBXBuildFile; fileRef = 7704894622AA358400E7606F /*
WXConsoleLogModule.h */; };
+ 7704894922AA358500E7606F /* WXConsoleLogModule.h in Headers */
= {isa = PBXBuildFile; fileRef = 7704894622AA358400E7606F /*
WXConsoleLogModule.h */; };
+ 7704894A22AA358500E7606F /* WXConsoleLogModule.m in Sources */
= {isa = PBXBuildFile; fileRef = 7704894722AA358400E7606F /*
WXConsoleLogModule.m */; };
+ 7704894B22AA358500E7606F /* WXConsoleLogModule.m in Sources */
= {isa = PBXBuildFile; fileRef = 7704894722AA358400E7606F /*
WXConsoleLogModule.m */; };
7715EB6221A69DD9001F1108 /* WXRichText.h in Headers */ = {isa =
PBXBuildFile; fileRef = 7715EB6021A69DD8001F1108 /* WXRichText.h */; settings =
{ATTRIBUTES = (Public, ); }; };
7715EB6321A69DD9001F1108 /* WXRichText.h in Headers */ = {isa =
PBXBuildFile; fileRef = 7715EB6021A69DD8001F1108 /* WXRichText.h */; settings =
{ATTRIBUTES = (Public, ); }; };
7715EB6421A69DD9001F1108 /* WXRichText.mm in Sources */ = {isa
= PBXBuildFile; fileRef = 7715EB6121A69DD9001F1108 /* WXRichText.mm */; };
@@ -1095,6 +1099,8 @@
74EF31C21DE6935600667A07 /* WXURLRewriteTests.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= WXURLRewriteTests.m; sourceTree = "<group>"; };
74F7BFF41DC782EC004D0871 /* testRootView.js */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript;
path = testRootView.js; sourceTree = "<group>"; };
74FD6E031C7C0E9600DBEB6D /* WXScrollerProtocol.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
WXScrollerProtocol.h; sourceTree = "<group>"; };
+ 7704894622AA358400E7606F /* WXConsoleLogModule.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
WXConsoleLogModule.h; sourceTree = "<group>"; };
+ 7704894722AA358400E7606F /* WXConsoleLogModule.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= WXConsoleLogModule.m; sourceTree = "<group>"; };
7715EB6021A69DD8001F1108 /* WXRichText.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
WXRichText.h; sourceTree = "<group>"; };
7715EB6121A69DD9001F1108 /* WXRichText.mm */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp;
path = WXRichText.mm; sourceTree = "<group>"; };
775BEE4D1C16F993008D1629 /* WXDefine.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
WXDefine.h; sourceTree = "<group>"; };
@@ -1848,6 +1854,8 @@
77E659D71C07F585008B8775 /* Module */ = {
isa = PBXGroup;
children = (
+ 7704894622AA358400E7606F /*
WXConsoleLogModule.h */,
+ 7704894722AA358400E7606F /*
WXConsoleLogModule.m */,
BA5F00EF1FC5AFFE00F76B5C /* WXLocaleModule.h */,
BA5F00F01FC5AFFE00F76B5C /* WXLocaleModule.m */,
DCE2CF981F46D4220021BDC4 /* WXVoiceOverModule.m
*/,
@@ -2488,6 +2496,7 @@
B8D66C8121255730003960BD /* render_type.h in
Headers */,
B8D66CA121255730003960BD /* WeexApiHeader.h in
Headers */,
B8D66CA921255730003960BD /* wson_util.h in
Headers */,
+ 7704894822AA358500E7606F /*
WXConsoleLogModule.h in Headers */,
B8D66C8B21255730003960BD /*
render_list_factory.h in Headers */,
745B2D681E5A8E1E0092D38A /*
WXMultiColumnLayout.h in Headers */,
B89543F720EB18B5006EAD63 /* WXCoreBridge.h in
Headers */,
@@ -2546,6 +2555,7 @@
B8D66C3621255730003960BD /*
render_action_move_element.h in Headers */,
DCA445A31EFA570800D0CFA8 /* WXSDKManager.h in
Headers */,
DCA445BE1EFA57BB00D0CFA8 /*
WXComponentManager.h in Headers */,
+ 7704894922AA358500E7606F /*
WXConsoleLogModule.h in Headers */,
DCA4459E1EFA56E500D0CFA8 /* WXUtility.h in
Headers */,
77A3D66F222F9F5B0078A6F5 /* WeexApiValue.h in
Headers */,
DCA445B91EFA579D00D0CFA8 /* WXErrorView.h in
Headers */,
@@ -3008,6 +3018,7 @@
742AD7321DF98C45007DC46C /*
WXResourceRequestHandlerDefaultImpl.m in Sources */,
74CFDD421F45941E007A1A66 /*
WXRecycleListTemplateManager.m in Sources */,
747DF6831E31AEE4005C53A8 /* WXLength.m in
Sources */,
+ 7704894A22AA358500E7606F /*
WXConsoleLogModule.m in Sources */,
17E5ACE2209211BD00EE81F1 /* WXTransition.mm in
Sources */,
77E65A0E1C155E99008B8775 /* WXDivComponent.m in
Sources */,
B8D66CAB21255730003960BD /* wson_util.cpp in
Sources */,
@@ -3212,6 +3223,7 @@
B8D66C4C21255730003960BD /*
render_action_remove_event.cpp in Sources */,
74B81AE41F73C3E500D3A61D /*
WXRecycleListComponent.mm in Sources */,
B8D66C6421255730003960BD /* render_text.cpp in
Sources */,
+ 7704894B22AA358500E7606F /*
WXConsoleLogModule.m in Sources */,
DC7764951F3C685200B5727E /*
WXRecyclerDragController.m in Sources */,
B89543F420EB18B5006EAD63 /* WXCoreBridge.mm in
Sources */,
DCA4453D1EFA55B300D0CFA8 /* WXRootView.m in
Sources */,
diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
index d2d9bd5..c498cc1 100644
--- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
+++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
@@ -66,6 +66,7 @@
[self registerModule:@"meta" withClass:NSClassFromString(@"WXMetaModule")];
[self registerModule:@"webSocket"
withClass:NSClassFromString(@"WXWebSocketModule")];
[self registerModule:@"voice-over"
withClass:NSClassFromString(@"WXVoiceOverModule")];
+ [self registerModule:@"sdk-console-log"
withClass:NSClassFromString(@"WXConsoleLogModule")];
}
+ (void)registerModule:(NSString *)name withClass:(Class)clazz
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
index 9f9c3de..451cc18 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
@@ -321,7 +321,7 @@ static NSThread *WXComponentThread;
if (supercomponent.ignoreInteraction) {
component.ignoreInteraction = YES;
}
- component.ignoreInteraction = [[component.attributes
objectForKey:@"ignoreInteraction"] boolValue];
+ component.ignoreInteraction = [[attributes
objectForKey:@"ignoreInteraction"] boolValue];
#ifdef DEBUG
WXLogDebug(@"flexLayout -> _recursivelyAddComponent :
super:(%@,%@):[%f,%f] ,child:(%@,%@):[%f,%f],childClass:%@",
diff --git a/ios/sdk/WeexSDK/Sources/Module/WXConsoleLogModule.h
b/ios/sdk/WeexSDK/Sources/Module/WXConsoleLogModule.h
new file mode 100644
index 0000000..f3f35d2
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/Module/WXConsoleLogModule.h
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#import <Foundation/Foundation.h>
+#import "WXModuleProtocol.h"
+
+/**
+ Redirect and output log to console.
+ */
+@interface WXConsoleLogModule : NSObject <WXModuleProtocol>
+@end
diff --git a/ios/sdk/WeexSDK/Sources/Module/WXConsoleLogModule.m
b/ios/sdk/WeexSDK/Sources/Module/WXConsoleLogModule.m
new file mode 100644
index 0000000..eacc8a4
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/Module/WXConsoleLogModule.m
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#import "WXConsoleLogModule.h"
+#import "WXLog.h"
+
+#if !TARGET_OS_WATCH
+#import <asl.h>
+#endif
+
+#if !__has_feature(objc_arc)
+#error This file must be compiled with ARC. Use -fobjc-arc flag (or convert
project to ARC).
+#endif
+
+@interface WXConsoleLogHandler : NSObject<WXLogProtocol>
+
+@property (nonatomic, assign) WXLogLevel logLevel;
+
++ (WXConsoleLogHandler *)sharedInstance;
+
+- (WXLogLevel)logLevel;
+
+- (void)log:(WXLogFlag)flag message:(NSString *)message;
+
+@end
+
+@implementation WXConsoleLogHandler
+
++ (WXConsoleLogHandler *)sharedInstance
+{
+ static dispatch_once_t onceToken;
+ static WXConsoleLogHandler* instance = nil;
+ dispatch_once(&onceToken, ^{
+ instance = [[WXConsoleLogHandler alloc] init];
+ });
+ return instance;
+}
+
+- (instancetype)init
+{
+ if (self = [super init]) {
+ _logLevel = WXLogLevelAll;
+ }
+ return self;
+}
+
+- (WXLogLevel)logLevel
+{
+ return _logLevel;
+}
+
+- (void)log:(WXLogFlag)flag message:(NSString *)message
+{
+#if !TARGET_OS_WATCH
+ dispatch_async(dispatch_get_main_queue(), ^{
+ asl_log_message(ASL_LEVEL_NOTICE, "%s", [message UTF8String]);
+ });
+#else
+ printf("\n%s\n", [message UTF8String]);
+#endif
+}
+
+@end
+
+@implementation WXConsoleLogModule
+
+WX_EXPORT_METHOD(@selector(switchLogLevel:callback:))
+
+- (void)switchLogLevel:(NSString*)logLevel
callback:(WXKeepAliveCallback)callback {
+ static id<WXLogProtocol> OriginalLogger = nil;
+
+ // When first invoke WXConsoleLogModule we record original logger
+ if (OriginalLogger == nil) {
+ OriginalLogger = [WXLog getCurrentExternalLog];
+ }
+
+ if ([logLevel isEqualToString:@"off"]) {
+ [WXLog registerExternalLog:OriginalLogger];
+ }
+ else if ([logLevel isEqualToString:@"error"]) {
+ [WXConsoleLogHandler sharedInstance].logLevel = WXLogLevelError;
+ [WXLog registerExternalLog:[WXConsoleLogHandler sharedInstance]];
+ }
+ else if ([logLevel isEqualToString:@"warning"]) {
+ [WXConsoleLogHandler sharedInstance].logLevel = WXLogLevelWarning;
+ [WXLog registerExternalLog:[WXConsoleLogHandler sharedInstance]];
+ }
+ else if ([logLevel isEqualToString:@"info"]) {
+ [WXConsoleLogHandler sharedInstance].logLevel = WXLogLevelInfo;
+ [WXLog registerExternalLog:[WXConsoleLogHandler sharedInstance]];
+ }
+ else if ([logLevel isEqualToString:@"debug"]) {
+ [WXConsoleLogHandler sharedInstance].logLevel = WXLogLevelDebug;
+ [WXLog registerExternalLog:[WXConsoleLogHandler sharedInstance]];
+ }
+
+ if (callback) {
+ callback(@{}, NO);
+ }
+}
+
+@end
diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXLog.h
b/ios/sdk/WeexSDK/Sources/Utility/WXLog.h
index b4ba21f..e6fa666 100644
--- a/ios/sdk/WeexSDK/Sources/Utility/WXLog.h
+++ b/ios/sdk/WeexSDK/Sources/Utility/WXLog.h
@@ -103,6 +103,8 @@ typedef NS_ENUM(NSUInteger, WeexLogLevel){
+ (void)registerExternalLog:(id<WXLogProtocol>)externalLog;
++ (id<WXLogProtocol>)getCurrentExternalLog;
+
@end
#define WX_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 :
__FILE__)
diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXLog.m
b/ios/sdk/WeexSDK/Sources/Utility/WXLog.m
index 2be15b1..793bbca 100644
--- a/ios/sdk/WeexSDK/Sources/Utility/WXLog.m
+++ b/ios/sdk/WeexSDK/Sources/Utility/WXLog.m
@@ -136,9 +136,8 @@ static BOOL _logToWebSocket = NO;
{
NSString *flagString;
switch (flag) {
- case WXLogFlagError: {
+ case WXLogFlagError:
flagString = @"error";
- }
break;
case WXLogFlagWarning:
flagString = @"warn";
@@ -231,6 +230,11 @@ static BOOL _logToWebSocket = NO;
_externalLog = externalLog;
}
++ (id<WXLogProtocol>)getCurrentExternalLog
+{
+ return _externalLog;
+}
+
@end
#pragma mark - WXSafeLog