But am stuck designing it properly.
the goal is to lift logging up to the api layer. so that one can rely on serverless architecture.
should it have a protocol?
conform your struct, a representable of your log message,
- have the option to construct my catalogue of logs.
- deterministic cases, deterministic behaviour
- keep the logging behaviour centralized.
- simply interact with other apis.
- register the handler, and pass the array of logs to create/ingest along
heres the gist:
extension LogType {
enum Base: String, Sendable {
case authentication
}
public static let generic = Self(.generic)
}
struct MyLog: Encodable {
let timestamp: Date
let message: String
private enum CodingKeys: String, CodingKey {
case timestamp = "@timestamp"
case message
}
// let the log handler create a log entry
public static func authentication(timestamp: String, message: String) -> Self {
.init(backing: .init(logType: .generic, timestamp: timestamp, message: message))
}
// other functions.
}
// call it
...somecode
MyLog.authentication("\(personID) has authenticated")
... so on and so forth
but to interface with a database or another medium of storage is a bit trickier. any suggestions?