Log improvements
This commit is contained in:
parent
9d9ac85c62
commit
f0d658d0e3
1 changed files with 12 additions and 12 deletions
|
|
@ -1,14 +1,14 @@
|
|||
import Foundation
|
||||
|
||||
struct Log {
|
||||
static var dateFormat = "yyyy-MM-dd hh:mm:ss.SSSSSSZ"
|
||||
static var dateFormatter: DateFormatter {
|
||||
private static let dateFormat = "yyyy-MM-dd hh:mm:ss.SSSSSSZ"
|
||||
private static let dateFormatter: DateFormatter = {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = dateFormat
|
||||
formatter.locale = Locale.current
|
||||
formatter.timeZone = TimeZone.current
|
||||
formatter.locale = .current
|
||||
formatter.timeZone = .current
|
||||
return formatter
|
||||
}
|
||||
}()
|
||||
|
||||
static func d(_ tag: String, _ message: String, _ other: Any?...) {
|
||||
log(.debug, tag, message, other)
|
||||
|
|
@ -26,22 +26,22 @@ struct Log {
|
|||
log(.error, tag, message, other)
|
||||
}
|
||||
|
||||
static func log(_ level: LogLevel, _ tag: String, _ message: String, _ other: Any?...) {
|
||||
private static func log(_ level: LogLevel, _ tag: String, _ message: String, _ other: Any?...) {
|
||||
print("\(dateStr()) ntfyApp [\(levelStr(level))] \(tag): \(message)")
|
||||
if !other.isEmpty {
|
||||
other.forEach { o in
|
||||
if o != nil {
|
||||
print(" ", o!)
|
||||
if let o = o {
|
||||
print(" ", o)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static func dateStr() -> String {
|
||||
return dateFormatter.string(from: Date())
|
||||
private static func dateStr() -> String {
|
||||
dateFormatter.string(from: Date())
|
||||
}
|
||||
|
||||
static func levelStr(_ level: LogLevel) -> String {
|
||||
private static func levelStr(_ level: LogLevel) -> String {
|
||||
switch level {
|
||||
case .debug: return "DEBUG"
|
||||
case .info: return "INFO"
|
||||
|
|
@ -51,7 +51,7 @@ struct Log {
|
|||
}
|
||||
}
|
||||
|
||||
enum LogLevel {
|
||||
private enum LogLevel {
|
||||
case debug
|
||||
case info
|
||||
case warning
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue