How to enable SQL logging in Aqueduct 3?

Viewed 254

It would be very useful for me to see in the terminal what requests are executed and how long they take. Logging of HTTP requests works fine, but I did not find a similar function for SQL. Is there a way to enable logging globally using config.yaml or in prepare() of ApplicationChannel?

1 Answers

Looks like i found dirty hack solution:

Future prepare() async {
  logger.onRecord.listen((rec) => print("$rec ${rec.error ?? ""} ${rec.stackTrace ?? ""}"));
  logger.parent.level = Level.FINE;
  ...
}

We need to set log level higher then default INFO. All SQL queries log their requests on FINE level.

I expected that this setting should be able to load from a config.yaml, but I did not find anything similar.

More about log levels can be find here

Related