Created
September 4, 2015 14:40
-
-
Save nuclearace/120907f56abbfc8b369b to your computer and use it in GitHub Desktop.
Logging
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
| trait Logger { | |
| def log(msg: String)(implicit logType: String) = { | |
| println(s"${logType}: ${msg}") | |
| } | |
| } | |
| object DefaultLogger extends Logger | |
| class SomeClass { | |
| implicit val logType = "SomeClass" | |
| DefaultLogger log "Creating SomeClass" | |
| } | |
| object Main extends App { | |
| val s = new SomeClass | |
| } |
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
| protocol Logger { | |
| func log(msg: String, logType: String) | |
| } | |
| extension Logger { | |
| func log(msg: String, logType: String) { | |
| print("\(logType): \(msg)") | |
| } | |
| } | |
| struct DefaultLogger: Logger { | |
| } | |
| class SomeClass { | |
| let logType = "SomeClass" | |
| init() { | |
| defLogger.log("Creating SomeClass", logType: "SomeClass") | |
| } | |
| } | |
| var defLogger = DefaultLogger() | |
| let a = SomeClass() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment