print statements often work

5 views
Skip to first unread message

William la Forge

unread,
May 24, 2013, 1:36:54 AM5/24/13
to AgileWikiDevelopers
My debugging techniques for several decades now has been to insert print statements. OSGi is forcing me to change to using the logger, which is probably a good thing.

The reason why I am being forced to change is that print statements, though they often work, do not always work.

monster

unread,
May 24, 2013, 6:13:19 AM5/24/13
to agilewiki...@googlegroups.com
While I do lot of that too, Logging has one really nice feature: If you fully use the Logging API, you can set all kind of "context" info, like logged-in user, session-key ... which can be added to all the default context info, like time, thread-name, ... And you get that for free, because you don't have to think about it while writing your debug output line; it happens automatically, and is configurable externally to the code. That can really help, in particular in multi-threaded code.

Brad Cox

unread,
May 27, 2013, 4:06:59 PM5/27/13
to agilewiki...@googlegroups.com
Logback/slf4j has one killer feature I couldn't do without; the ability to report the java file that generated each line. The ability to timestamp each line is also handy for quick/dirty performance reports by pasting log lines into a spreadsheet. But avoid java.util.Log; its convenient but poisonous.


On Fri, May 24, 2013 at 6:13 AM, monster <skunki...@googlemail.com> wrote:
While I do lot of that too, Logging has one really nice feature: If you fully use the Logging API, you can set all kind of "context" info, like logged-in user, session-key ... which can be added to all the default context info, like time, thread-name, ... And you get that for free, because you don't have to think about it while writing your debug output line; it happens automatically, and is configurable externally to the code. That can really help, in particular in multi-threaded code.

--
You received this message because you are subscribed to the Google Groups "AgileWikiDevelopers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to agilewikidevelo...@googlegroups.com.
To post to this group, send email to agilewiki...@googlegroups.com.
Visit this group at http://groups.google.com/group/agilewikidevelopers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

William la Forge

unread,
May 28, 2013, 3:29:09 AM5/28/13
to AgileWikiDevelopers
I do have one issue which I believe is common with both slf4j and logback. How do you close gracefully or flush?

My test code for Karaf runs under pax exam and when the test is finished, it is finished. Period! Which means the final log messages are not displayed, at least when using the slf4j-simple jar to display them on the console.

I've looked at both the Logger and LoggerFactory API and I don't see anything helpful. So I'm doing a Thread.sleep(). (shudder)

Any ideas?

monster

unread,
May 28, 2013, 1:16:31 PM5/28/13
to agilewiki...@googlegroups.com
I'm not going to try it, so idk if it works, but here is one Google search result.

http://stackoverflow.com/questions/3678755/do-i-need-to-flush-events-when-shutting-down-using-logback

There is a SL4J bug about this, which the main dev thinks is a clear WONT_FIX ... explained by the logic that if you can't configure SLF4J explicitly, then you should not stop it either.  :(

William la Forge

unread,
May 28, 2013, 1:47:47 PM5/28/13
to AgileWikiDevelopers
cool!


Reply all
Reply to author
Forward
0 new messages