Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ambiguous loggers; use clogger and flogger instead
/// TODO: is something like Loggable.Console / Loggable.File possible in Swift - single namespace inside a target?
// A console logger
protocol ConsoleLoggable {
var clogger: ConsoleLoggerProtocol { get }
}
extension ConsoleLoggable {
var clogger: ConsoleLoggerProtocol {
return DefaultConsoleLogger()
}
}
protocol ConsoleLoggerProtocol {
func log()
}
struct DefaultConsoleLogger: ConsoleLoggerProtocol {
func log() {
print("CONSOLE log...")
}
}
// A console logger
protocol FileLoggable {
var flogger: FileLoggerProtocol { get }
}
extension FileLoggable {
var flogger: FileLoggerProtocol {
return DefaultFileLogger()
}
}
protocol FileLoggerProtocol {
func log()
}
struct DefaultFileLogger: FileLoggerProtocol {
func log() {
print("FILE log...")
}
}
// Test
struct LoggerTest: ConsoleLoggable, FileLoggable {
//struct LoggerTest: FileLoggable, ConsoleLoggable {
func test() {
clogger.log()
flogger.log()
}
}
LoggerTest().test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment