question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get SLF4J logging to work

See original GitHub issue

I am trying to get slf4j to work within the notebooks because some 3rd party libs that I use need it. When I try to set jshell classpath directly through --class-path it works. If I set IJAVA_CLASSPATH in kernel.json to point to the logging jars or when I import them in the notebook, it does not work, it says SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

%maven org.slf4j:slf4j-api:1.7.16
%maven ch.qos.logback:logback-classic:1.0.13    
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.impl.StaticLoggerBinder;

Logger slf4jLogger = LoggerFactory.getLogger("T");
slf4jLogger.warn("Hi, {}", "Test");

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SpencerParkcommented, Aug 21, 2018

Thank you for the report. I was able to reproduce and can confirm this is a bug.

Classpath related things are an ongoing issue with all the dynamic loading going on in this environment. I’ve been trying to find a fix but the closest I’ve gotten in with the newest beta version and manually loading things which still has some warnings but eventually does log something. I will continue to investigate and update when I get a chance.

In case you are curious this is what I am referring to is the following which essentially pulls out the code from slf4j that loads the logger.

%maven org.slf4j:slf4j-api:jar:1.8.0-beta2
%maven ch.qos.logback:logback-classic:jar:1.3.0-alpha4

import org.slf4j.spi.SLF4JServiceProvider;

ServiceLoader<SLF4JServiceProvider> serviceLoader = ServiceLoader.load(SLF4JServiceProvider.class);
List<SLF4JServiceProvider> providerList = new ArrayList<SLF4JServiceProvider>();
for (SLF4JServiceProvider provider : serviceLoader)
    providerList.add(provider);
    
providerList.get(0).initialize();
providerList.get(0).getLoggerFactory().getLogger("JupyterNotebook").info("HelloWorld")
0reactions
aelkayeshcommented, Sep 6, 2018

Thank you a million 😃 It works as needed so far.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How slf4j works? No log getting created - Stack Overflow
SLF4J is just a logging abstraction - it doesn't write any logs itself. Use Logback - it implements SLF4J natively and is written...
Read more >
SLF4J FAQ
SLF4J is a simple facade for logging systems allowing the end-user to plug in the desired logging system at deployment time. When should...
Read more >
I cannot get my slf4j logging statements to print to standard ...
I cannot get my slf4j logging statements to print to standard output or a file. I have the following slf4j logging code: import...
Read more >
Introduction to SLF4J - Baeldung
A quick and to the point guide of how to use Log4j2 and Logback with ... There are cases when we cannot replace...
Read more >
SLF4J Tutorial: Configuration Example for Logging in Java
When using SLF4J you probably won't be using the slf4j-simple library and you'll want to use it with a dedicated logging framework so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found