Scala – SLF4J Logging

Configuration details and implementation usage of logging in Scala:

 

build.sbt

scalaVersion := “2.10.3”

libraryDependencies ++= Seq(

– – –

“org.slf4j” % “slf4j-api” % “1.7.5”,

“org.slf4j” % “slf4j-simple” % “1.7.5”,

"org.clapper" %% "grizzled-slf4j" % "1.0.2"

)

 

MainJob.scala

package com.cisco.cand.app

 

import java.util.Date

import org.slf4j.LoggerFactory

/**
* Created by Nag Arvind Gudiseva on 07-Apr-2016.
*/
object MainJob extends App{

val logger = LoggerFactory.getLogger(MainJob.getClass)

val startTime = new Date()

logger.info(” :: Start Time :: ” + startTime + ” :: “)

logger.info(” :: Start Module :: Main Job :: “)

– – –

val endTime = new Date()

logger.info(” :: End Time :: ” + endTime + ” :: “)

val timeDiff = (endTime.getTime() – startTime.getTime()) / (1000 * 60)

logger.info(” :: Time Difference :: ” + timeDiff + ” :: “)

logger.info(” :: End Module :: Main Job :: “)

}

 

simplelogger.properties [Location: src\main\resources\]

org.slf4j.simpleLogger.logFile  = System.err
org.slf4j.simpleLogger.defaultLogLevel = info
org.slf4j.simpleLogger.showDateTime  = true
org.slf4j.simpleLogger.dateTimeFormat  = yyyy’/’MM’/’dd’ ‘HH’:’mm’:’ss’-‘S
org.slf4j.simpleLogger.showThreadName  = true
org.slf4j.simpleLogger.showLogName  = true
org.slf4j.simpleLogger.showShortLogName= false
org.slf4j.simpleLogger.levelInBrackets = true

– – –

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s