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)?
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.
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().
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With