import Foundation

struct LogEntry: Identifiable {

    let id: TimeInterval

    let date: Date

    let level: Log.Level

    let message: String

    init(date: Date = Date(), level: Log.Level, message: String) {
        self.id = date.timeIntervalSince1970
        self.date = date
        self.level = level
        self.message = message
    }
}

private let df: DateFormatter = {
    let df = DateFormatter()
    df.dateStyle = .short
    df.timeStyle = .medium
    return df
}()

extension LogEntry: CustomStringConvertible {

    var description: String {
        "[\(df.string(from: date))][\(level.rawValue)] \(message)"
    }
}
