-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from CovidTrackerFr/develop
Release 1.3 - Merge develop into main
- Loading branch information
Showing
65 changed files
with
2,507 additions
and
534 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ disabled_rules: | |
- nesting | ||
- identifier_name | ||
line_length: 200 | ||
file_length: 800 | ||
type_body_length: 500 |
Large diffs are not rendered by default.
Oops, something went wrong.
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,152 @@ | ||
// | ||
// Logger.swift | ||
// ViteMaDose | ||
// | ||
// Created by Victor Sarda on 09/05/2021. | ||
// | ||
|
||
import Foundation | ||
/// Enum which maps an appropiate symbol which added as prefix for each log message | ||
/// | ||
/// - error: Log type error | ||
/// - info: Log type info | ||
/// - debug: Log type debug | ||
/// - verbose: Log type verbose | ||
/// - warning: Log type warning | ||
/// - severe: Log type severe | ||
enum LogEvent: String { | ||
case e = "[🚨]" // error | ||
case i = "[ℹ️]" // info | ||
case d = "[💬]" // debug | ||
case v = "[🔬]" // verbose | ||
case w = "[⚠️]" // warning | ||
case s = "[🔥]" // severe | ||
} | ||
|
||
/// Wrapping Swift.print() within DEBUG flag | ||
/// | ||
/// - Note: *print()* might cause [security vulnerabilities](https://codifiedsecurity.com/mobile-app-security-testing-checklist-ios/) | ||
/// | ||
/// - Parameter object: The object which is to be logged | ||
/// | ||
func print(_ object: Any) { | ||
// Only allowing in DEBUG mode | ||
#if DEBUG | ||
Swift.print(object) | ||
#endif | ||
} | ||
|
||
final class Log { | ||
|
||
static var dateFormat = "yyyy-MM-dd hh:mm:ss" | ||
static var dateFormatter: DateFormatter { | ||
let formatter = DateFormatter() | ||
formatter.dateFormat = dateFormat | ||
formatter.locale = Locale.current | ||
formatter.timeZone = TimeZone.current | ||
return formatter | ||
} | ||
|
||
private static var isLoggingEnabled: Bool { | ||
#if DEBUG | ||
return true | ||
#else | ||
return false | ||
#endif | ||
} | ||
|
||
// MARK: - Loging methods | ||
|
||
/// Logs error messages on console with prefix [🚨] | ||
/// | ||
/// - Parameters: | ||
/// - object: Object or message to be logged | ||
/// - filename: File name from where loggin to be done | ||
/// - line: Line number in file from where the logging is done | ||
/// - column: Column number of the log message | ||
/// - funcName: Name of the function from where the logging is done | ||
class func e(_ object: Any, filename: String = #file, line: Int = #line, column: Int = #column, funcName: String = #function) { | ||
guard isLoggingEnabled else { return } | ||
print("\(Date().toString()) \(LogEvent.e.rawValue)[\(sourceFileName(filePath: filename))]:\(line) \(column) \(funcName) -> \(object)") | ||
} | ||
|
||
/// Logs info messages on console with prefix [ℹ️] | ||
/// | ||
/// - Parameters: | ||
/// - object: Object or message to be logged | ||
/// - filename: File name from where loggin to be done | ||
/// - line: Line number in file from where the logging is done | ||
/// - column: Column number of the log message | ||
/// - funcName: Name of the function from where the logging is done | ||
class func i (_ object: Any, filename: String = #file, line: Int = #line, column: Int = #column, funcName: String = #function) { | ||
guard isLoggingEnabled else { return } | ||
print("\(Date().toString()) \(LogEvent.i.rawValue)[\(sourceFileName(filePath: filename))]:\(line) \(column) \(funcName) -> \(object)") | ||
} | ||
|
||
/// Logs debug messages on console with prefix [💬] | ||
/// | ||
/// - Parameters: | ||
/// - object: Object or message to be logged | ||
/// - filename: File name from where loggin to be done | ||
/// - line: Line number in file from where the logging is done | ||
/// - column: Column number of the log message | ||
/// - funcName: Name of the function from where the logging is done | ||
class func d(_ object: Any, filename: String = #file, line: Int = #line, column: Int = #column, funcName: String = #function) { | ||
guard isLoggingEnabled else { return } | ||
print("\(Date().toString()) \(LogEvent.d.rawValue)[\(sourceFileName(filePath: filename))]:\(line) \(column) \(funcName) -> \(object)") | ||
} | ||
|
||
/// Logs messages verbosely on console with prefix [🔬] | ||
/// | ||
/// - Parameters: | ||
/// - object: Object or message to be logged | ||
/// - filename: File name from where loggin to be done | ||
/// - line: Line number in file from where the logging is done | ||
/// - column: Column number of the log message | ||
/// - funcName: Name of the function from where the logging is done | ||
class func v(_ object: Any, filename: String = #file, line: Int = #line, column: Int = #column, funcName: String = #function) { | ||
guard isLoggingEnabled else { return } | ||
print("\(Date().toString()) \(LogEvent.v.rawValue)[\(sourceFileName(filePath: filename))]:\(line) \(column) \(funcName) -> \(object)") | ||
} | ||
|
||
/// Logs warnings verbosely on console with prefix [⚠️] | ||
/// | ||
/// - Parameters: | ||
/// - object: Object or message to be logged | ||
/// - filename: File name from where loggin to be done | ||
/// - line: Line number in file from where the logging is done | ||
/// - column: Column number of the log message | ||
/// - funcName: Name of the function from where the logging is done | ||
class func w(_ object: Any, filename: String = #file, line: Int = #line, column: Int = #column, funcName: String = #function) { | ||
guard isLoggingEnabled else { return } | ||
print("\(Date().toString()) \(LogEvent.w.rawValue)[\(sourceFileName(filePath: filename))]:\(line) \(column) \(funcName) -> \(object)") | ||
} | ||
|
||
/// Logs severe events on console with prefix [🔥] | ||
/// | ||
/// - Parameters: | ||
/// - object: Object or message to be logged | ||
/// - filename: File name from where loggin to be done | ||
/// - line: Line number in file from where the logging is done | ||
/// - column: Column number of the log message | ||
/// - funcName: Name of the function from where the logging is done | ||
class func s(_ object: Any, filename: String = #file, line: Int = #line, column: Int = #column, funcName: String = #function) { | ||
guard isLoggingEnabled else { return } | ||
print("\(Date().toString()) \(LogEvent.s.rawValue)[\(sourceFileName(filePath: filename))]:\(line) \(column) \(funcName) -> \(object)") | ||
} | ||
|
||
/// Extract the file name from the file path | ||
/// | ||
/// - Parameter filePath: Full file path in bundle | ||
/// - Returns: File Name with extension | ||
private class func sourceFileName(filePath: String) -> String { | ||
let components = filePath.components(separatedBy: "/") | ||
return components.last ?? "" | ||
} | ||
} | ||
|
||
internal extension Date { | ||
func toString() -> String { | ||
return Log.dateFormatter.string(from: self as Date) | ||
} | ||
} |
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
Oops, something went wrong.