Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MXLog.dev for faster print debugging. #3694

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading