M
Mikhail Vladimirov
Hello, Java developers community.
Let me present "ultralog" project (http://code.google.com/p/ultralog/) which main purpose is to demonstrate new concept of how logging APIs could be structured.
The idea is that each logger in the application has its own interface specific to the purpose of the logger. This interface defines all messages that could be logged via this logger. Here is an example of such interface:
protected interface HelloLogger extends BasicLogger
{
@LogMessage (level = INFO, template = "Hello, ${1}!")
void hello (String user);
}
The logging framework generates implementations of such interfaces on the fly or at compile time by compiling message templates into Java bytecode. Here is how this logger could be used:
HelloLogger logger = LoggerManager.createLogger (HelloLogger.class);
if (logger.isInfoEnabled ())
logger.hello (System.getProperty ("user.name"));
Advantages of this approach:
- Clear syntax.
- All log messages for the logger are defined in one place which makes it easier to review and restyle them in consistent manner.
- Log messages are defined as methods, so IDEs "find references" feature could be used to fine all places where particular message is logged.
- Values of arbitrary types including primitive types could be substituted into log message without allocating any temporary objects.
See project WiKi (http://code.google.com/p/ultralog/wiki/TableOfContents) for more information and feel free to provide feedback.
Let me present "ultralog" project (http://code.google.com/p/ultralog/) which main purpose is to demonstrate new concept of how logging APIs could be structured.
The idea is that each logger in the application has its own interface specific to the purpose of the logger. This interface defines all messages that could be logged via this logger. Here is an example of such interface:
protected interface HelloLogger extends BasicLogger
{
@LogMessage (level = INFO, template = "Hello, ${1}!")
void hello (String user);
}
The logging framework generates implementations of such interfaces on the fly or at compile time by compiling message templates into Java bytecode. Here is how this logger could be used:
HelloLogger logger = LoggerManager.createLogger (HelloLogger.class);
if (logger.isInfoEnabled ())
logger.hello (System.getProperty ("user.name"));
Advantages of this approach:
- Clear syntax.
- All log messages for the logger are defined in one place which makes it easier to review and restyle them in consistent manner.
- Log messages are defined as methods, so IDEs "find references" feature could be used to fine all places where particular message is logged.
- Values of arbitrary types including primitive types could be substituted into log message without allocating any temporary objects.
See project WiKi (http://code.google.com/p/ultralog/wiki/TableOfContents) for more information and feel free to provide feedback.