Taylor Venable avatar Taylor Venable committed 897f21b

Add logging for output messages.

Comments (0)

Files changed (3)

src/main/resources/META-INF/logback.xml

+<configuration>
+
+  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+    <layout class="ch.qos.logback.classic.PatternLayout">
+      <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
+    </layout>
+  </appender>
+
+  <root level="debug">
+    <appender-ref ref="STDOUT" />
+  </root>
+</configuration>

src/main/scala/net/metasyntax/ldif/LdifPipeline.scala

 import _root_.scala.actors.Actor._
 
 import ast._
+import util.Logging
 
 private case object Shutdown
 
  remain, it sends the Shutdown signal to the transformer and terminates. */
 
 private class LdifPipelineSource(s: LdifStream, next: LdifPipelineTransformer) extends Actor {
+  val logger = Logging("LDIF Parser")
+
   def act {
+    logger.info("Pipeline source started")
+
     s.version match {
       case Some(v) => next ! v
       case None => throw new RuntimeException("Invalid LDIF file: no version")
       next ! e.get
       e = s.nextEntry
     }
+
     next ! Shutdown
+    logger.info("Pipeline source finished")
   }
 }
 
  that along to the sink and terminates. */
 
 private class LdifPipelineTransformer(f: LdifEntry => LdifEntry, next: LdifPipelineSink) extends Actor {
+  val logger = Logging("LDIF Parser")
+
   def act {
     var entryCount = 0
     while (true) {
           next ! e1
           entryCount = entryCount + 1
           if (entryCount % 100 == 0)
-            println("Entries read: " + entryCount)
+            logger.debug("Processed entries (so far): %d" format (entryCount))
         }
         case Shutdown => {
+          logger.info("Processed a total of %d entries" format (entryCount))
           next ! Shutdown
           exit()
         }
  signal, it terminates. */
 
 private class LdifPipelineSink(ps: java.io.PrintStream) extends Actor {
+  val logger = Logging("LDIF Parser")
+
   def act {
+    logger.info("Pipeline sink started")
+
     while (true) {
       receive {
         case (v: LdifVersion) => v.print(ps)
         case (e: LdifEntry) => e.print(ps)
-        case Shutdown => exit()
+        case Shutdown => {
+          logger.info("Pipeline sink finished")
+          exit()
+        }
       }
     }
   }

src/main/scala/net/metasyntax/ldif/util/Logging.scala

+/// Copyright (c) 2011, Taylor Venable
+/// All rights reserved.
+///
+/// Redistribution and use in source and binary forms, with or without
+/// modification, are permitted provided that the following conditions are met:
+///
+///     * Redistributions of source code must retain the above copyright
+///       notice, this list of conditions and the following disclaimer.
+///
+///     * Redistributions in binary form must reproduce the above copyright
+///       notice, this list of conditions and the following disclaimer in the
+///       documentation and/or other materials provided with the distribution.
+///
+/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+/// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+/// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+/// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+/// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+/// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+/// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+/// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+/// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+/// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+/// POSSIBILITY OF SUCH DAMAGE.
+
+package net.metasyntax.ldif.util
+
+import _root_.net.liftweb.common.{
+  Box, Logger, Logback
+}
+
+object Logging {
+  val logUrl = {
+    val loader = Thread.currentThread.getContextClassLoader
+    loader.getResource("META-INF/logback.xml")
+  }
+
+  Logger.setup = Box(() => Logback.withFile(logUrl))
+
+  def apply(cls: Class[_]): Logger = {
+    Logger(cls)
+  }
+
+  def apply(name: String): Logger = {
+    Logger(name)
+  }
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.