FIRMessagingLogger.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright 2017 Google
  3. *
  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
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.
  15. */
  16. #import "FIRMessagingConfig.h"
  17. #import "FIRMMessageCode.h"
  18. // The convenience macros are only defined if they haven't already been defined.
  19. #ifndef FIRMessagingLoggerInfo
  20. // Convenience macros that log to the shared FIRMessagingLogger instance. These macros
  21. // are how users should typically log to FIRMessagingLogger.
  22. #define FIRMessagingLoggerDebug(code, ...) \
  23. [FIRMessagingSharedLogger() logFuncDebug:__func__ messageCode:code msg:__VA_ARGS__]
  24. #define FIRMessagingLoggerInfo(code, ...) \
  25. [FIRMessagingSharedLogger() logFuncInfo:__func__ messageCode:code msg:__VA_ARGS__]
  26. #define FIRMessagingLoggerNotice(code, ...) \
  27. [FIRMessagingSharedLogger() logFuncNotice:__func__ messageCode:code msg:__VA_ARGS__]
  28. #define FIRMessagingLoggerWarn(code, ...) \
  29. [FIRMessagingSharedLogger() logFuncWarning:__func__ messageCode:code msg:__VA_ARGS__]
  30. #define FIRMessagingLoggerError(code, ...) \
  31. [FIRMessagingSharedLogger() logFuncError:__func__ messageCode:code msg:__VA_ARGS__]
  32. #endif // !defined(FIRMessagingLoggerInfo)
  33. /// Protocols
  34. @protocol FIRMessagingLogFormatter <NSObject>
  35. - (NSString *)stringForFunc:(NSString *)func
  36. withFormat:(NSString *)fmt
  37. valist:(va_list)args
  38. level:(FIRMessagingLogLevel)level NS_FORMAT_FUNCTION(2, 0);
  39. @end
  40. /// FIRMessagingLogWriter
  41. @protocol FIRMessagingLogWriter <NSObject>
  42. // Writes the given log message to where the log writer is configured to write.
  43. - (void)logMessage:(NSString *)msg level:(FIRMessagingLogLevel)level;
  44. @end
  45. /// FIRMessagingLogFilter
  46. @protocol FIRMessagingLogFilter <NSObject>
  47. // Returns YES if |msg| at |level| should be logged; NO otherwise.
  48. - (BOOL)filterAllowsMessage:(NSString *)msg level:(FIRMessagingLogLevel)level;
  49. @end
  50. @interface FIRMessagingLogLevelFilter : NSObject <FIRMessagingLogFilter>
  51. - (instancetype)initWithLevel:(FIRMessagingLogLevel)level;
  52. @end
  53. @interface FIRMessagingLogger : NSObject
  54. @property(nonatomic, readwrite, strong) id<FIRMessagingLogFilter> filter;
  55. @property(nonatomic, readwrite, strong) id<FIRMessagingLogWriter> writer;
  56. @property(nonatomic, readwrite, strong) id<FIRMessagingLogFormatter> formatter;
  57. - (void)logFuncDebug:(const char *)func
  58. messageCode:(FIRMessagingMessageCode)messageCode
  59. msg:(NSString *)fmt, ... NS_FORMAT_FUNCTION(3, 4);
  60. - (void)logFuncInfo:(const char *)func
  61. messageCode:(FIRMessagingMessageCode)messageCode
  62. msg:(NSString *)fmt, ... NS_FORMAT_FUNCTION(3, 4);
  63. - (void)logFuncNotice:(const char *)func
  64. messageCode:(FIRMessagingMessageCode)messageCode
  65. msg:(NSString *)fmt, ... NS_FORMAT_FUNCTION(3, 4);
  66. - (void)logFuncWarning:(const char *)func
  67. messageCode:(FIRMessagingMessageCode)messageCode
  68. msg:(NSString *)fmt, ... NS_FORMAT_FUNCTION(3, 4);
  69. - (void)logFuncError:(const char *)func
  70. messageCode:(FIRMessagingMessageCode)messageCode
  71. msg:(NSString *)fmt, ... NS_FORMAT_FUNCTION(3, 4);
  72. @end
  73. /**
  74. * Instantiates and/or returns a shared FIRMessagingLogger used exclusively
  75. * for FIRMessaging log messages.
  76. *
  77. * @return the shared FIRMessagingLogger instance
  78. */
  79. FIRMessagingLogger *FIRMessagingSharedLogger();