diff --git a/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.mm b/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.mm index 31e142cb92e..87183a5e03b 100644 --- a/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.mm +++ b/framework/examples/ios-demo/HippyDemo/RenderPage/HippyDemoViewController.mm @@ -35,6 +35,33 @@ static NSString *const engineKey = @"Demo"; +static NSString *formatLog(NSDate *timestamp, HippyLogLevel level, NSString *fileName, NSNumber *lineNumber, NSString *message) { + static NSArray *logLevelMap = @[@"TRACE", @"INFO", @"WARN", @"ERROR", @"FATAL"]; + static NSDateFormatter *formatter; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + formatter = [NSDateFormatter new]; + formatter.dateFormat = formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss.SSS"; + }); + + NSString *levelStr = level < 0 || level > logLevelMap.count ? logLevelMap[1] : logLevelMap[level]; + + if(fileName){ + return [[NSString alloc] initWithFormat:@"[%@][%@:%d][%@]%@", + [formatter stringFromDate:timestamp], + fileName.lastPathComponent, + lineNumber.intValue, + levelStr, + message + ]; + }else{ + return [[NSString alloc] initWithFormat:@"[%@]%@", + [formatter stringFromDate:timestamp], + message + ]; + } +} + @interface HippyDemoViewController () { DriverType _driverType; RenderType _renderType; @@ -99,7 +126,12 @@ - (void)viewDidLoad { - (void)registerLogFunction { HippySetLogFunction(^(HippyLogLevel level, HippyLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { - NSLog(@"hippy says:%@ in file %@ at line %@", message, fileName, lineNumber); + NSString *log = formatLog([NSDate date], level, fileName, lineNumber, message); + if([log hasSuffix:@"\n"]){ + fprintf(stderr, "%s", log.UTF8String); + }else{ + fprintf(stderr, "%s\n", log.UTF8String); + } }); } diff --git a/framework/ios/base/bridge/HippyBridge.mm b/framework/ios/base/bridge/HippyBridge.mm index b367da495f5..7965ff25245 100644 --- a/framework/ios/base/bridge/HippyBridge.mm +++ b/framework/ios/base/bridge/HippyBridge.mm @@ -414,7 +414,7 @@ - (void)loadBundleURL:(NSURL *)bundleURL } return; } - HippyLogInfo(@"Begin loading bundle(%s) at %s", HP_CSTR_NOT_NULL(bundleURL.absoluteString.lastPathComponent.UTF8String), HP_CSTR_NOT_NULL(bundleURL.absoluteString.UTF8String)); + HippyLogInfo(@"[HP PERF] Begin loading bundle(%s) at %s", HP_CSTR_NOT_NULL(bundleURL.absoluteString.lastPathComponent.UTF8String), HP_CSTR_NOT_NULL(bundleURL.absoluteString.UTF8String)); [_bundleURLs addObject:bundleURL]; dispatch_async(HippyBridgeQueue(), ^{ [self beginLoadingBundle:bundleURL completion:completion]; @@ -509,7 +509,7 @@ - (void)loadInstanceForRootView:(NSNumber *)rootTag withProperties:(NSDictionary - (void)innerLoadInstanceForRootView:(NSNumber *)rootTag withProperties:(NSDictionary *)props { HippyAssert(_moduleName, @"module name must not be null"); HippyLogInfo(@"[Hippy_OC_Log][Life_Circle],Running application %@ (%@)", _moduleName, props); - HippyLogInfo(@"Begin loading instance for HippyBridge(%p)", self); + HippyLogInfo(@"[HP PERF] Begin loading instance for HippyBridge(%p)", self); NSDictionary *param = @{@"name": _moduleName, @"id": rootTag, @"params": props ?: @{}, @@ -517,7 +517,7 @@ - (void)innerLoadInstanceForRootView:(NSNumber *)rootTag withProperties:(NSDicti footstone::value::HippyValue value = [param toHippyValue]; std::shared_ptr domValue = std::make_shared(value); self.javaScriptExecutor.pScope->LoadInstance(domValue); - HippyLogInfo(@"End loading instance for HippyBridge(%p)", self); + HippyLogInfo(@"[HP PERF] End loading instance for HippyBridge(%p)", self); } - (void)rootViewSizeChangedEvent:(NSNumber *)tag params:(NSDictionary *)params { diff --git a/modules/footstone/include/footstone/logging.h b/modules/footstone/include/footstone/logging.h index cba1b2aa415..f4694117ace 100644 --- a/modules/footstone/include/footstone/logging.h +++ b/modules/footstone/include/footstone/logging.h @@ -119,7 +119,8 @@ class LogMessage { } std::ostringstream s; - s<<"thread:"<