Console.log in Dart Language

How can I enter the browser console, for example console.log in JavaScript, from the Dart language?

+68
dart console
Jan 21 2018-12-12T00:
source share
5 answers

Plain:

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

The main top-level print function is always available in all Dart implementations (browser, virtual machine, etc.). Since Dart has line interpolation, it's easy to use this to print useful things:

 var a = 123; var b = new Point(2, 3); print('a is $a, b is ${bx}, ${by}'); 
+89
Jan 22 2018-12-12T00:
source share

In addition, dart:html allows you to use the window.console object.

 import 'dart:html'; void main() { window.console.debug("debug message"); window.console.info("info message"); window.console.error("error message"); } 
+52
Jan 22 2018-12-12T00:
source share

It's simple! Just import the registration package:

 import 'package:logging/logging.dart'; 

Create a logger object:

 final _logger = Logger('YourClassName'); 

Then in your code, when you need to enter something:

 _logger.info('Request received!'); 

If you catch an exception, you can register it and the stack trace.

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

Log Package Documentation: https://github.com/dart-lang/logging

+1
Oct. 27 '18 at 22:23
source share

use print ("my literal");

if for printing variables; use $ {myVariable} as in

print ("my answer is $ {myVariable}");

0
May 31 '18 at 11:00
source share

Dart logging using the print("put something here") function Works for the Internet and Flutter.

0
Dec 12 '18 at 10:02
source share



All Articles