Created
March 1, 2019 14:10
-
-
Save superarts/86b2c8a5c7cfbbb03da79e1d6fccc9ec to your computer and use it in GitHub Desktop.
Ambiguous loggers; use clogger and flogger instead
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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