What is the best approach for logging in IntelliJ 13.1.2?

What ist the best or common approach for simple console application logging in IntelliJ 13.1.2? I'm one of these guys that always used the good old console println approach. But this is evil, some say. So I want to dive into logging with Java 1.8 and IntelliJ 13.1.2 community edition. There are so many logging frameworks out there that I'm quite confused. Is it still necessary to use an external logging framework like log4j from Apache.org or is logging with Java 1.8 fundamental changed?

I'm also new to IntelliJ and not sure how to add one of these frameworks to my application. Is there a IntelliJ approach for build in logging? Basically I only want to get rid of my if...else constructs, for debug logging output. Of course I could write my own logging facility but this is also evil, some say. ;-)

4 comments

SLF4J is a library that provides a standardized interface to most of the
commonly used logging libraries. Using this will allow you to change the
underlying logging without changing any of the existing logging code in
your application.

I personally like Logback (http://logback.qos.ch/) for logging - it is
very flexible and configurable.

I found the documentation for both to be helpful.

On 5/8/14 7:38 AM, Frank Loizzi wrote:

What ist the best or common approach for simple console application logging in IntelliJ 13.1.2? I'm one of these guys that always used the good old console println approach. But this is evil, some say. So I want to dive into logging with Java 1.8 and IntelliJ 13.1.2 community edition. There are so many logging frameworks out there that I'm quite confused. Is it still necessary to use an external logging framework like log4j from Apache.org or is logging with Java 1.8 fundamental changed?

>

I'm also new to IntelliJ and not sure how to add one of these frameworks to my application. Is there a IntelliJ approach for build in logging? Basically I only want to get rid of my if...else constructs, for debug logging output. Of course I could write my own logging facility but this is also evil, some say. ;)


0

Thanks for your answer. I use now org.slf4j 1.7.7 with java.util bindings and could configure IntelliJ to use the latest version. In default Maven repositories there is only 1.7.4 available, so I had to do it manually. IntelliJ is quite complex, so far my experience. Adding slf4j to the classpath is non intuitive for beginners. Now I'm able to compile and run Java source with Logger objects. However, at runtime Java throws a "Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory". I'm sure I have still something overlooked. But what?

0

Hi Frank,

SLF4J is only a facade - that is, an interface without any
implementation. You have to pick an underlying logging method.

Donald

On 5/9/14 3:31 AM, Frank Loizzi wrote:

Thanks for your answer. I use now org.slf4j and could configure IntelliJ to use the latest version. In default Maven repositories there is only 1.7.4 available, so I had to do it manually. IntelliJ is quite complex, so far my experience. Adding slf4j to the classpath is non intuitive for beginners. Now I'm able to compile and run Java source with Logger objects. However, at runtime Java throws a "Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory". I'm sure I have still something overlooked. But what?


0

I know that org.slf4j is only a facade. As I wrote, I use it with java.util bindings, that is java.util.logging. That's not the best choice but I had to make it work in the first line. As I wrote I can compile, run and debug a Java console application but if I try to run the same application on production level (\out\production\application\pack.name.application) than it throws an exception. It seems that the used libraries are not exported or included to the output level. I don't know how to achieve this with IntelliJ.

Edit: I had to include SLF4J jar libraries into the CLASSPATH. That's a very cubersome method to use external libraries, in my opinon. Is there a way in IntelliJ to add references automatically to the production output? In Visual Studio 2013 I can decide if an used library should copied to release output. In IntelliJ I found a similar feature (Project Structure -> Modules -> Dependencies) but it does not that what I expect. Setting any of SLF4J to runtime (scope) is not copy this libraries.

Nachricht geändert durch Frank Loizzi

0

Please sign in to leave a comment.