Log4Dart is a logger for Dart inspired by Slf4J.
The logger and its appender are interfaces and thus supports multiple implementations. Currently the following implementation ships with Log4Dart
- ConsoleAppender a appender that logs to the console
- LoggerImpl a simple logger implementation with diagnostic support
The logger is accessed through the LoggerFactory like this
// Setup a logger builder function for the application
// this is the function invoked by the logger factory
// when asked for a logger
LoggerFactory.configureBuilder((name) => new LoggerImpl(name, debugEnabled:true));
// Get logger inside application code
Logger logger = LoggerFactory.getLogger("name");
The logger supports nested diagnostic contexts which can be used to track application state like this
logger.putContext("context-name", "context-message");
try {
// log messages from now gets added a context-message
:
logger.debug("something important happend");
} finally {
// stop logging with context-message
logger.removeContext("context-name");
}
Some missing stuff (feel free to add more):
- Implement a file appender
- Create a Dart version of sprintf and use it for implementing the formatters
- Figure out how best to configure the log output format
- When reflection arrives in Dart add ability to show the class/line where the log message originated
feel free to send in patched for these (or other features you miss).
BSD License (Same as Dart itself). See LICENSE file.