Privacy and console logs
Looking for the previous SDK? See the 6.x console logs privacy page.
Bugsee captures your application's console logs automatically: standard output and standard
error (print, NSLog), CocoaLumberjack, the console of web pages in a WKWebView, and the
console output that the React Native, Flutter and Unity SDKs forward. You can turn the capture
off, keep only the more important levels, or clean every line before it is recorded.
Disabling log capture
Set BugseeOptionCaptureLogs (BugseeOptions.captureLogs) to NO. Nothing is captured
automatically then. Lines your code sends with Bugsee.log are still recorded.
- Objective-C
- Swift
BugseeOptions *options = [BugseeOptions defaultOptions];
options.captureLogs = NO;
[Bugsee launchWithToken:@"<your_app_token>" options:options];
let options = BugseeOptions.default()
options.captureLogs = false
Bugsee.launch(token: "<your_app_token>", options: options)
Keeping only some levels
BugseeOptionCaptureLogsLevel takes a BugseeLogLevel and drops every line more verbose than
it. The default, BugseeLogLevelVerbose, keeps everything; BugseeLogLevelWarning keeps
warnings and errors only. The level is applied before your filter, so the filter never sees the
dropped lines.
- Objective-C
- Swift
[Bugsee launchWithToken:@"<your_app_token>" andOptions:@{
BugseeOptionCaptureLogsLevel : @(BugseeLogLevelWarning),
}];
Bugsee.launch(token: "<your_app_token>", dictionaryOptions: [
BugseeOptionCaptureLogsLevel: BugseeLogLevelWarning.rawValue,
])
Filtering logs
A log filter receives every line before it is recorded, as a BugseeLogEvent. Change its
text (or its level, subsystem and category) and pass it to the decision block, or pass
nil to drop the line. A line whose text you set to an empty string is dropped too.
Set the filter with a block:
- Objective-C
- Swift
NSRegularExpression *regex =
[NSRegularExpression regularExpressionWithPattern:@"access_token=[0-9a-z\\-]*"
options:NSRegularExpressionCaseInsensitive
error:nil];
[Bugsee setLogEventFilter:^(BugseeLogEvent *event, BugseeLogFilterDecisionBlock decision) {
if ([event.text containsString:@"password"]) {
decision(nil); // drop the line
return;
}
event.text = [regex stringByReplacingMatchesInString:event.text
options:0
range:NSMakeRange(0, event.text.length)
withTemplate:@"access_token=<redacted>"];
decision(event);
}];
// Remove the filter
[Bugsee setLogEventFilter:nil];
let regex = try! NSRegularExpression(pattern: "access_token=[0-9a-z\\-]*",
options: .caseInsensitive)
Bugsee.setLogEventFilter { event, decision in
if event.text.contains("password") {
decision(nil) // drop the line
return
}
let range = NSRange(event.text.startIndex..., in: event.text)
event.text = regex.stringByReplacingMatches(in: event.text, options: [], range: range,
withTemplate: "access_token=<redacted>")
decision(event)
}
// Remove the filter
Bugsee.setLogEventFilter(nil)
Or implement the filter in your BugseeDelegate:
- Objective-C
- Swift
- (void)bugseeFilterLog:(BugseeLogEvent *)log
completionHandler:(BugseeLogFilterDecisionBlock)decisionBlock {
if ([log.text containsString:@"password"]) {
decisionBlock(nil);
return;
}
decisionBlock(log);
}
// ...somewhere within the class
[Bugsee sharedInstance].delegate = self;
class BugseeHandler: NSObject, BugseeDelegate {
func bugsee(filterLog log: BugseeLogEvent,
completionHandler decisionBlock: @escaping BugseeLogFilterDecisionBlock) {
if log.text.contains("password") {
decisionBlock(nil)
return
}
decisionBlock(log)
}
}
// ...somewhere in your setup code
Bugsee.sharedInstance()?.delegate = bugseeHandler
- If both are set, the block filter is used and the delegate method is not called.
- Call the decision block once, within 10 seconds. Past that the line is dropped, and a later call is ignored. The filter may finish on any thread.
- Lines sent with
Bugsee.logskip the filter, because your code wrote them. To run such a line through the filter, send it withlog:level:requiresFiltering:andrequiresFilteringset toYES:
- Objective-C
- Swift
[Bugsee log:message level:BugseeLogLevelInfo requiresFiltering:YES];
Bugsee.log(message, level: BugseeLogLevelInfo, requiresFiltering: true)
More about console logs: Console logs.