Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see the output of Logger in dartlang (Dartium or command-line)

Tags:

logging

dart

I'd like to be able to log for debugging purpose from a package that could be either part of a web app or a command line application

Current I use

print('some text');

But I cannot control at runtime what is printed (DEBUG, INFO, ...) While I'm used to use java.util.logging.Logger in java, I could not find a way to use the Logger class in the logging package of dart, in either a web or command line application.

Logger logger = new Logger('test');
logger.info('some text');

The simple code above compiles fine but I cannot see any ouput in either the console of Dartium or the Output pane in the DartEditor.

Has anyone successfully used it (and see some text)?

like image 602
alextk Avatar asked Feb 12 '13 17:02

alextk


People also ask

How do I print my dart login?

import 'dart:developer'; log('data: $data'); You can also use print() , but this is not a good practice because it can slow down your program in a production environment.

How do you get the log in flutter?

The Dart print() function outputs to the system console, which you can view using flutter logs (which is basically a wrapper around adb logcat). If you output too much at once, then Android sometimes discards some log lines. To avoid this, you can use debugPrint().

How do I print long data in flutter?

Using Print() method Example print("This Message using Print method"); print("This Message using Print method"); Suppose, the log message or error log message is long the android just ignores some of the log & print only half of it, In that case you can use 'debugPrint()' it will print whole list of log data error.


1 Answers

In my Dart Bat-belt, I keep a function like this:

void printLogRecord(LogRecord r) {
  print("${r.loggerName} ${r.level} ${r.message}");
}

Then I'll add it to a Logger, typically the root logger:

Logger.root.level = Level.FINE;
Logger.root.onRecord.listen(printLogRecord);
like image 155
Justin Fagnani Avatar answered Sep 20 '22 04:09

Justin Fagnani