Reputation: 309
This is a duplicate of another question. Actually I have exactly the same question and providing Logger.root.onRecord.listen
didn't help. Also this answer reports developer.log() can be used to log data to flutter console.
Source code:
import 'dart:io';
import 'dart:developer' as developer;
import 'package:logging/logging.dart';
void main(List<String> arguments) {
stderr.writeln('Hello from stderr');
stdout.writeln('Hello from stdout');
print('Hello from print');
print('Logger level ${Logger.root.level}');
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((r) => print(r));
var log = Logger('MyLogger');
for (var level in Level.LEVELS) {
print('Level: $level, isLoggable: ${log.isLoggable(level)}');
log.log(level, 'Log message with level $level');
}
developer.log('Hello from developer.log');
}
That produces the following output:
/opt/java/jdk/flutter/bin/cache/dart-sdk/bin/dart --enable-asserts /home/m_pashka/Projects/tests/flutter/dart-test1/bin/dart_test3.dart
Hello from stdout
Hello from print
Logger level INFO
Level: ALL, isLoggable: true
[ALL] MyLogger: Log message with level ALL
Level: FINEST, isLoggable: true
[FINEST] MyLogger: Log message with level FINEST
Level: FINER, isLoggable: true
[FINER] MyLogger: Log message with level FINER
Level: FINE, isLoggable: true
[FINE] MyLogger: Log message with level FINE
Level: CONFIG, isLoggable: true
[CONFIG] MyLogger: Log message with level CONFIG
Level: INFO, isLoggable: true
[INFO] MyLogger: Log message with level INFO
Level: WARNING, isLoggable: true
[WARNING] MyLogger: Log message with level WARNING
Level: SEVERE, isLoggable: true
[SEVERE] MyLogger: Log message with level SEVERE
Level: SHOUT, isLoggable: true
[SHOUT] MyLogger: Log message with level SHOUT
Level: OFF, isLoggable: true
[OFF] MyLogger: Log message with level OFF
Hello from stderr
Process finished with exit code 0
No Hello from developer.log
line there. I also tried different dart versions: 2.0.0, 2.13.4, 2.14.4.
I used dart command line to run example:
<dart_sdk_path>/dart-sdk/bin/dart --enable-asserts <project_path>/<file>.dart
Also tried this snippet in Dart Pad:
import 'dart:developer' as developer;
void main() {
developer.log('Hello from developer.log');
developer.log('log me', name: 'my.app.category');
print('Hello from print');
}
Output is:
Hello from print
Upvotes: 8
Views: 11301
Reputation: 747
**There is an issue with a log for printing map data you need to try this package **
using this you can easily print different types of responses under different tags listed below
logger.v("Verbose log");
logger.d("Debug log");
logger.i("Info log");
logger.w("Warning log");
logger.e("Error log");
logger.wtf("What a terrible failure log");
Upvotes: 1
Reputation: 309
As it was mentioned earlier by Christopher Moore developer.log()
doesn't print anything to the dart console. Instead it emits events that can be observed by the Logging View of DevTools. You can use Install and run DevTools from the command line for instructions on how to install and launch DevTools and Start the target app section of Dart DevTools for command to start the Dart command-line app to be observed in dev tools.
So it is something like
# dart pub global activate devtools
to install devtools# dart pub global run devtools
to start devtools (can be omited)# dart run --pause-isolates-on-start --observe main.dart
to start main.dart with devtools connected. On this step you can either use short URL and put into DevTools web UI or just use long link to open DevTools in your browser.Still not sure about correctness of Debugging Flutter apps programmatically # Logging page documentation. It mentions
Note: You can view logs in DevTools’ Logging view or in your system console. This sections shows how to set up your logging statements.
But it doesn't mention that stderr.writeln()
is visible in Logging view but developer.log()
is not visible in console output. Also it is unclear why is that Logging view not visible in Intellij Idea/Android studio.
Upvotes: 8