Various logging fixes (#164)

Various logging fixes:
* imported the ObjCWrapper and updated the MXLogger. Also added back support for app containers
* updated MXLog.swift from El and fixed/improved its logging format
* updated most app log strings
* Remove unnecessary swiftlint rule
* Various tweaks following code review
* Added back type annoation on MXLogger logFiles method
* Fix generated Swift-ObjC header name
This commit is contained in:
Stefan Ceriu
2022-08-30 18:05:21 +03:00
committed by GitHub
parent c92e6c2092
commit 39be67cec6
24 changed files with 288 additions and 102 deletions
+55 -29
View File
@@ -67,8 +67,8 @@ private var logger: SwiftyBeaver.Type = {
}
public static func verbose(_ message: @autoclosure () -> Any,
_ file: String = #file,
_ function: String = #function,
file: String = #file,
function: String = #function,
line: Int = #line,
context: Any? = nil) {
logger.verbose(message(), file, function, line: line, context: context)
@@ -80,8 +80,8 @@ private var logger: SwiftyBeaver.Type = {
}
public static func debug(_ message: @autoclosure () -> Any,
_ file: String = #file,
_ function: String = #function,
file: String = #file,
function: String = #function,
line: Int = #line,
context: Any? = nil) {
logger.debug(message(), file, function, line: line, context: context)
@@ -93,8 +93,8 @@ private var logger: SwiftyBeaver.Type = {
}
public static func info(_ message: @autoclosure () -> Any,
_ file: String = #file,
_ function: String = #function,
file: String = #file,
function: String = #function,
line: Int = #line,
context: Any? = nil) {
logger.info(message(), file, function, line: line, context: context)
@@ -106,8 +106,8 @@ private var logger: SwiftyBeaver.Type = {
}
public static func warning(_ message: @autoclosure () -> Any,
_ file: String = #file,
_ function: String = #function,
file: String = #file,
function: String = #function,
line: Int = #line,
context: Any? = nil) {
logger.warning(message(), file, function, line: line, context: context)
@@ -118,32 +118,57 @@ private var logger: SwiftyBeaver.Type = {
logger.warning(message, file, function, line: line)
}
public static func error(_ message: @autoclosure () -> Any,
_ file: String = #file,
_ function: String = #function,
/// Log error with additional details
///
/// - 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
public static func error(_ message: String,
file: String = #file,
function: String = #function,
line: Int = #line,
context: Any? = nil) {
logger.error(message(), file, function, line: line, context: context)
logger.error(message, file, function, line: line, context: context)
}
@available(swift, obsoleted: 5.4)
@objc public static func logError(_ message: String, file: String, function: String, line: Int) {
logger.error(message, file, function, line: line)
@objc public static func logError(_ message: String,
file: String,
function: String,
line: Int,
context: Any? = nil) {
logger.error(message, file, function, line: line, context: context)
}
public static func failure(_ message: @autoclosure () -> Any,
_ file: String = #file,
_ function: String = #function,
/// Log failure with additional details
///
/// 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
public static func failure(_ message: String,
file: String = #file,
function: String = #function,
line: Int = #line,
context: Any? = nil) {
logger.error(message(), file, function, line: line, context: context)
assertionFailure("\(message())")
logger.error(message, file, function, line: line, context: context)
#if DEBUG
assertionFailure("\(message)")
#endif
}
@available(swift, obsoleted: 5.4)
@objc public static func logFailure(_ message: String, file: String, function: String, line: Int) {
logger.error(message, file, function, line: line)
assertionFailure(message)
@objc public static func logFailure(_ message: String,
file: String,
function: String,
line: Int,
context: Any? = nil) {
logger.error(message, file, function, line: line, context: context)
#if DEBUG
assertionFailure("\(message)")
#endif
}
// MARK: - Private
@@ -152,24 +177,27 @@ private var logger: SwiftyBeaver.Type = {
if let subLogName = configuration.subLogName {
MXLogger.setSubLogName(subLogName)
}
MXLogger.redirectNSLog(toFiles: configuration.redirectLogsToFiles,
numberOfFiles: configuration.maxLogFilesCount,
sizeLimit: configuration.logFilesSizeLimit)
guard configuration.logLevel != .none else {
logger.removeAllDestinations()
return
}
logger.removeAllDestinations()
let consoleDestination = ConsoleDestination()
consoleDestination.useNSLog = true
consoleDestination.asynchronously = false
consoleDestination.format = "$M"
consoleDestination.format = "$C$N.$F:$l $M $X$c" // See https://docs.swiftybeaver.com/article/20-custom-format
consoleDestination.levelColor.verbose = ""
consoleDestination.levelColor.debug = ""
consoleDestination.levelColor.info = ""
consoleDestination.levelColor.warning = "⚠️"
consoleDestination.levelColor.error = "🚨"
consoleDestination.levelColor.warning = "⚠️ "
consoleDestination.levelColor.error = "🚨 "
switch configuration.logLevel {
case .verbose:
@@ -185,8 +213,6 @@ private var logger: SwiftyBeaver.Type = {
case .none:
break
}
logger.removeAllDestinations()
logger.addDestination(consoleDestination)
}
}