summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLLoggingConfiguration.m
diff options
context:
space:
mode:
authorFabian Guerra Soto <fabian.guerra@mapbox.com>2018-11-14 15:42:18 -0800
committerGitHub <noreply@github.com>2018-11-14 15:42:18 -0800
commitc8fbcfd322e1af4520f0bdc7e5945f6ffd3b4b73 (patch)
tree9158facaa7fc8b728a69f87f494a71fb659d9727 /platform/darwin/src/MGLLoggingConfiguration.m
parent86677b97c6d5e7db75358e9f5745dab4cec5d0e4 (diff)
downloadqtlocation-mapboxgl-c8fbcfd322e1af4520f0bdc7e5945f6ffd3b4b73.tar.gz
[ios, macos] Logging. (#13235)
* [ios, macos] Update the logging subsystem to platform agnostic. * [ios, macos] Add coordinate to string function. * [ios, macos] Add BOOL to string function. * [ios, macos] Add tracing logs. * [ios, macos] Add tracing logs to generated style classes. * [ios, macos] Split logging categories accordingly to MGLLoggingLevel. * [ios, macos] Log network requests. * [ios, macos] Migrate NSAssert to MGLAssert. * [ios, macos] Include MGLLoggingConfiguration to filesource-files.txt. * [ios, macos] Fix logger string specifier for the line parameter. * [ios, macos] Add logs to shapes classes. * [ios, macos] Add logs to offline classes. * [ios, macos] Add logs to annotation classes. * [ios, macos] Add logs to foundation classes. * [ios, macos] Fix snapshotter size logging. * [macos] Add logs to map view. * [ios, macos] Fix string from boolean prefix, add custom function for NSCAssert. * Log size test * [ios, macos] Add logging conditional compilation flag. * [ios, macos] Rename function NSStringFromMGLTransition to MGLStringFromMGLTransition. * [ios, macos] Remove verbose logging for release builds. * [ios, macos] Rename NSStringFromCLLocationCoordinate2D to MGLStringFromCLLocationCoordinate2D. * [ios, macos] Clean unnecesary blank lines in MGLLight.mm set methods. * [ios, macos] Fix logging grammar, format, function names. * [ios, macos] Remove compilation flag, rename flags.
Diffstat (limited to 'platform/darwin/src/MGLLoggingConfiguration.m')
-rw-r--r--platform/darwin/src/MGLLoggingConfiguration.m67
1 files changed, 61 insertions, 6 deletions
diff --git a/platform/darwin/src/MGLLoggingConfiguration.m b/platform/darwin/src/MGLLoggingConfiguration.m
index 93f2698287..fb760b7392 100644
--- a/platform/darwin/src/MGLLoggingConfiguration.m
+++ b/platform/darwin/src/MGLLoggingConfiguration.m
@@ -1,5 +1,6 @@
#import "MGLLoggingConfiguration_Private.h"
+#ifndef MGL_LOGGING_DISABLED
#if __has_builtin(__builtin_os_log_format)
#import <os/log.h>
#endif
@@ -42,21 +43,74 @@
if (@available(iOS 10.0, macOS 10.12.0, *)) {
static dispatch_once_t once;
- static os_log_t mapbox_log;
+ static os_log_t info_log;
+#if MGL_LOGGING_ENABLE_DEBUG
+ static os_log_t debug_log;
+#endif
+ static os_log_t error_log;
+ static os_log_t fault_log;
static os_log_type_t log_types[] = { OS_LOG_TYPE_DEFAULT,
OS_LOG_TYPE_INFO,
+#if MGL_LOGGING_ENABLE_DEBUG
OS_LOG_TYPE_DEBUG,
+#endif
OS_LOG_TYPE_ERROR,
OS_LOG_TYPE_FAULT };
dispatch_once(&once, ^ {
- mapbox_log = os_log_create("com.mapbox.maps-ios-sdk", "SDK");
+ info_log = os_log_create("com.mapbox.maps", "INFO");
+#if MGL_LOGGING_ENABLE_DEBUG
+ debug_log = os_log_create("com.mapbox.maps", "DEBUG");
+#endif
+ error_log = os_log_create("com.mapbox.maps", "ERROR");
+ fault_log = os_log_create("com.mapbox.maps", "FAULT");
});
- NSUInteger logTypesCount = sizeof(log_types) / sizeof(os_log_type_t);
- NSAssert(level <= logTypesCount, @"There is an attempt to log a non suported logging level.");
+
+ os_log_t mapbox_log;
+ switch (level) {
+ case MGLLoggingLevelInfo:
+ mapbox_log = info_log;
+ break;
+#if MGL_LOGGING_ENABLE_DEBUG
+ case MGLLoggingLevelDebug:
+ mapbox_log = debug_log;
+ break;
+#endif
+ case MGLLoggingLevelError:
+ mapbox_log = error_log;
+ break;
+ case MGLLoggingLevelFault:
+ mapbox_log = fault_log;
+ break;
+ case MGLLoggingLevelNone:
+ default:
+ break;
+ }
+
os_log_type_t logType = log_types[level];
- os_log_with_type(mapbox_log, logType, "%@ - %d: %@", fileName, line, message);
+ os_log_with_type(mapbox_log, logType, "%@ - %lu: %@", fileName, (unsigned long)line, message);
} else {
- NSLog(@"[SDK] %@ - %lu: %@", fileName, line, message);
+ NSString *category;
+ switch (level) {
+ case MGLLoggingLevelInfo:
+ category = @"INFO";
+ break;
+#if MGL_LOGGING_ENABLE_DEBUG
+ case MGLLoggingLevelDebug:
+ category = @"DEBUG";
+ break;
+#endif
+ case MGLLoggingLevelError:
+ category = @"ERROR";
+ break;
+ case MGLLoggingLevelFault:
+ category = @"FAULT";
+ break;
+ case MGLLoggingLevelNone:
+ default:
+ break;
+ }
+
+ NSLog(@"[%@] %@ - %lu: %@", category, fileName, (unsigned long)line, message);
}
};
@@ -64,3 +118,4 @@
}
@end
+#endif