diff options
author | m-stephen <truestyle2005@163.com> | 2019-07-25 15:39:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-25 15:39:01 +0800 |
commit | 2e5897c0f49120c72b7431b3af7d41bef3414719 (patch) | |
tree | 9b08bab9c802813f390826d1ae0ecb90c88667d2 /platform/darwin | |
parent | a8db681454e5173c03154e79c5f125ce26d653c1 (diff) | |
download | qtlocation-mapboxgl-2e5897c0f49120c72b7431b3af7d41bef3414719.tar.gz |
[ios, macos]MGLLoggingConfiguration can filter logs from core (#15120)
* [ios, macos] update proj config
* [ios, macos] implement the logging logic
* [ios, macos] update comments
* [ios, macos] update mac os config
* [ios, macos] re-generate sdk files
* [ios, macos] re-generate sdk files json
* [ios, macos]re-generate json files
* [ios, macos] re-generate ios json files
* [ios] change conditions to bit mask
* [ios, macos]send messages to platform
* [ios, macos] add changelogs
* [ios, macos] revert `logging_nslog`
* [ios, macos] add event name and code into log msg
* [ios, macos] update changlog
* [ios, macos] fix a nit
* [ios, macos]Fix nits.
Diffstat (limited to 'platform/darwin')
-rw-r--r-- | platform/darwin/filesource-files.json | 2 | ||||
-rw-r--r-- | platform/darwin/src/MGLLoggingConfiguration.h | 29 | ||||
-rw-r--r-- | platform/darwin/src/MGLLoggingConfiguration.mm (renamed from platform/darwin/src/MGLLoggingConfiguration.m) | 48 | ||||
-rw-r--r-- | platform/darwin/src/MGLLoggingConfiguration_Private.h | 8 | ||||
-rw-r--r-- | platform/darwin/src/logging_nslog.mm | 12 |
5 files changed, 73 insertions, 26 deletions
diff --git a/platform/darwin/filesource-files.json b/platform/darwin/filesource-files.json index b2e6fbc9b4..62043a0dcd 100644 --- a/platform/darwin/filesource-files.json +++ b/platform/darwin/filesource-files.json @@ -1,7 +1,7 @@ { "//": "This file can be edited manually and is the canonical source.", "sources": [ - "platform/darwin/src/MGLLoggingConfiguration.m", + "platform/darwin/src/MGLLoggingConfiguration.mm", "platform/darwin/src/MGLNetworkConfiguration.m", "platform/darwin/src/http_file_source.mm", "platform/default/src/mbgl/storage/file_source.cpp", diff --git a/platform/darwin/src/MGLLoggingConfiguration.h b/platform/darwin/src/MGLLoggingConfiguration.h index d79336df4c..2445078584 100644 --- a/platform/darwin/src/MGLLoggingConfiguration.h +++ b/platform/darwin/src/MGLLoggingConfiguration.h @@ -16,33 +16,38 @@ NS_ASSUME_NONNULL_BEGIN */ typedef NS_ENUM(NSInteger, MGLLoggingLevel) { /** - None-level messages are ignored. + None-level won't print any messages. */ MGLLoggingLevelNone = 0, /** + Fault-level messages contain system-level error information. + */ + MGLLoggingLevelFault, + /** + Error-level messages contain information that is intended to aid in process-level + errors. + */ + MGLLoggingLevelError, + /** + Warning-level messages contain warning information for potential risks. + */ + MGLLoggingLevelWarning, + /** Info-level messages contain information that may be helpful for flow tracing but is not essential. */ MGLLoggingLevelInfo, -#if MGL_LOGGING_ENABLE_DEBUG /** Debug-level messages contain information that may be helpful for troubleshooting specific problems. */ +#if MGL_LOGGING_ENABLE_DEBUG MGLLoggingLevelDebug, #endif /** - Error-level messages contain information that is intended to aid in process-level - errors. - */ - MGLLoggingLevelError, - /** - Fault-level messages contain system-level error information. - */ - MGLLoggingLevelFault, - /** - :nodoc: Any new logging level should be included in the default logging implementation. + Verbose-level will print all messages. */ + MGLLoggingLevelVerbose, }; /** diff --git a/platform/darwin/src/MGLLoggingConfiguration.m b/platform/darwin/src/MGLLoggingConfiguration.mm index 4dfe3f7901..75d2439365 100644 --- a/platform/darwin/src/MGLLoggingConfiguration.m +++ b/platform/darwin/src/MGLLoggingConfiguration.mm @@ -1,3 +1,6 @@ +#include <mbgl/util/logging.hpp> +#include <mbgl/util/enum.hpp> + #import "MGLLoggingConfiguration_Private.h" #ifndef MGL_LOGGING_DISABLED @@ -5,10 +8,39 @@ #import <os/log.h> #endif -@implementation MGLLoggingConfiguration +namespace mbgl { + +class MGLCoreLoggingObserver : public Log :: Observer { +public: + //Return true not print messages at core level, and filter at platform level. + bool onRecord(EventSeverity severity, Event event, int64_t code, const std::string& msg) override{ + + NSString *message = [NSString stringWithFormat:@"[event]:%s [code]:%lld [message]:%@", Enum<Event>::toString(event), code, [NSString stringWithCString:msg.c_str() encoding:NSUTF8StringEncoding]]; + switch (severity) { + case EventSeverity::Debug: + MGLLogDebug(message); + break; + case EventSeverity::Info: + MGLLogInfo(message); + break; + case EventSeverity::Warning: + MGLLogWarning(message); + break; + case EventSeverity::Error: + MGLLogError(message); + break; + } + return true; + } +}; +} -+ (instancetype)sharedConfiguration +@implementation MGLLoggingConfiguration { + std::unique_ptr<mbgl::MGLCoreLoggingObserver> _coreLoggingObserver; +} + ++ (instancetype)sharedConfiguration { static dispatch_once_t once; static id sharedConfiguration; dispatch_once(&once, ^{ @@ -18,6 +50,13 @@ return sharedConfiguration; } +- (id)init{ + if(self = [super init]){ + mbgl::Log::setObserver(std::make_unique<mbgl::MGLCoreLoggingObserver>()); + } + return self; +} + - (void)setHandler:(void (^)(MGLLoggingLevel, NSString *, NSUInteger, NSString *))handler { if (!handler) { @@ -27,8 +66,7 @@ } } -- (void)logCallingFunction:(const char *)callingFunction functionLine:(NSUInteger)functionLine messageType:(MGLLoggingLevel)type format:(id)messageFormat, ... -{ +- (void)logCallingFunction:(const char *)callingFunction functionLine:(NSUInteger)functionLine messageType:(MGLLoggingLevel)type format:(id)messageFormat, ... { va_list formatList; va_start(formatList, messageFormat); NSString *formattedMessage = [[NSString alloc] initWithFormat:messageFormat arguments:formatList]; @@ -68,6 +106,7 @@ os_log_t mapbox_log; switch (level) { case MGLLoggingLevelInfo: + case MGLLoggingLevelWarning: mapbox_log = info_log; break; #if MGL_LOGGING_ENABLE_DEBUG @@ -92,6 +131,7 @@ NSString *category; switch (level) { case MGLLoggingLevelInfo: + case MGLLoggingLevelWarning: category = @"INFO"; break; #if MGL_LOGGING_ENABLE_DEBUG diff --git a/platform/darwin/src/MGLLoggingConfiguration_Private.h b/platform/darwin/src/MGLLoggingConfiguration_Private.h index 3acc0291c0..40b4df440d 100644 --- a/platform/darwin/src/MGLLoggingConfiguration_Private.h +++ b/platform/darwin/src/MGLLoggingConfiguration_Private.h @@ -14,6 +14,7 @@ NS_INLINE NSString *MGLStringFromNSEdgeInsets(NSEdgeInsets insets) { #define MGLLogInfo(...) #define MGLLogDebug(...) +#define MGLLogWarning(...) #define MGLLogError(...) #define MGLLogFault(...) @@ -25,9 +26,10 @@ NS_INLINE NSString *MGLStringFromNSEdgeInsets(NSEdgeInsets insets) { #define MGLLogDebug(...) #endif -#define MGLLogInfo(message, ...) MGLLogWithType(MGLLoggingLevelInfo, __PRETTY_FUNCTION__, __LINE__, message, ##__VA_ARGS__) -#define MGLLogError(message, ...) MGLLogWithType(MGLLoggingLevelError, __PRETTY_FUNCTION__, __LINE__, message, ##__VA_ARGS__) -#define MGLLogFault(message, ...) MGLLogWithType(MGLLoggingLevelFault, __PRETTY_FUNCTION__, __LINE__, message, ##__VA_ARGS__) +#define MGLLogInfo(message, ...) MGLLogWithType(MGLLoggingLevelInfo, __PRETTY_FUNCTION__, __LINE__, message, ##__VA_ARGS__) +#define MGLLogWarning(message, ...) MGLLogWithType(MGLLoggingLevelWarning, __PRETTY_FUNCTION__, __LINE__, message, ##__VA_ARGS__) +#define MGLLogError(message, ...) MGLLogWithType(MGLLoggingLevelError, __PRETTY_FUNCTION__, __LINE__, message, ##__VA_ARGS__) +#define MGLLogFault(message, ...) MGLLogWithType(MGLLoggingLevelFault, __PRETTY_FUNCTION__, __LINE__, message, ##__VA_ARGS__) #endif diff --git a/platform/darwin/src/logging_nslog.mm b/platform/darwin/src/logging_nslog.mm index dd428f56b1..ac3c939bb5 100644 --- a/platform/darwin/src/logging_nslog.mm +++ b/platform/darwin/src/logging_nslog.mm @@ -4,11 +4,11 @@ #import <Foundation/Foundation.h> namespace mbgl { - -void Log::platformRecord(EventSeverity severity, const std::string &msg) { - NSString *message = + + void Log::platformRecord(EventSeverity severity, const std::string &msg) { + NSString *message = [[NSString alloc] initWithBytes:msg.data() length:msg.size() encoding:NSUTF8StringEncoding]; - NSLog(@"[%s] %@", Enum<EventSeverity>::toString(severity), message); -} - + NSLog(@"[%s] %@", Enum<EventSeverity>::toString(severity), message); + } + } |