2. Agenda
About Myself
What Is Logging?
Storyboard
Analysis
Definition
Why Do We Want To Log Things?
How Do We Do Logging?
Logically
Technically
3. About Myself
Software/Solution Architect with a consulting
company in Germany
Dealing with software since the age of 10
Atari ST … Basic, Assembler, Pascal
Primarily dealing with Java and Python nowadays
EAI, SOA, BPM
JBossAS 4 and JBossAS 5
Apache ServiceMix, jBPM, JBoss Rules
…
Passion
Software Quality
Excellence in Craftsmanship
Drop me a message axel (dot) irriger (at) gmail (dot) com
4. What Is Logging? - Storyboard
John and Will are software developers. They are both
experienced and get things done, literary speaken.
On a tough assignment, they get errors and the software
does not, what it should. Since they both short on
schedule, they need to get that error fixed quickly, to not
burn the deadline to ashes.
What will they do?
5. What Is Logging? –John‘s Way
John automatically fires up his favorite debugger and
starts digging around the code, where it expects the
error to be.
After some hours passing, digging here, poking there,
he located the error and got it fixed.
It was in a different module than he first expected –
but who cares, the job is done and the clock shows
11pm.
6. What Is Logging? –Will‘s Way
Will gets curious – why in hell must this happen know? But it is, as it
is. So, he fires up his IDE and reconfigures the logging system to
„debug“ and starts the application again.
After some 5-10 minutes looking through the log files, he gets curious
– there‘s something wrong in this XYZ module. Though he doesn‘t
know what.
So, he again reconfigures the logging system again to „trace“ and
starts his run again. Filtering out the logs pretty quickly he sees that
gets wrong … that parameter should look different!
He fixes the issue and starts again – everything‘s fine now.
It‘s 6pm, a little late, but just in time for dinner.
7. What Is Logging? – Analysis
John did not care about logging – it just takes time and
gets you nothing. That cost him time, overall
Will did care about logging, to be able to fix things faster
Logging helped him see, what the application did
He could locate the issue at hand more quickly and pin down the
suspected piece of code
He needed not do any intense digging but just read output
8. What Is Logging? – Definition
Logging is about letting the program speak what it does
Using fine-grained thresholds, from the most generic to
the most detailed information, information is written to a
log
Logging is the process of noting down processing steps to
document
What is done
With what data it is done
What the outcome is
9. Why Do We Want To Log Things?
Understanding and Documentation
Being able to provide good logging helps yourself to better
understand the code
Reading through log messages helps new developers to more easily
grasp your intentions
Bug fixing
Detect errors more easily
Detect strange variable values more easily
Find the error vs. Look for the error
Support
Really want to do endless iterations with a customer, or just get the
logs and start working?
10. How Do We Do Logging? - Logically
What to log?
Method/Function entry and exist You want to know where
the program walks along
General information like starting, stopping, configuring You
want to see the „big picture“ of the program
External information and computations You want explicitly
see what can‘t be seen (RDBMS input, run-timecomputations,
etc.)
Parameters passed You want to see, how things happened
and why
Log frameworks offer granularity – use it
11. How Do We Do Logging? - Logically
How should levels be used?
FATAL everything which stops the program from continuing (no
RDBMS, unable to read system files)
ERROR everything which is erroneous, but does not stop te
program from continuing (Mail adresses not found, so no mailing)
WARN If defaults are used, because no configuration was passed
and things like that
INFO General informations
DEBUG External informations, Control-Flow decisions
TRACE Method/Function entry/exit, Parameters
Use this as a convention until you feel comfortable
When you‘re comfortable, adjust to your habbits
12. How Do We Do Logging? - Technically
Decide on the framework and stick to that
java.util.logging – Provided out of the box
Apache log4j (log4j) – The widest usage
Apache Commons::Logging (commons-logging) – Abstraction layer for other frameworks
Simple Logging Facade for Java (slf4j) – Simpler abstraction layer for other frameworks
Get familiar to your framework
How to use categories to filter things
How to filter out unimportant stuff
How to use appenders to utilize different log files
How to use loggers to support Console, File, SMTP, SNMP, ...
Always use something like „isDebugEnabled“ or „isLevelEnabled“
Don‘t even try to log something if it wouldn‘t be written
LOG.debug huge messages with „debug“ disabled has huge performance impact
Message will be serialized (costly) and then skipped!
13. Summary
We have seen why logging is worth a consideration
We have seen why we want to do logging at all
We have seen how logging should be approached
logically („from the brain“)
We have seen how logging should be approached
technically („from the keyboard“)
Various logging frameworks will be discussed in ongoing
sessions
Get out and your hands dirty!