1

I am using these two logging dependences:

<dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.12</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.12</version>
        </dependency>

and I use the logging like this:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory
            .getLogger(PluginConfigurationParser.class);

and then inside my code, i do something like this:

if (LOG.isDebugEnabled()) {
                            LOG.debug("some string for me");
                        }

When i run the code inside eclipse( from public static void main), the code is executed but the log doesn't appear on the console. could you tell me how can i enable it?

I do know that slf4j is an api and I need the actual binding, but i am not sure if one of the two dependencies are consider a binding.

hope you be patient because of my slf4j small knowledge

Marco Dinatsoli
  • 10,322
  • 37
  • 139
  • 253
  • how your configuration looks like ? – Daniel Jipa Aug 10 '15 at 11:25
  • Read the documentation on how to configure logging and where you want it to be output. Also note that you almost never need to call the `isDebugEnabled()` and related methods since the `LOG.debug` will check whether the level is enabled. – Kayaman Aug 10 '15 at 11:26
  • @DanielJipa i don't know if there is a configuration for logging, what file should I search for? where is its location? – Marco Dinatsoli Aug 10 '15 at 12:12
  • it seems i was doing everything correctly, because when i did log.info, it works, just the log.debug does't work. why please? – Marco Dinatsoli Aug 10 '15 at 12:14
  • @Kayaman kindly check my last comment please – Marco Dinatsoli Aug 10 '15 at 12:16
  • @DanielJipa would you please check my last comment? – Marco Dinatsoli Aug 10 '15 at 12:16
  • Your logging is configured for level INFO, meaning that DEBUG messages aren't shown. If you had googled for "slf4j simple configuration", your problem would've been solved already. Now you're just wasting everyone's time. – Kayaman Aug 10 '15 at 12:23

1 Answers1

1

You need to initialize the logger inside your class, like the following:
private final Logger logger = LoggerFactory.getLogger(yourClass.class).

Afterwards, logger.info("message") should work.

I think your loop is what's throwing it off, because if you just use logger.info or logger.debug, then if it works, it'll print, and if not, it won't and throw an error instead, but that might be helpful to see.

  • it seems i was doing almost everything correctly, when i did log.info it works good, but when i did log.debug, it did't show anything and it didn't throw any exception or error. what do i miss please? – Marco Dinatsoli Aug 10 '15 at 12:15