Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » slf4j logging for runtime debugging
slf4j logging for runtime debugging [message #1023636] Sun, 24 March 2013 20:15
Steve Kallestad is currently offline Steve KallestadFriend
Messages: 62
Registered: March 2013
I prefer slf4j over log4j for a variety of reasons, but I understand when I have to take a few extra steps to use my preferred logger.

A few weeks ago, I got a little stumped by the XText documentation:

Xtext uses Apache's log4j for logging. It is configured using the so called
, which is
looked up in the root of the Java classpath. If you want to change or provide configuration at runtime
(i.e. non-OSGI), all you have to do is putting such a
in place and make sure that it is not
overridden by other
in previous classpath entries.
In OSGi you provide configuration by creating a fragment for
. In this case you need to
make sure that there's no second fragment contributing a

I read this several times and frankly, I felt like a third grader trying to decipher an encyclopedia entry.

I started looking into what it takes to build OSGI fragments, then got distracted by some postings about xtext's built in logger, and almost caved and started using log4j just to get things moving forward.

But one thing stuck in my mind and I couldn't get past it... logging should be easy. I shouldn't be forced into a particular logger implementation and I *really* shouldn't be throwing System.out.println statements in my code.

So I finally pulled myself away from deciphering documentation and figured out that doing logging with slf4j is pretty easy.

In plugin.xml, on the dependencies tab, I added two imported packages - ch.qos.logback.classic and org.slf4j. They're already on the list (I believe) because antlr brought them in.

From there, working with slf4j is the same as it always was.

For any classes I declare, it's a matter of inserting:
 private static final Logger logger = LoggerFactory.getLogger(MyClass.class);

and adding any statements:
logger.debug("My debug message: {}", someString);

Now, where to put logback.xml...

logback-classic looks for logback.xml on the classpath and I had a pretty hard time figuring out how to include my own logback.xml that was editable.

Under launch configurations, under "Launch Runtime Eclipse" in the VM arguments textbox, I added:

now I can edit the logback.xml file to show/hide various loglevels for various classes while troubleshooting.

So anyhow, I figured I'd share this little tidbit in case anyone else out there got stumped by the logging documentation.

[Updated on: Sun, 24 March 2013 20:17]

Report message to a moderator

Previous Topic:[Xtext 2.3] Cross references in DSL across multiple DSL files?
Next Topic:Language supporting Integers, Floats, Hex Numbers and Range Expressions
Goto Forum:

Current Time: Wed Jan 29 04:47:53 GMT 2020

Powered by FUDForum. Page generated in 0.01473 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top