Skip to content

iggymacd/log4dart

Repository files navigation

Log4Dart

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");
}

TODO

Some missing stuff (feel free to add more):

  1. Implement a file appender
  2. Create a Dart version of sprintf and use it for implementing the formatters
  3. Figure out how best to configure the log output format
  4. 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).

License

BSD License (Same as Dart itself). See LICENSE file.

About

Slf4J inspired log implementation for Dart

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published