Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 1.75 KB

README.md

File metadata and controls

56 lines (42 loc) · 1.75 KB

Build Status

Log4Dart

Logging library with multiple appenders, configurable formatting and log tracing.

Getting Started

1. Add the folowing to your pubspec.yaml and run pub install

	dependencies:
	  log4dart: any

2. Add log4dart to some code and run it

	import "package:log4dart/log4dart.dart";
	
	main() {
		var myClass = new MyClass();
		myClass.someMethod();
	}
		
	class MyClass {
		static final _logger = LoggerFactory.getLoggerFor(MyClass);
	
		someMethod() {
			_logger.info("a info message");
			// :
			_logger.warnFormat("%s %s", ["message", "formatting"]);
		}
	}

Creating Loggers

Log4Dart is split in multiple libraries so it can run on both servers and in browsers.

// for client side logging (works both on the VM and when compiled to JS)
import "package:log4dart/log4dart.dart";

// for VM logging, allows you to log to files (does not compile to JS) 
import "package:log4dart/log4dart_vm.dart";

When you want to retrieve a logger instance you can do it in one of two ways

  1. LoggerFactory.getLoggerFor(MyClass) - logger with the fully qualified name of MyClass
  2. LoggerFactory.getLogger("MyClass") - logger with the name "MyClass"

Where the qualified name is the library name and type name concatenated together.

More Information

The configuration guide covers everything from log level setup to output formatting. For more advanced features, such as log tracing, check out the advanced feature guide.