Log API
I. Startup Configuration Interface
Please obtain the AppID and LogConfig Address from the platform or contact technical support.
BRLogConfiguration Configuration
@interface BRLogConfiguration : NSObject
/// AppID
@property (nonatomic, copy) NSString *appID;
/// Data collection mode [Only effective when set at startup]
/// YES: Data is sent remotely and stored locally
/// NO: Data is not sent remotely and not stored locally
@property (nonatomic, assign) BOOL isTrackingData;
/// Application version
@property (nonatomic, copy, nullable) NSString *applicationVersion;
@end
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| appID | NSString | Platform-generated unique application ID (length limit: 256 characters) |
| isTrackingData | BOOL | Data collection mode [Only effective when set at startup], YES: Data is sent remotely and stored locally, NO: Data is not sent remotely and not stored locally |
| applicationVersion | NSString | Custom application version (length limit: 256 characters) |
-
Example
Objective-C
BRLogConfiguration *config = [[BRLogConfiguration alloc] init];
config.isTrackingData = YES;
config.appID = @"<#AppID#>";
config.applicationVersion = @"1.0.0";Swift
let config = BRLogConfiguration()
config.isTrackingData = true
config.appID = "<#AppID#>"
config.applicationVersion = "1.0.0"
BRLogAgent Startup Interface
/// Start BRLogAgent
+ (void)startWithConfiguration:(BRLogConfiguration *)configuration;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| configuration | BRLogConfiguration | LogAgent configuration object |
-
Example
Objective-C
BRLogConfiguration *config = [[BRLogConfiguration alloc] init];
// Any configuration...
[BRLogAgent startWithConfiguration:config];Swift
let config = BRLogConfiguration()
// Any configuration...
BRLogAgent.start(with: config)
Set Config Address
Used by private cloud customers to set the config address for private deployment. Public cloud customers should not call this. This interface must be set before calling + startWithConfiguration:.
/// Set Config address (Please set before BRLogAgent starts)
+ (void)setConfigAddress:(NSString *)configAddress;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| configAddress | NSString | Private cloud config address |
-
Example
Objective-C
[BRLogAgent setConfigAddress:@"<#LogConfig Address#>"];Swift
BRLogAgent.setConfigAddress("<#LogConfig Address#>")
II. Log Output Interface
Custom Log Output
Log output uses the BRLogger class, which can be customized using BRLoggerBuilder.
- BRLogger Class Description
| Property | Type | Description |
|---|---|---|
| levelThreshold | BRLogLevel | Log threshold: Logs with a level equal to or more severe than levelThreshold will be reported and stored |
| loggerName | NSString | Logger name (length limit: 256 characters) |
| printConsole | BOOL | Whether to enable console output |
| prefix | NSString | Log prefix, unified for logs generated by this Logger |
Log Levels BRLogLevel: BRLogLevelDebug BRLogLevelInfo BRLogLevelNotice BRLogLevelWarn BRLogLevelError BRLogLevelEmergency
-
Example
Objective-C
// Custom logger configuration
BRLoggerBuilder *builder = [[BRLoggerBuilder alloc] init];
builder.levelThreshold = BRLogLevelDebug; // Log level threshold
builder.loggerName = @"Home Logger"; // Logger custom name
builder.printConsole = NO; // Whether to print to console
builder.prefix = @"[Bonree]"; // Log message prefixSwift
// Custom logger configuration
let builder = BRLoggerBuilder()
builder.levelThreshold = .debug // Log level threshold
builder.loggerName = "Home Logger" // Logger custom name
builder.printConsole = true // Whether to print to console
builder.prefix = "[Bonree]" // Log message prefix
Create Log Output Object Interface (Class Method)
+ (BRLogger *)loggerWithBuilder:(BRLoggerBuilder *)builder;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| builder | BRLoggerBuilder | Custom Logger configuration |
- Return Value Description
| Type | Description |
|---|---|
| BRLogger | Log output object |
-
Example
Objective-C
// Generate logger with configuration
BRLogger *logger = [BRLogger loggerWithBuilder:builder];Swift
// Generate logger with configuration
let logger = BRLogger(builder: builder)
Create Log Output Object Interface (Instance Method)
- (BRLogger *)initWithBuilder:(BRLoggerBuilder *)builder;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| builder | BRLoggerBuilder | Custom Logger configuration |
- Return Value Description
| Type | Description |
|---|---|
| BRLogger | Log output object |
-
Example
Objective-C
// Generate logger with configuration
BRLogger *logger = [[BRLogger alloc] initWithBuilder:builder];Swift
// Generate logger with configuration
let logger = BRLogger.init(builder: builder)
Debug Output Method
- (void)debug:(nullable NSString *)message;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| message | NSString | Log content |
- Example
Objective-C
// Debug log
[self.logger debug:@"test content"];
Swift
// Debug log
logger.debug("Debug log")
Debug Output Method (Optional Error Information)
- (void)debug:(nullable NSString *)message error:(nullable NSError *)error;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| message | NSString | Log content |
| error | NSError | Error information |
- Example
Objective-C
// Debug log
NSError *err = [NSError errorWithDomain:@"test domain" code:-999 userInfo:nil];
[self.logger debug:@"test content" error:err];
Swift
// Debug log
let error = NSError(domain: "test domain", code: -9999)
logger.debug("Debug log", error: error)