Last active
February 7, 2018 00:29
-
-
Save xicmiah/cc2b51f79a8f57af5166b41f9fee1fd0 to your computer and use it in GitHub Desktop.
Revisions
-
xicmiah revised this gist
Feb 7, 2018 . 3 changed files with 6 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,8 @@ object Main extends App with PosLogging { Logger(getClass).info("Goodbye, MDC") logger.debug(s"Messages are still by-name: ${println("this only runs on debug")}") logger.info("Hello from main") } 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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ </encoder> </appender> <root level="info"> <appender-ref ref="STDOUT" /> </root> </configuration> 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ [0m[[0minfo[0m] [0mLoading project definition from /Users/miah/Code/scratchpad/project[0m [0m[[0minfo[0m] [0mSet current project to Hello (in build file:/Users/miah/Code/scratchpad/)[0m [0m[[0minfo[0m] [0mRunning example.Main [0m [pos=example.Foo#doStuff:18] INFO example.Foo: Hi from Foo [] INFO example.Main$: Goodbye, MDC [pos=example.Main:13] INFO example.Main$: Hello from main [0m[[32msuccess[0m] [0mTotal time: 1 s, completed Feb 7, 2018 1:28:57 AM[0m -
xicmiah revised this gist
Feb 6, 2018 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ [0m[[0minfo[0m] [0mLoading project definition from /Users/miah/Code/scratchpad/project[0m [0m[[0minfo[0m] [0mSet current project to Hello (in build file:/Users/miah/Code/scratchpad/)[0m [0m[[0minfo[0m] [0mRunning example.Main [0m [pos=example.Foo#doStuff:16] INFO example.Foo: Hi from Foo [] INFO example.Main$: Goodbye, MDC [pos=example.Main:11] INFO example.Main$: Hello from main [0m[[32msuccess[0m] [0mTotal time: 1 s, completed Feb 7, 2018 12:48:23 AM[0m -
xicmiah revised this gist
Feb 6, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,9 +6,9 @@ import org.slf4j.MDC object Main extends App with PosLogging { new Foo().doStuff() Logger(getClass).info("Goodbye, MDC") logger.info("Hello from main") } class Foo extends PosLogging { -
xicmiah revised this gist
Feb 6, 2018 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,8 @@ object Main extends App with PosLogging { new Foo().doStuff() logger.info("Hello from main") Logger(getClass).info("Goodbye, MDC") } class Foo extends PosLogging { @@ -35,5 +37,7 @@ object PosLogging { MDC.put("pos", pos.value) originalMsg } override def afterLog(a: Pos): Unit = MDC.remove("pos") } } -
xicmiah revised this gist
Feb 6, 2018 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ <configuration> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>[%mdc] %level %logger{36}: %msg%n</pattern> <!-- For visible MDC --> </encoder> </appender> 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 charactersOriginal file line number Diff line number Diff line change @@ -3,4 +3,4 @@ [0m[[0minfo[0m] [0mRunning example.Main [0m [pos=example.Foo#doStuff:14] INFO example.Foo: Hi from Foo [pos=example.Main:9] INFO example.Main$: Hello from main [0m[[32msuccess[0m] [0mTotal time: 1 s, completed Feb 6, 2018 11:54:36 PM[0m -
xicmiah revised this gist
Feb 6, 2018 . 2 changed files with 5 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,6 @@ package example import com.typesafe.scalalogging._ import org.slf4j.MDC object Main extends App with PosLogging { new Foo().doStuff() @@ -21,6 +20,8 @@ trait PosLogging { } object PosLogging { import sourcecode._ /** Simple wrapper to get both Enclosing and Line */ final case class Pos(enclosing: Enclosing, line: Line) { def value = s"${enclosing.value}:${line.value}" 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ [0m[[0minfo[0m] [0mLoading project definition from /Users/miah/Code/scratchpad/project[0m [0m[[0minfo[0m] [0mSet current project to Hello (in build file:/Users/miah/Code/scratchpad/)[0m [0m[[0minfo[0m] [0mRunning example.Main [0m [pos=example.Foo#doStuff:14] INFO example.Foo: Hi from Foo [pos=example.Main:9] INFO example.Main$: Hello from main [0m[[32msuccess[0m] [0mTotal time: 1 s, completed Feb 6, 2018 11:53:05 PM[0m -
xicmiah revised this gist
Feb 6, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ lazy val root = (project in file(".")) name := "Hello", libraryDependencies ++= Seq( "com.typesafe.scala-logging" %% "scala-logging" % "3.8.0-SNAPSHOT", // nightly :(, used for Logger#takingImplicit "ch.qos.logback" % "logback-classic" % "1.2.3", "com.lihaoyi" %% "sourcecode" % "0.1.4") ) -
xicmiah revised this gist
Feb 6, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ lazy val root = (project in file(".")) name := "Hello", libraryDependencies ++= Seq( "com.typesafe.scala-logging" %% "scala-logging" % "3.8.0-SNAPSHOT", // nightly :(, used for Logger$takingImplicit "ch.qos.logback" % "logback-classic" % "1.2.3", "com.lihaoyi" %% "sourcecode" % "0.1.4") ) -
xicmiah revised this gist
Feb 6, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ lazy val root = (project in file(".")) name := "Hello", libraryDependencies ++= Seq( "com.typesafe.scala-logging" %% "scala-logging" % "3.8.0-SNAPSHOT", // nightly :( "ch.qos.logback" % "logback-classic" % "1.2.3", "com.lihaoyi" %% "sourcecode" % "0.1.4") ) -
xicmiah revised this gist
Feb 6, 2018 . No changes.There are no files selected for viewing
-
xicmiah created this gist
Feb 6, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ package example import com.typesafe.scalalogging._ import org.slf4j.MDC import sourcecode._ object Main extends App with PosLogging { new Foo().doStuff() logger.info("Hello from main") } class Foo extends PosLogging { def doStuff(): Unit = { logger.info("Hi from Foo") } } trait PosLogging { protected val logger: LoggerTakingImplicit[PosLogging.Pos] = Logger.takingImplicit(getClass)(PosLogging.CanLogPos) } object PosLogging { /** Simple wrapper to get both Enclosing and Line */ final case class Pos(enclosing: Enclosing, line: Line) { def value = s"${enclosing.value}:${line.value}" } object Pos { implicit def generate(implicit enclosing: Enclosing, line: Line): Pos = Pos(enclosing, line) } implicit case object CanLogPos extends CanLog[Pos] { override def logMessage(originalMsg: String, pos: Pos): String = { MDC.put("pos", pos.value) originalMsg } } } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ lazy val root = (project in file(".")) .settings( inThisBuild(List( organization := "com.example", scalaVersion := "2.12.4", version := "0.1.0-SNAPSHOT" )), name := "Hello", libraryDependencies ++= Seq( "com.typesafe.scala-logging" %% "scala-logging" % "3.8.0-SNAPSHOT", "ch.qos.logback" % "logback-classic" % "1.2.3", "com.lihaoyi" %% "sourcecode" % "0.1.4") ) 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ <configuration> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>[%mdc] %level %logger{36}: %msg%n</pattern> </encoder> </appender> <root level="debug"> <appender-ref ref="STDOUT" /> </root> </configuration> 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ [0m[[0minfo[0m] [0mLoading project definition from /Users/miah/Code/scratchpad/project[0m [0m[[0minfo[0m] [0mSet current project to Hello (in build file:/Users/miah/Code/scratchpad/)[0m [0m[[0minfo[0m] [0mRunning example.Main [0m [pos=example.Foo#doStuff:15] INFO example.Foo: Hi from Foo [pos=example.Main:10] INFO example.Main$: Hello from main [0m[[32msuccess[0m] [0mTotal time: 1 s, completed Feb 6, 2018 11:44:09 PM[0m