Add MXLog.dev for faster print debugging. (#3694)

* Add MXLog.dev for easier print debugging.

* Remove the unused context parameter on MXLog.
This commit is contained in:
Doug 2025-01-22 09:18:12 +00:00 committed by GitHub
parent 909ee4abf2
commit f194285250
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -51,73 +51,80 @@ enum MXLog {
file: String = #file, file: String = #file,
function: String = #function, function: String = #function,
line: Int = #line, line: Int = #line,
column: Int = #column, column: Int = #column) {
context: Any? = nil) { log(message, level: .trace, file: file, function: function, line: line, column: column)
log(message, level: .trace, file: file, function: function, line: line, column: column, context: context)
} }
static func debug(_ message: Any, static func debug(_ message: Any,
file: String = #file, file: String = #file,
function: String = #function, function: String = #function,
line: Int = #line, line: Int = #line,
column: Int = #column, column: Int = #column) {
context: Any? = nil) { log(message, level: .debug, file: file, function: function, line: line, column: column)
log(message, level: .debug, file: file, function: function, line: line, column: column, context: context)
} }
static func info(_ message: Any, static func info(_ message: Any,
file: String = #file, file: String = #file,
function: String = #function, function: String = #function,
line: Int = #line, line: Int = #line,
column: Int = #column, column: Int = #column) {
context: Any? = nil) { log(message, level: .info, file: file, function: function, line: line, column: column)
log(message, level: .info, file: file, function: function, line: line, column: column, context: context)
} }
static func warning(_ message: Any, static func warning(_ message: Any,
file: String = #file, file: String = #file,
function: String = #function, function: String = #function,
line: Int = #line, line: Int = #line,
column: Int = #column, column: Int = #column) {
context: Any? = nil) { log(message, level: .warn, file: file, function: function, line: line, column: column)
log(message, level: .warn, file: file, function: function, line: line, column: column, context: context)
} }
/// Log error with additional details /// Log error.
/// ///
/// - Parameters: /// - Parameters:
/// - message: Description of the error without any variables (this is to improve error aggregations by type) /// - message: Description of the error without any variables (this is to improve error aggregations by type)
/// - context: Additional context-dependent details about the issue
static func error(_ message: Any, static func error(_ message: Any,
file: String = #file, file: String = #file,
function: String = #function, function: String = #function,
line: Int = #line, line: Int = #line,
column: Int = #column, column: Int = #column) {
context: Any? = nil) { log(message, level: .error, file: file, function: function, line: line, column: column)
log(message, level: .error, file: file, function: function, line: line, column: column, context: context)
} }
/// Log failure with additional details /// Log failure.
/// ///
/// A failure is any type of programming error which should never occur in production. In `DEBUG` configuration /// A failure is any type of programming error which should never occur in production. In `DEBUG` configuration
/// any failure will raise `assertionFailure` /// any failure will raise `assertionFailure`
/// ///
/// - Parameters: /// - Parameters:
/// - message: Description of the error without any variables (this is to improve error aggregations by type) /// - message: Description of the error without any variables (this is to improve error aggregations by type)
/// - context: Additional context-dependent details about the issue
static func failure(_ message: Any, static func failure(_ message: Any,
file: String = #file, file: String = #file,
function: String = #function, function: String = #function,
line: Int = #line, line: Int = #line,
column: Int = #column, column: Int = #column) {
context: Any? = nil) { log(message, level: .error, file: file, function: function, line: line, column: column)
log(message, level: .error, file: file, function: function, line: line, column: column, context: context)
#if DEBUG #if DEBUG
assertionFailure("\(message)") assertionFailure("\(message)")
#endif #endif
} }
#if DEBUG
private static let devPrefix = URL.documentsDirectory.pathComponents[2].uppercased()
/// A helper method for print debugging, only available on debug builds.
///
/// When running on the simulator this will log `[USERNAME] message` so that
/// you can easily filter the Xcode console to see only the logs you're interested in.
static func dev(_ message: Any,
file: String = #file,
function: String = #function,
line: Int = #line,
column: Int = #column) {
log("[\(devPrefix)] \(message)", level: .info, file: file, function: function, line: line, column: column)
}
#endif
// MARK: - Private // MARK: - Private
// periphery:ignore:parameters function,column // periphery:ignore:parameters function,column
@ -138,14 +145,13 @@ enum MXLog {
return Span(file: file, line: UInt32(line), level: level.rustLogLevel, target: currentTarget, name: name) return Span(file: file, line: UInt32(line), level: level.rustLogLevel, target: currentTarget, name: name)
} }
// periphery:ignore:parameters function,column,context // periphery:ignore:parameters function,column
private static func log(_ message: Any, private static func log(_ message: Any,
level: LogLevel, level: LogLevel,
file: String = #file, file: String = #file,
function: String = #function, function: String = #function,
line: Int = #line, line: Int = #line,
column: Int = #column, column: Int = #column) {
context: Any? = nil) {
guard didConfigureOnce else { guard didConfigureOnce else {
return return
} }