Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLF4J: The following loggers will not work because they were created during the default configuration phase of the underlying logging system. #23

Closed
dhinojosa opened this issue May 1, 2013 · 4 comments

Comments

@dhinojosa
Copy link

Not sure that scalalogging can work in conjunction with Java code. I tested scalalogging in a project with both scala and java code (see github url below) with an underlying slf4j-simple implementation and ended up with the following statement where the following displayed:

> test 
SLF4J: The following loggers will not work because they were created
SLF4J: during the default configuration phase of the underlying logging system.
SLF4J: See also http://www.slf4j.org/codes.html#substituteLogger
SLF4J: com.evolutionnext.Person
[info] PersonSpec:
[info] Using logging with inside of a model 
[info] - should display the log file
2013-05-01T08:58:13-0600 [pool-593-thread-5] [DEBUG] com.evolutionnext.Calculator - Adding 2 and 5
[info] CalculatorSpec:
[info] Using logging with inside of a service type class, calculator 
[info] - should add two ints and display the log
[info] Passed: : Total 2, Failed 0, Errors 0, Passed 2, Skipped 0
[success] Total time: 0 s, completed May 1, 2013 8:58:13 AM

This small project has two tests, one that tests a scala object and the other a java object.
Try it out by cloning https://github.com/dhinojosa/scala_logging_study and running test. You will find that it will randomly choose which class it will apply logging to.

@dhinojosa
Copy link
Author

@blair
Copy link

blair commented May 2, 2013

I use the following code to get around this issue, was provided by this question and answer: http://stackoverflow.com/a/12095245 . The below code works for sbt 0.12.x, the Stackoverflow code looks to be for an older version of sbt.

// SLF4J initializes itself upon the first logging call.  Because sbt
// runs tests in parallel it is likely that a second thread will
// invoke a second logging call before SLF4J has completed
// initialization from the first thread's logging call, leading to
// these messages:
//   SLF4J: The following loggers will not work because they were created
//   SLF4J: during the default configuration phase of the underlying logging system.
//   SLF4J: See also http://www.slf4j.org/codes.html#substituteLogger
//   SLF4J: com.imageworks.common.concurrent.SingleThreadInfiniteLoopRunner
//
// As a workaround, load SLF4J's root logger before starting the unit
// tests [1].
//
// [1] http://stackoverflow.com/a/12095245
testOptions in Test += Tests.Setup(classLoader =>
  classLoader
    .loadClass("org.slf4j.LoggerFactory")
    .getMethod("getLogger", classLoader.loadClass("java.lang.String"))
    .invoke(null, "ROOT")
)

@dhinojosa
Copy link
Author

Whoa. I had no idea there was that kind of setting in sbt. Thanks Blair. Heiko, your call on whether this is a fix or not. I am going to plug this in as soon as possible.

@hseeberger
Copy link
Contributor

@blair, thanks for answering.

There is a simple alternative, if you don't need parallel test execution:

parallelExecution in Test := false

Closing this, because it's not a ScalaLogging issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants