What is the difference between log4j and java.util.logging
Asked Answered
J

1

6

Which is best for getting the log files of user logged in his account? Explain with a small example... Thanks for your time...

Jolly answered 22/12, 2010 at 7:58 Comment(0)
N
6

Log4j is a defacto standard logging library for Java.

Java.util.logging is a built in logging mechanism in Java, but that doesn't make it the greatest...

Use Log4j and its MDC. This way, you can easily log different user accounts like this:

MDC.put(user);
logger.log("Deleted something important!");

This way, if logging is configured correctly, in your log output you will see something like this:

[user Alice] Deleted something important!

and this will work for every user in a multi user environment.

Note: if you're starting a new project, I'd suggest using slf4j and Logback. This combination is even more powerful than log4j or java.util.logging.

I have been using this combination for some time and it has really paid off handsomely. Very useful for bug squashing and auditing user interaction, among other things.

Nodus answered 22/12, 2010 at 8:2 Comment(4)
@darioo..can u plz suggest good tutorials how to use slf4j and LogbackJolly
@dude: read the Logback manual. Everything you need, you will find there.Nodus
I would rather think that java.util.logging is the standard as it comes pre-installed. For example java.util.logging is available on Android - try Log4J there.Vacuity
Thanks for bringing attention ton MDC (and NDC). Great stuff.Gearhart

© 2022 - 2024 — McMap. All rights reserved.