-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No Bug: Add Log handler and debug menu for JitsiSDK logs. (brave/brav…
- Loading branch information
Showing
5 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
Sources/Brave/Frontend/Settings/Debug/BraveTalkLogsViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import UIKit | ||
import os.log | ||
import OSLog | ||
import SnapKit | ||
|
||
public class BraveTalkLogsViewController: UIViewController { | ||
|
||
private var logsTextView = UITextView() | ||
|
||
public override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
logsTextView.isEditable = false | ||
view.addSubview(logsTextView) | ||
logsTextView.snp.makeConstraints { | ||
$0.edges.equalToSuperview() | ||
} | ||
|
||
logsTextView.text = getLogs() | ||
|
||
let shareButton = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(shareLogs)) | ||
navigationItem.rightBarButtonItem = shareButton | ||
} | ||
|
||
@objc private func shareLogs() { | ||
do { | ||
let fileURL = try createTemporaryLogFile() | ||
let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil) | ||
present(activityViewController, animated: true) | ||
} catch { | ||
Logger.module.error("Error while creating the log file: \(error.localizedDescription, privacy: .public)") | ||
} | ||
} | ||
|
||
private func createTemporaryLogFile() throws -> URL { | ||
let logsString = getLogs() | ||
let temporaryDirectoryURL = FileManager.default.temporaryDirectory | ||
let logFileURL = temporaryDirectoryURL.appendingPathComponent("Logs.txt") | ||
|
||
try logsString.write(to: logFileURL, atomically: true, encoding: .utf8) | ||
return logFileURL | ||
} | ||
|
||
private func getLogs() -> String { | ||
do { | ||
let store = try OSLogStore(scope: .currentProcessIdentifier) | ||
|
||
return try store | ||
.getEntries() | ||
.compactMap { $0 as? OSLogEntryLog } | ||
.filter { $0.category == "BraveTalk" && $0.subsystem == Bundle.main.bundleIdentifier } | ||
.map { "[\($0.date.formatted())] \($0.composedMessage)" } | ||
.joined(separator: "\n") | ||
} catch { | ||
Logger.module.error("\(error.localizedDescription, privacy: .public)") | ||
} | ||
|
||
return "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import Foundation | ||
import Shared | ||
import JitsiMeetSDK | ||
import os.log | ||
|
||
class BraveTalkJitsiLogHandler: JitsiMeetBaseLogHandler { | ||
|
||
override func logVerbose(_ msg: String!) { | ||
Logger.module.debug("[verbose]: \(msg, privacy: .public)") | ||
} | ||
|
||
override func logDebug(_ msg: String!) { | ||
Logger.module.debug("\(msg, privacy: .public)") | ||
} | ||
|
||
override func logInfo(_ msg: String!) { | ||
Logger.module.info("\(msg, privacy: .public)") | ||
} | ||
|
||
override func logWarn(_ msg: String!) { | ||
Logger.module.warning("\(msg, privacy: .public)") | ||
} | ||
|
||
override func logError(_ msg: String!) { | ||
Logger.module.error("\(msg, privacy: .public)") | ||
} | ||
} |