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)
Info Output Method
- (void)info:(nullable NSString *)message;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| message | NSString | Log content |
- Example
Objective-C
// Info log
[self.logger info:@"test content"];
Swift
// Info log
logger.info("Info log")
Info Output Method (Optional Error Information)
- (void)info:(nullable NSString *)message error:(nullable NSError *)error;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| message | NSString | Log content |
| error | NSError | Error information |
- Example
Objective-C
// Info log
NSError *err = [NSError errorWithDomain:@"test domain" code:-999 userInfo:nil];
[self.logger info:@"test content" error:err];
Swift
// Info log
let error = NSError(domain: "test domain", code: -9999)
logger.info("Info log", error: error)
Warn Output Method
- (void)warn:(nullable NSString *)message;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| message | NSString | Log content |
- Example
Objective-C
// Warn log
[self.logger warn:@"test content"];
Swift
// Warn log
logger.warn("Warn log")
Warn Output Method (Optional Error Information)
- (void)warn:(nullable NSString *)message error:(nullable NSError *)error;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| message | NSString | Log content |
| error | NSError | Error information |
- Example
Objective-C
// Warn log
NSError *err = [NSError errorWithDomain:@"test domain" code:-999 userInfo:nil];
[self.logger warn:@"test content" error:err];
Swift
// Warn log
let error = NSError(domain: "test domain", code: -9999)
logger.warn("Warn log", error: error)
Error Output Method
- (void)error:(nullable NSString *)message;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| message | NSString | Log content |
- Example
Objective-C
// Error log
[self.logger error:@"test content"];
Swift
// Error log
logger.error("Error log")
Error Output Method (Optional Error Information)
- (void)error:(nullable NSString *)message error:(nullable NSError *)error;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| message | NSString | Log content |
| error | NSError | Error information |
- Example
Objective-C
// Error log
NSError *err = [NSError errorWithDomain:@"test domain" code:-999 userInfo:nil];
[self.logger error:@"test content" error:err];
Swift
// Error log
let error = NSError(domain: "test domain", code: -9999)
logger.error("Error log", error: error)
Emergency Output Method
- (void)emergency:(nullable NSString *)message;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| message | NSString | Log content |
- Example
Objective-C
// Emergency log
[self.logger emergency:@"test content"];
Swift
// Emergency log
logger.emergency("Emergency log")
Emergency Output Method (Optional Error Information)
- (void)emergency:(nullable NSString *)message error:(nullable NSError *)error;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| message | NSString | Log content |
| error | NSError | Error information |
- Example
Objective-C
// Emergency log
NSError *err = [NSError errorWithDomain:@"test domain" code:-999 userInfo:nil];
[self.logger emergency:@"test content" error:err];
Swift
// Emergency log
let error = NSError(domain: "test domain", code: -9999)
logger.emergency("Emergency log", error: error)
Custom Parameter Output Method
- (void)logWithLevel:(BRLogLevel)level
message:(nullable NSString *)message
error:(nullable NSError *)error
attributes:(nullable NSDictionary<NSString *, id> *)attributes;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| level | BRLogLevel | Log level |
| message | NSString | Log content |
| error | NSError | Error information |
| attributes | NSDictionary | Additional attributes |
Only NSString and NSNumber types are supported for values in attributes
- Example
Objective-C
NSError *err = [NSError errorWithDomain:@"test domain" code:-999 userInfo:nil];
[self.logger logWithLevel:BRLogLevelDebug message:@"debug message" error:err attributes:@{@"name": @"test name"}];
Swift
let error = NSError(domain: "test domain", code: -9999)
logger.log(with: .debug, message: "log message", error: error, attributes: ["name": "test name"])
III. Custom Functionality Interface
BRLogAgent supports setting attributes, and the attribute values are attached to logs for easy viewing and analysis.
The following two methods can add/remove attributes to/from BRLogger. Logs generated by this BRLogger will then carry these attributes.
Add Attribute Interface
- (void)addAttributeForKey:(NSString *)key value:(id)value;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| key | NSString | Attribute key |
| value | id | Attribute value |
Only NSString and NSNumber types are supported for values in attributes
- Example
Objective-C
[self.logger addAttributeForKey:@"name" value:@"Bonree"];
Swift
logger.addAttribute(forKey: "name", value: "Bonree")
Remove Attribute Interface
- (void)removeAttributeForKey:(NSString *)key;
- Interface Description
| Parameter Name | Type | Description |
|---|---|---|
| key | NSString | Attribute key |
- Example
Objective-C
[self.logger removeAttributeForKey:@"name"];
Swift
logger.removeAttribute(forKey: "name")