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