SLF4J Logging in Spark-Scala

import org.slf4j.{Logger, LoggerFactory}
val logger: Logger = LoggerFactory.getLogger(this.getClass.getName)
#Bazel build dependency
java_library(
name = "slf4j",
exports = [
"@maven//:org_slf4j_slf4j_api_1_7_32",
"@maven//:org_slf4j_slf4j_log4j12_1_7_30", #Replace this
]
)
package(default_visibility = [
"//src/main/scala:__subpackages__",
"//src/test/scala:__subpackages__",
])

load("@io_bazel_rules_scala//scala:scala.bzl",_scala_library="scala_library")
scala_library(
name = "logging",
srcs = glob(["Logging.scala"]),
resources = [
"//src/main/scala/TestApp/common/logging/resources:simplelogger.properties",
"//src/main/scala/TestApp/common/logging/resources:log4j.properties"
],
deps = [
":slf4j",
]
)
#Log4j pattern documentation - https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html# Set everything to be logged to the console
log4j.rootCategory=INFO, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{dd-MM-yyyy HH:mm:ss} [%t] %-3p %c: %m%n

# Settings to quiet third party logs that are too verbose
log4j.logger.org.sparkproject.jetty=ERROR
log4j.logger.org.sparkproject.jetty.util.component.AbstractLifeCycle=ERROR
log4j.logger.org.apache.spark.repl.SparkIMain$exprTyper=WARN
log4j.logger.org.apache.spark.repl.SparkILoop$SparkILoopInterpreter=WARN
log4j.logger.org.apache.spark.scheduler=WARN
log4j.logger.org.apache.spark.storage.memory=WARN
log4j.logger.org.apache.spark.SecurityManager=WARN
log4j.logger.org.apache.spark.SparkEnv=WARN
log4j.logger.org.apache.spark.storage=WARN
log4j.logger.org.apache.spark.sql=WARN
log4j.logger.org.apache.spark.executor=WARN
log4j.logger.org.apache.parquet.filter2=WARN
log4j.logger.org.apache.spark.SparkContext=WARN
log4j.logger.org.apache.parquet.hadoop=WARN
log4j.logger.org.apache.hadoop.mapreduce=WARN
# SLF4J's SimpleLogger configuration file
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.

# Default logging detail level for all instances of SimpleLogger.
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, defaults to "info".
#org.slf4j.simpleLogger.defaultLogLevel=error
org.slf4j.simplelogger.defaultlog=error

# Logging detail level for a SimpleLogger instance named "xxxxx".
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, the default logging detail level is used.
#org.slf4j.simpleLogger.log.xxxxx=

# Set to true if you want the current date and time to be included in output messages.
# Default is false, and will output the number of milliseconds elapsed since startup.
org.slf4j.simpleLogger.showDateTime=true

# The date and time format to be used in the output messages.
# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
# If the format is not specified or is invalid, the default format is used.
# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z

# Set to true if you want to output the current thread name.
# Defaults to true.
org.slf4j.simpleLogger.showThreadName=true

# Set to true if you want the Logger instance name to be included in output messages.
# Defaults to true.
org.slf4j.simpleLogger.showLogName=true

# Set to true if you want the last component of the name to be included in output messages.
# Defaults to false.
org.slf4j.simpleLogger.showShortLogName=false

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store