Skip to content

Commit

Permalink
Add MXLog.dev for faster print debugging. (#3694)
Browse files Browse the repository at this point in the history
* Add MXLog.dev for easier print debugging.

* Remove the unused context parameter on MXLog.
  • Loading branch information
pixlwave authored Jan 22, 2025
1 parent 909ee4a commit f194285
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions ElementX/Sources/Other/Logging/MXLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,73 +51,80 @@ enum MXLog {
file: String = #file,
function: String = #function,
line: Int = #line,
column: Int = #column,
context: Any? = nil) {
log(message, level: .trace, file: file, function: function, line: line, column: column, context: context)
column: Int = #column) {
log(message, level: .trace, file: file, function: function, line: line, column: column)
}

static func debug(_ message: Any,
file: String = #file,
function: String = #function,
line: Int = #line,
column: Int = #column,
context: Any? = nil) {
log(message, level: .debug, file: file, function: function, line: line, column: column, context: context)
column: Int = #column) {
log(message, level: .debug, file: file, function: function, line: line, column: column)
}

static func info(_ message: Any,
file: String = #file,
function: String = #function,
line: Int = #line,
column: Int = #column,
context: Any? = nil) {
log(message, level: .info, file: file, function: function, line: line, column: column, context: context)
column: Int = #column) {
log(message, level: .info, file: file, function: function, line: line, column: column)
}

static func warning(_ message: Any,
file: String = #file,
function: String = #function,
line: Int = #line,
column: Int = #column,
context: Any? = nil) {
log(message, level: .warn, file: file, function: function, line: line, column: column, context: context)
column: Int = #column) {
log(message, level: .warn, file: file, function: function, line: line, column: column)
}

/// Log error with additional details
/// Log error.
///
/// - Parameters:
/// - 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,
file: String = #file,
function: String = #function,
line: Int = #line,
column: Int = #column,
context: Any? = nil) {
log(message, level: .error, file: file, function: function, line: line, column: column, context: context)
column: Int = #column) {
log(message, level: .error, file: file, function: function, line: line, column: column)
}

/// Log failure with additional details
/// Log failure.
///
/// A failure is any type of programming error which should never occur in production. In `DEBUG` configuration
/// any failure will raise `assertionFailure`
///
/// - Parameters:
/// - 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,
file: String = #file,
function: String = #function,
line: Int = #line,
column: Int = #column,
context: Any? = nil) {
log(message, level: .error, file: file, function: function, line: line, column: column, context: context)
column: Int = #column) {
log(message, level: .error, file: file, function: function, line: line, column: column)

#if DEBUG
assertionFailure("\(message)")
#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

// periphery:ignore:parameters function,column
Expand All @@ -138,14 +145,13 @@ enum MXLog {
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,
level: LogLevel,
file: String = #file,
function: String = #function,
line: Int = #line,
column: Int = #column,
context: Any? = nil) {
column: Int = #column) {
guard didConfigureOnce else {
return
}
Expand Down

0 comments on commit f194285

Please sign in to comment.