2 * Copyright 2018 Google
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #import <Foundation/Foundation.h>
19 #import <GoogleUtilities/GULLoggerLevel.h>
21 NS_ASSUME_NONNULL_BEGIN
24 * The services used in the logger.
26 typedef NSString *const GULLoggerService;
33 * Initialize GULLogger.
35 extern void GULLoggerInitializeASL(void);
38 * Override log level to Debug.
40 void GULLoggerForceDebug(void);
43 * Turn on logging to STDERR.
45 extern void GULLoggerEnableSTDERR(void);
48 * Changes the default logging level of GULLoggerLevelNotice to a user-specified level.
49 * The default level cannot be set above GULLoggerLevelNotice if the app is running from App Store.
50 * (required) log level (one of the GULLoggerLevel enum values).
52 extern void GULSetLoggerLevel(GULLoggerLevel loggerLevel);
55 * Checks if the specified logger level is loggable given the current settings.
56 * (required) log level (one of the GULLoggerLevel enum values).
58 extern BOOL GULIsLoggableLevel(GULLoggerLevel loggerLevel);
61 * Register version to include in logs.
64 extern void GULLoggerRegisterVersion(const char *version);
67 * Logs a message to the Xcode console and the device log. If running from AppStore, will
68 * not log any messages with a level higher than GULLoggerLevelNotice to avoid log spamming.
69 * (required) log level (one of the GULLoggerLevel enum values).
70 * (required) service name of type GULLoggerService.
71 * (required) message code starting with "I-" which means iOS, followed by a capitalized
72 * three-character service identifier and a six digit integer message ID that is unique
74 * An example of the message code is @"I-COR000001".
75 * (required) message string which can be a format string.
76 * (optional) variable arguments list obtained from calling va_start, used when message is a format
79 extern void GULLogBasic(GULLoggerLevel level,
80 GULLoggerService service,
82 NSString *messageCode,
84 // On 64-bit simulators, va_list is not a pointer, so cannot be marked nullable
85 // See: http://stackoverflow.com/q/29095469
86 #if __LP64__ && TARGET_OS_SIMULATOR || TARGET_OS_OSX
89 va_list _Nullable args_ptr
94 * The following functions accept the following parameters in order:
95 * (required) service name of type GULLoggerService.
96 * (required) message code starting from "I-" which means iOS, followed by a capitalized
97 * three-character service identifier and a six digit integer message ID that is unique
99 * An example of the message code is @"I-COR000001".
100 * See go/firebase-log-proposal for details.
101 * (required) message string which can be a format string.
102 * (optional) the list of arguments to substitute into the format string.
104 * GULLogError(kGULLoggerCore, @"I-COR000001", @"Configuration of %@ failed.", app.name);
106 extern void GULLogError(GULLoggerService service,
108 NSString *messageCode,
110 ...) NS_FORMAT_FUNCTION(4, 5);
111 extern void GULLogWarning(GULLoggerService service,
113 NSString *messageCode,
115 ...) NS_FORMAT_FUNCTION(4, 5);
116 extern void GULLogNotice(GULLoggerService service,
118 NSString *messageCode,
120 ...) NS_FORMAT_FUNCTION(4, 5);
121 extern void GULLogInfo(GULLoggerService service,
123 NSString *messageCode,
125 ...) NS_FORMAT_FUNCTION(4, 5);
126 extern void GULLogDebug(GULLoggerService service,
128 NSString *messageCode,
130 ...) NS_FORMAT_FUNCTION(4, 5);
134 #endif // __cplusplus
136 @interface GULLoggerWrapper : NSObject
139 * Objective-C wrapper for GULLogBasic to allow weak linking to GULLogger
140 * (required) log level (one of the GULLoggerLevel enum values).
141 * (required) service name of type GULLoggerService.
142 * (required) message code starting with "I-" which means iOS, followed by a capitalized
143 * three-character service identifier and a six digit integer message ID that is unique
144 * within the service.
145 * An example of the message code is @"I-COR000001".
146 * (required) message string which can be a format string.
147 * (optional) variable arguments list obtained from calling va_start, used when message is a format
151 + (void)logWithLevel:(GULLoggerLevel)level
152 withService:(GULLoggerService)service
153 withCode:(NSString *)messageCode
154 withMessage:(NSString *)message
155 withArgs:(va_list)args;
159 NS_ASSUME_NONNULL_END