Fix flow logging more

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/86089b38
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/86089b38
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/86089b38

Branch: 
refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure
Commit: 86089b387153cb3dc66d8807efbfe5d9e761b01c
Parents: 0ab0156
Author: Mikael Ståldal <mikael.stal...@magine.com>
Authored: Wed Jun 29 21:08:12 2016 +0200
Committer: Mikael Ståldal <mikael.stal...@magine.com>
Committed: Wed Jun 29 21:11:15 2016 +0200

----------------------------------------------------------------------
 .../org/apache/logging/log4j/scala/Logger.scala      |  8 +-------
 .../org/apache/logging/log4j/scala/LoggerMacro.scala |  6 +++---
 .../org/apache/logging/log4j/scala/LoggerTest.scala  |  8 ++++----
 .../org/apache/logging/log4j/scala/Logger.scala      |  8 +-------
 .../org/apache/logging/log4j/scala/LoggerMacro.scala |  6 +++---
 .../org/apache/logging/log4j/scala/LoggerTest.scala  |  8 ++++----
 .../scala-api/src/main/resources/log4j2.xml          |  4 ++--
 .../logging/log4j/scalasample/LoggingApp.scala       | 15 +++++++++++++--
 8 files changed, 31 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86089b38/log4j-api-scala_2.10/src/main/scala/org/apache/logging/log4j/scala/Logger.scala
----------------------------------------------------------------------
diff --git 
a/log4j-api-scala_2.10/src/main/scala/org/apache/logging/log4j/scala/Logger.scala
 
b/log4j-api-scala_2.10/src/main/scala/org/apache/logging/log4j/scala/Logger.scala
index 5fa2cb7..4999bdb 100644
--- 
a/log4j-api-scala_2.10/src/main/scala/org/apache/logging/log4j/scala/Logger.scala
+++ 
b/log4j-api-scala_2.10/src/main/scala/org/apache/logging/log4j/scala/Logger.scala
@@ -454,7 +454,7 @@ class Logger private(val delegate: ExtendedLogger) {
     * @param params the parameters to the method.
     * @return The built `EntryMessage`
     */
-  def traceEntry(params: Any*): EntryMessage =
+  def traceEntry(params: AnyRef*): EntryMessage =
   macro LoggerMacro.traceEntryParams
 
   /**
@@ -623,10 +623,4 @@ class Logger private(val delegate: ExtendedLogger) {
     delegate.logMessage(FQCN, level, marker, 
messageFactory.newMessage(message), cause)
   }
 
-  // TODO inline this to get FQCN correct
-  /** Should normally not be used directly from application code, but needs to 
be public for access by macros. */
-  def traceEntryParams(params: Any*): EntryMessage = {
-    delegate.traceEntry(null: String, params) // TODO should not do ifEnabled 
check
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86089b38/log4j-api-scala_2.10/src/main/scala/org/apache/logging/log4j/scala/LoggerMacro.scala
----------------------------------------------------------------------
diff --git 
a/log4j-api-scala_2.10/src/main/scala/org/apache/logging/log4j/scala/LoggerMacro.scala
 
b/log4j-api-scala_2.10/src/main/scala/org/apache/logging/log4j/scala/LoggerMacro.scala
index 513dd90..507242e 100644
--- 
a/log4j-api-scala_2.10/src/main/scala/org/apache/logging/log4j/scala/LoggerMacro.scala
+++ 
b/log4j-api-scala_2.10/src/main/scala/org/apache/logging/log4j/scala/LoggerMacro.scala
@@ -343,7 +343,7 @@ private object LoggerMacro {
       c.prefix.splice.delegate.traceEntry()
     )
 
-  def traceEntryParams(c: LoggerContext)(params: c.Expr[Any]*): 
c.Expr[EntryMessage] = {
+  def traceEntryParams(c: LoggerContext)(params: c.Expr[AnyRef]*): 
c.Expr[EntryMessage] = {
     import c.universe._
     val isEnabled = Apply(
       Select(Select(c.prefix.tree, newTermName("delegate")), 
newTermName("isEnabled")),
@@ -356,8 +356,8 @@ private object LoggerMacro {
     )
 
     val log = Apply(
-      Select(c.prefix.tree, newTermName("traceEntryParams")),
-      (params map (_.tree)).toList
+      Select(Select(c.prefix.tree, newTermName("delegate")), 
newTermName("traceEntry")),
+      reify(null: String).tree :: (params map (_.tree)).toList
     )
     c.Expr[EntryMessage](If(isEnabled, log, reify(null).tree))
   }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86089b38/log4j-api-scala_2.10/src/test/scala/org/apache/logging/log4j/scala/LoggerTest.scala
----------------------------------------------------------------------
diff --git 
a/log4j-api-scala_2.10/src/test/scala/org/apache/logging/log4j/scala/LoggerTest.scala
 
b/log4j-api-scala_2.10/src/test/scala/org/apache/logging/log4j/scala/LoggerTest.scala
index d9237a5..4c14d5d 100644
--- 
a/log4j-api-scala_2.10/src/test/scala/org/apache/logging/log4j/scala/LoggerTest.scala
+++ 
b/log4j-api-scala_2.10/src/test/scala/org/apache/logging/log4j/scala/LoggerTest.scala
@@ -451,16 +451,16 @@ class LoggerTest extends FunSuite with Matchers with 
MockitoSugar {
     val f = fixture
     when(f.mockLogger.isEnabled(Level.TRACE, AbstractLogger.ENTRY_MARKER, 
null.asInstanceOf[AnyRef], null)).thenReturn(true)
     val logger = Logger(f.mockLogger)
-    logger.traceEntry("foo", 17)
-    verify(f.mockLogger).traceEntry(anyString(), any[Array[AnyRef]])
+    logger.traceEntry("foo", "bar")
+    verify(f.mockLogger).traceEntry(null: String, "foo", "bar")
   }
 
   test("traceEntry disabled with params") {
     val f = fixture
     when(f.mockLogger.isEnabled(Level.TRACE, AbstractLogger.ENTRY_MARKER, 
null.asInstanceOf[AnyRef], null)).thenReturn(false)
     val logger = Logger(f.mockLogger)
-    logger.traceEntry("foo", 17)
-    verify(f.mockLogger, never).traceEntry(anyString(), any[Array[AnyRef]])
+    logger.traceEntry("foo", "bar")
+    verify(f.mockLogger, never).traceEntry(anyString(), anyString(), 
anyString())
   }
 
   test("traceEntry enabled with message") {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86089b38/log4j-api-scala_2.11/src/main/scala/org/apache/logging/log4j/scala/Logger.scala
----------------------------------------------------------------------
diff --git 
a/log4j-api-scala_2.11/src/main/scala/org/apache/logging/log4j/scala/Logger.scala
 
b/log4j-api-scala_2.11/src/main/scala/org/apache/logging/log4j/scala/Logger.scala
index 5fa2cb7..4999bdb 100644
--- 
a/log4j-api-scala_2.11/src/main/scala/org/apache/logging/log4j/scala/Logger.scala
+++ 
b/log4j-api-scala_2.11/src/main/scala/org/apache/logging/log4j/scala/Logger.scala
@@ -454,7 +454,7 @@ class Logger private(val delegate: ExtendedLogger) {
     * @param params the parameters to the method.
     * @return The built `EntryMessage`
     */
-  def traceEntry(params: Any*): EntryMessage =
+  def traceEntry(params: AnyRef*): EntryMessage =
   macro LoggerMacro.traceEntryParams
 
   /**
@@ -623,10 +623,4 @@ class Logger private(val delegate: ExtendedLogger) {
     delegate.logMessage(FQCN, level, marker, 
messageFactory.newMessage(message), cause)
   }
 
-  // TODO inline this to get FQCN correct
-  /** Should normally not be used directly from application code, but needs to 
be public for access by macros. */
-  def traceEntryParams(params: Any*): EntryMessage = {
-    delegate.traceEntry(null: String, params) // TODO should not do ifEnabled 
check
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86089b38/log4j-api-scala_2.11/src/main/scala/org/apache/logging/log4j/scala/LoggerMacro.scala
----------------------------------------------------------------------
diff --git 
a/log4j-api-scala_2.11/src/main/scala/org/apache/logging/log4j/scala/LoggerMacro.scala
 
b/log4j-api-scala_2.11/src/main/scala/org/apache/logging/log4j/scala/LoggerMacro.scala
index 77a0a0c..0f1bac5 100644
--- 
a/log4j-api-scala_2.11/src/main/scala/org/apache/logging/log4j/scala/LoggerMacro.scala
+++ 
b/log4j-api-scala_2.11/src/main/scala/org/apache/logging/log4j/scala/LoggerMacro.scala
@@ -343,7 +343,7 @@ private object LoggerMacro {
       c.prefix.splice.delegate.traceEntry()
     )
 
-  def traceEntryParams(c: LoggerContext)(params: c.Expr[Any]*): 
c.Expr[EntryMessage] = {
+  def traceEntryParams(c: LoggerContext)(params: c.Expr[AnyRef]*): 
c.Expr[EntryMessage] = {
     import c.universe._
     val isEnabled = Apply(
       Select(Select(c.prefix.tree, newTermName("delegate")), 
newTermName("isEnabled")),
@@ -356,8 +356,8 @@ private object LoggerMacro {
     )
 
     val log = Apply(
-      Select(c.prefix.tree, newTermName("traceEntryParams")),
-      (params map (_.tree)).toList
+      Select(Select(c.prefix.tree, newTermName("delegate")), 
newTermName("traceEntry")),
+      reify(null: String).tree :: (params map (_.tree)).toList
     )
     c.Expr[EntryMessage](If(isEnabled, log, reify(null).tree))
   }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86089b38/log4j-api-scala_2.11/src/test/scala/org/apache/logging/log4j/scala/LoggerTest.scala
----------------------------------------------------------------------
diff --git 
a/log4j-api-scala_2.11/src/test/scala/org/apache/logging/log4j/scala/LoggerTest.scala
 
b/log4j-api-scala_2.11/src/test/scala/org/apache/logging/log4j/scala/LoggerTest.scala
index d9237a5..4c14d5d 100644
--- 
a/log4j-api-scala_2.11/src/test/scala/org/apache/logging/log4j/scala/LoggerTest.scala
+++ 
b/log4j-api-scala_2.11/src/test/scala/org/apache/logging/log4j/scala/LoggerTest.scala
@@ -451,16 +451,16 @@ class LoggerTest extends FunSuite with Matchers with 
MockitoSugar {
     val f = fixture
     when(f.mockLogger.isEnabled(Level.TRACE, AbstractLogger.ENTRY_MARKER, 
null.asInstanceOf[AnyRef], null)).thenReturn(true)
     val logger = Logger(f.mockLogger)
-    logger.traceEntry("foo", 17)
-    verify(f.mockLogger).traceEntry(anyString(), any[Array[AnyRef]])
+    logger.traceEntry("foo", "bar")
+    verify(f.mockLogger).traceEntry(null: String, "foo", "bar")
   }
 
   test("traceEntry disabled with params") {
     val f = fixture
     when(f.mockLogger.isEnabled(Level.TRACE, AbstractLogger.ENTRY_MARKER, 
null.asInstanceOf[AnyRef], null)).thenReturn(false)
     val logger = Logger(f.mockLogger)
-    logger.traceEntry("foo", 17)
-    verify(f.mockLogger, never).traceEntry(anyString(), any[Array[AnyRef]])
+    logger.traceEntry("foo", "bar")
+    verify(f.mockLogger, never).traceEntry(anyString(), anyString(), 
anyString())
   }
 
   test("traceEntry enabled with message") {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86089b38/log4j-samples/scala-api/src/main/resources/log4j2.xml
----------------------------------------------------------------------
diff --git a/log4j-samples/scala-api/src/main/resources/log4j2.xml 
b/log4j-samples/scala-api/src/main/resources/log4j2.xml
index f5b89b4..ac0664b 100644
--- a/log4j-samples/scala-api/src/main/resources/log4j2.xml
+++ b/log4j-samples/scala-api/src/main/resources/log4j2.xml
@@ -20,12 +20,12 @@
     <Appenders>
         <Console name="Console">
             <PatternLayout>
-                <Pattern>%d %5p [%t] %c{1} %X - %m%n</Pattern>
+                <Pattern>%d %5p %c{1} %X %F:%L - %m%n</Pattern>
             </PatternLayout>
         </Console>
     </Appenders>
     <Loggers>
-        <Root level="INFO">
+        <Root level="TRACE">
             <AppenderRef ref="Console"/>
         </Root>
     </Loggers>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86089b38/log4j-samples/scala-api/src/main/scala/org/apache/logging/log4j/scalasample/LoggingApp.scala
----------------------------------------------------------------------
diff --git 
a/log4j-samples/scala-api/src/main/scala/org/apache/logging/log4j/scalasample/LoggingApp.scala
 
b/log4j-samples/scala-api/src/main/scala/org/apache/logging/log4j/scalasample/LoggingApp.scala
index b50c83b..82c2acf 100644
--- 
a/log4j-samples/scala-api/src/main/scala/org/apache/logging/log4j/scalasample/LoggingApp.scala
+++ 
b/log4j-samples/scala-api/src/main/scala/org/apache/logging/log4j/scalasample/LoggingApp.scala
@@ -4,7 +4,18 @@ import org.apache.logging.log4j.scala.Logging
 
 object LoggingApp extends App with Logging {
 
-  val i = 17
-  logger.info(s"Hello, world: $i")
+  val s1 = "foo"
+  val s2 = "bar"
+  logger.info(s"Hello, world: $s1 $s2")
+
+  logger.traceEntry()
+  logger.traceEntry(s1, s2)
+  val entryMessage = 
logger.traceEntry(logger.messageFactory.newMessage("foobar": CharSequence))
+
+  logger.traceExit()
+  logger.traceExit(s2)
+  logger.traceExit(entryMessage)
+  logger.traceExit(entryMessage, s2)
+  logger.traceExit(logger.messageFactory.newMessage("foobar": CharSequence), 
s2)
 
 }
\ No newline at end of file

Reply via email to