Here's the notes from our call this morning regarding the use of jboss logging - chime
in if I got something wrong, or if you disagree (say, for example, we should use some
other third party logging framework rather than JBoss Logging :-)
Here's an example from Undertow:
https://github.com/undertow-io/undertow/blob/master/core/src/main/java/io...
We agreed that Hawkular will not use this mechanism for DEBUG or TRACE level messages, but
will use it for INFO, WARN, ERROR, and FATAL.
In our message interfaces, we can do what undertow does - that is, declare the logger
instance right in the interface, for example, put this in your MsgLogger interface:
MsgLogger LOGGER = Logger.getMessageLogger(MsgLogger.class,
MsgLogger.class.getPackage().getName());
Each major component will have its own logging prefix (alerts will have, for example,
"HAWKALRT" or whatever they want to call it; metrics will have
"HAWK-METRICS" or whatever; inventory another like "HAWKINV"). Each
major component will then divy up the ID ranges how it sees fit.
It is most likely useful to have one logging interface per maven module within the major
component; however, this is up to the developers how they want to separate or combine
their messages - one uber interface or one per maven module or something else. but just
keep in mind the pros and cons of each (e.g. if you have one uber interface, all of your
maven modules will have a dependency on it - and if you add a message, all maven modules
that depend on it will need to rebuild with it, even if they don't need the message -
plus, all your developers will need to edit the same file throughout development, so there
will be alot of git pulling, merging, and conflict resolutions).
Note that in my work, I put one message interface in each maven module that needs
messages. I put them in a package called .log and I named them all "MsgLogger".
I don't know if its the right thing to do to name them all the same - but having the
package names differentiate them was all I needed so far to be able to find them when I
needed to edit them in Eclipse (I just searched for "MsgLogger" and I got the
full list of all my message loggers in the search window - each for me to pick which one I
wanted). Again, time will tell if I should have named them differently rather than all the
same - I really don't have an opinion either way. I don't have good argument for
naming them the same OR naming them differently. Up to you what to do.
To log ad-hoc messages in the debug and trace level, you'll need to define a JBoss
Logging Logger like this:
private final Logger log = Logger.getLogger(YourClass.class);
and use debugf to log debug messages as an example:
log.debugf("This is the first arg [%d] and this is the second [%s].", myNum,
myStr);
We are hopefully going to have the parent pom declare the logging processor for us, so you
only should have to declare logging deps in your maven modules, and the log code
generation will just work. You need these two deps:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
<scope>provided</scope>
</dependency>