|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2020 Google LLC |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +/** |
| 20 | + * @file |
| 21 | + * This file implements a platform-specific Weave log interface. |
| 22 | + * |
| 23 | + */ |
| 24 | + |
| 25 | +#import <Foundation/Foundation.h> |
| 26 | + |
| 27 | +NS_ASSUME_NONNULL_BEGIN |
| 28 | + |
| 29 | +@protocol NLWeaveLogWriter; |
| 30 | + |
| 31 | +/** |
| 32 | + * Weave logging modules – for indicating which component created a log. |
| 33 | + * |
| 34 | + * @note |
| 35 | + * Must align with the order of nl::Weave::Logging::LogModule values. |
| 36 | + */ |
| 37 | +typedef NS_ENUM(NSInteger, NLLogModule) { |
| 38 | + NLLogModuleNotSpecified = 0, |
| 39 | + |
| 40 | + NLLogModuleInet, |
| 41 | + NLLogModuleBle, |
| 42 | + NLLogModuleMessageLayer, |
| 43 | + NLLogModuleSecurityManager, |
| 44 | + NLLogModuleExchangeManager, |
| 45 | + NLLogModuleTLV, |
| 46 | + NLLogModuleASN1, |
| 47 | + NLLogModuleCrypto, |
| 48 | + NLLogModuleDeviceManager, |
| 49 | + NLLogModuleAlarm, |
| 50 | + NLLogModuleBDX, |
| 51 | + NLLogModuleDataManagement, |
| 52 | + NLLogModuleDeviceControl, |
| 53 | + NLLogModuleDeviceDescription, |
| 54 | + NLLogModuleEcho, |
| 55 | + NLLogModuleFabricProvisioning, |
| 56 | + NLLogModuleNetworkProvisioning, |
| 57 | + NLLogModuleServiceDirectory, |
| 58 | + NLLogModuleServiceProvisioning, |
| 59 | + NLLogModuleSoftwareUpdate, |
| 60 | + NLLogModuleTokenPairing, |
| 61 | + NLLogModuleHeatLink, |
| 62 | + NLLogModuleTimeService, |
| 63 | + NLLogModuleWeaveTunnel, |
| 64 | + NLLogModuleHeartbeat, |
| 65 | + NLLogModuleWeaveSystemLayer, |
| 66 | + NLLogModuleDropcamLegacyPairing, |
| 67 | + NLLogModuleEventLogging, |
| 68 | + NLLogModuleSupport, |
| 69 | + |
| 70 | + // Module for logs originating from the Objective-C @c NLLogging macros. |
| 71 | + // |
| 72 | + // Must NOT overlap with the values mapped from nl::Weave::Logging::LogModule. |
| 73 | + NLLogModuleCocoa = 100, |
| 74 | +}; |
| 75 | + |
| 76 | +/** |
| 77 | + * Logging levels – for indicating the relative importance of a log message. |
| 78 | + * |
| 79 | + * @note |
| 80 | + * Must align with the order of nl::Weave::Logging::LogCategory values. |
| 81 | + */ |
| 82 | +typedef NS_ENUM(NSInteger, NLLogLevel) { |
| 83 | + NLLogLevelNone = 0, |
| 84 | + NLLogLevelError, |
| 85 | + NLLogLevelProgress, |
| 86 | + NLLogLevelDetail, |
| 87 | + NLLogLevelRetain, |
| 88 | +}; |
| 89 | + |
| 90 | +/** |
| 91 | + * Platform-specific component for managing Weave log messages. |
| 92 | + * |
| 93 | + * Exposes an interface for external clients to configure the shared @c NLWeaveLogWriter – the log |
| 94 | + * writer will receive Weave logs from both the shared C++ source code and the platform-specific |
| 95 | + * Objective-C source code. This allows clients to connect Weave logs to their own logging system. |
| 96 | + */ |
| 97 | +@interface NLWeaveLogging : NSObject |
| 98 | + |
| 99 | +#pragma Logging Configuration |
| 100 | + |
| 101 | +/** |
| 102 | + * Sets the shared @c NLWeaveLogWriter to start receiving Weave logs. |
| 103 | + * |
| 104 | + * @note |
| 105 | + * This should be called prior to any Weave operations to ensure the log writer has been |
| 106 | + * configured before any logs are written. The log writer will only receive messages logged after |
| 107 | + * it has been set as the shared writer. |
| 108 | + */ |
| 109 | ++ (void)setSharedLogWriter:(nullable id<NLWeaveLogWriter>)logWriter; |
| 110 | + |
| 111 | +#pragma Log Methods |
| 112 | + |
| 113 | +/** |
| 114 | + * Internal handler method for logging a message to the console and notifying the shared log writer. |
| 115 | + * |
| 116 | + * @param logModule The logging module to which the log belongs. |
| 117 | + * @param logModuleName The name of the logging module. |
| 118 | + * @param logLevel The level of the log message. |
| 119 | + * @param formattedLogMessage The formatted log message. |
| 120 | + */ |
| 121 | ++ (void)handleWeaveLogFromModule:(NLLogModule)logModule |
| 122 | + moduleName:(NSString *)logModuleName |
| 123 | + level:(NLLogLevel)logLevel |
| 124 | + formattedMessage:(NSString *)formattedLogMessage; |
| 125 | + |
| 126 | +@end |
| 127 | + |
| 128 | +NS_ASSUME_NONNULL_END |
0 commit comments