Giter Site home page Giter Site logo

Comments (6)

rbellamy avatar rbellamy commented on August 23, 2024 9

@analytically - looks like the folks over at reactive-kafka figured it out - akka/alpakka-kafka#99.

Basically, if your dependency tree includes the older scala-logging-slf4j artifact you'll see this exception.

Answer: exclude("com.typesafe.scala-logging", "scala-logging-slf4j_2.11")

from scala-logging.

timo-aho avatar timo-aho commented on August 23, 2024 5

I'll leave my solution for Databricks logging problem for further reference.

tl;dr:
Databricks uses old com.typesafe.scalalogging version 2.1.2. For newer ones, this is repaired.

Solution
Scalalogging uses org.slf4j.Logger in the background. Let's do our own Logger trait based on the latter:

package yourPackage

import org.slf4j.{Logger, LoggerFactory}

// Serializable logger
trait MyLogging {
  @transient
  protected lazy val logger: Logger =
    LoggerFactory.getLogger(getClass.getName)
}

Then let's use this trait instead of com.typesafe.scalalogging.LazyLogging.

trait YourSparkApp extends yourPackage.MyLogging
{
  def main(argList: Array[String]): Unit = {
      implicit val logger: Logger = this.logger // For implicit usage.
      logger.info("This should work.")
      ...
    }
}

Longer explanation
The currently newest Databricks 5.5 (Scala 2.11) uses old version of com.typesafe.scalalogging 2.1.2 as shown in
https://docs.databricks.com/release-notes/runtime/5.5.html#installed-java-and-scala-libraries-scala-2-11-cluster-version
To my knowledge, it is difficult to override this logger with other packages or versions in Spark. (I think there is an experimental flag for spark-submit.)

Logger should not be serialized, thus, it needs to be transient. However, 2.1.2 does not do this as shown here:
2.1.2: https://github.com/lightbend/scala-logging/blob/v2.1.2/scala-logging-slf4j/src/main/scala/com/typesafe/scalalogging/slf4j/Logging.scala#L28
As explained in this issue, in the newer versions, this is repaired. For instance 3.9.0: https://github.com/lightbend/scala-logging/blob/v3.9.0/src/main/scala/com/typesafe/scalalogging/Logging.scala#L27
Nevertheless, this currently does not help with Databricks because of the old library version used.

Hence, we need to create our own Logging trait based on org.sljf4j and inherit this (instead of com.typesafe.scalalogging.LazyLogging).
We do not even need to change dependencies in Maven or SBT because org.slf4j is already included in the scalalogging library.

from scala-logging.

analytically avatar analytically commented on August 23, 2024

Do you see the same using StrictLogging?

from scala-logging.

skate056 avatar skate056 commented on August 23, 2024

Yes, I see that same error intermittently using the StrictLogging interface.

java.lang.InstantiationError: com.typesafe.scalalogging.Logger
	at com.typesafe.scalalogging.Logger$.apply(Logger.scala:32)
	at com.typesafe.scalalogging.StrictLogging$class.$init$(Logging.scala:38)
	at com.hivehome.kafka.connect.sqs.SQSSourceTask.<init>(SQSSourceTask.scala:36)

I am also using 3.5.0

from scala-logging.

rbellamy avatar rbellamy commented on August 23, 2024

@analytically why was this issue closed? I don't see a workaround or a commit addressing this problem (which I am now seeing too).

from scala-logging.

analytically avatar analytically commented on August 23, 2024

I'm unable to reproduce it.

from scala-logging.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.