Console.log In Dart Language


Answer :

Simple:



print('This will be logged to the console in the browser.');


A basic top-level print function is always available in all implementations of Dart (browser, VM, etc.). Because Dart has string interpolation, it's easy to use that to print useful stuff too:



var a = 123;
var b = new Point(2, 3);
print('a is $a, b is ${b.x}, ${b.y}');


Also, dart:html allows use of window.console object.



import 'dart:html';

void main() {
window.console.debug("debug message");
window.console.info("info message");
window.console.error("error message");
}


It’s easy! Just import the logging package:



import 'package:logging/logging.dart';


Create a logger object:



final _logger = Logger('YourClassName');


Then in your code when you need to log something:



_logger.info('Request received!');


If you catch an exception you can log it and the stacktrace as well.



_logger.severe('Oops, an error occurred', err, stacktrace);


Logging package documentation : https://github.com/dart-lang/logging



Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable