--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
@Logprotected static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(LogExample.class.getPackage().getName());j.u.l. is a little bit tricky in this sense. If you run this code snippet using the default j.u.l.LogManager:
Logger l1 = Logger.getLogger("org.acme.spacecraft.commons.core.SpecificClass1");
Logger l2 = Logger.getLogger("org.acme.spacecraft.rocket.engine.boosters.SpecificClass2");
Logger l3 = Logger.getLogger("org.acmear.spacecraft.rocket.engine.boosters.SpecificClass3");
String configFileContents =
".level = OFF \n"+
"org.acme.spacecraft.commons.level = ALL \n"+
"org.acme.spacecraft.rocket.engine.level = ALL \n" +
"org.acme.spacecraft.rocket.engine.boosters.SpecificClass3.level = OFF \n";
LogManager logManager = LogManager.getLogManager();
logManager.readConfiguration(new ByteArrayInputStream(configFileContents.getBytes("UTF-8")));
System.out.println(l1.isLoggable(Level.FINE));
System.out.println(l2.isLoggable(Level.FINE));
System.out.println(l3.isLoggable(Level.FINE));
Logger.getLogger("org.acme.spacecraft.commons");
Logger.getLogger("org.acme.spacecraft.rocket.engine");
System.out.println('-');
System.out.println(l1.isLoggable(Level.FINE));
System.out.println(l2.isLoggable(Level.FINE));
System.out.println(l3.isLoggable(Level.FINE));
You will get:
false
false
false
-
true
true
false
Silly? It is because the parent loggers in the hierarchy are injected by the LogManager only when they are explicitly created in code, so a coarse-grained configuration in a config properties file or ApplicationServer console isn’t available except if you do the hack.
This is with the DEFAULT JDK implementation. Please note that JBossAS, WebLogic, WebSphere and Glassfish actually use a more sophisticated LogManager (if I remember well), so this behaviour may change.
Cheers!
thanks for your reaction, let me see if I can add a few more cents.
We might at two sides of the discussion, information wise, since I do not have a lot of experience with j.u.l. The one I did have was too interspersed with DIY code, and we threw it out in favor of Slf4Jwith a logback backend. The basics of j.u.l. logging are of course not that hard, but configuring loggers is something that might be a bit harder than say in Log4J or Slf4J.So, though I'm not really sure about the options in j.u.l., the configuration of loggers in Slf4J implementation (log4j, logback, log4j2, ... ) all seem to have a lot of convenience to configure groups of loggers based on their package name. I agree that in most systems a single, global, log output, is more than enough. But that use case is really easy in these systems, and using a single logging instance does not really make easier. It does however make it harder when you do want to differentiate in a deployed instance. And though this use case is probably not very common (or something you want to avoid), using a single logger will, afaik, result in a situation where all differentiating information is gone.
The memory footprint of the individual loggers for the types of applications I have worked with pales in comparison to the entire class/perm-gen overhead. I must admit I don't have hard figures, and only the word of the implementers of Log4J and Logback. Though they seem to have a fun time pointing towards each other when mentioning performance (http://logback.qos.ch/reasonsToSwitch.html, http://logging.apache.org/log4j/2.x/performance.html).
Of course, j.u.l. is never mentioned here, and neither is a comparison of memory footprint. In general people seem to care more about memory throughput because it can become a bottleneck when you do a rather large amount of logging on a JVM. In short, I don't really see the memory argument here, but have zero figures to back myself up. 100% pure opinion and gut feeling. Perhaps if I feel inspired I'll do a measurement or get lucky and find that someone else has already done this work for me ;)
What do you think of this new proposal?:
· Admit a default value in the annotation
· If empty value, same as now: private and initialized with the class name as the logger subsystem name.
· If present, make the field protected / package protected, and use that specified name
@Log
@Log(“subsystemName”)
J
thanks for your reaction, let me see if I can add a few more cents.
Yes, you are right about the accesibility of the fied. But please consider adding the value attribute with the name.
Best!
De: Reinier Zwitserloot [mailto:rein...@gmail.com]
Enviado el: jueves, 09 de enero de 2014 1:00
Para: project...@googlegroups.com
CC: Jesús Viñuales
Asunto: Re: [project lombok] @Log logger instance visibility
.... except this proposal is not 'natural' (as in, it is not easy to fathom what is going on just reading the usage). I'm okay with non-natural usage to an extent, but it is definitely a downside to any proposal, and this proposal is already on shaky ground.
Do all logging systems offer string-based naming?
Good question. I think so. For the currently supported logging frameworks at least, see:
@CommonsLog : http://commons.apache.org/proper/commons-logging/apidocs/org/apache/commons/logging/LogFactory.html#getLog(java.lang.String)
@Log : http://docs.oracle.com/javase/6/docs/api/java/util/logging/Logger.html#getLogger(java.lang.String)
@Log4j : http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Logger.html#getLogger(java.lang.String)
@Slf4j : http://www.slf4j.org/apidocs/org/slf4j/LoggerFactory.html#getLogger(java.lang.String)
@XSlf4j : http://www.slf4j.org/apidocs/org/slf4j/ext/XLoggerFactory.html#getXLogger(java.lang.String)