3

I'm new to Loopback. I have used Sequelize ORM in the past, and I'm used to seeing Sequelize output the SQL statements to the Console. How can I do the same with Loopback 4? I've done extensive searching on the web, and I found a place where they suggested to add debug: true to the datasource config json file. However, this change had no effect.

Any help is greatly appreciated.

Peruz Carlsen
  • 572
  • 2
  • 10

1 Answers1

8

Hello from the LoopBack team

We use debug module to deal with debug logging and most connectors print SQL statements in their debug log.

You can enable debug logs by setting the environment variable DEBUG. For example, on a Unix system (Unix, MacOS), you can run the following command:

DEBUG=loopback:connector* npm start

On Windows, you have to set the variable in a standalone command.

set DEBUG=loopback:connector*
npm start
Miroslav Bajtoš
  • 10,667
  • 1
  • 41
  • 99
  • I'm using Windows. I did as you suggested. After I execute the two statements you suggested, I still don't see the SQL statement in the console. Should I be looking for the debug output somewhere else? – Peruz Carlsen Jan 08 '20 at 19:59
  • That's weird. Debug statements are printed to standard error output, you should see them in the console. Do you see at least _some_ debug statements? Also, what connector are you using? – Miroslav Bajtoš Jan 09 '20 at 07:28
  • I'm using loopback:connector:mssql connector. I built my app using lb4 app and I then started adding datasource, models, repositories, and controllers. And now I would like to see the SQL statements that are generated by lb. – Peruz Carlsen Jan 10 '20 at 14:45
  • On Windows, you can also use the system environment variables – Andrew Jan 12 '22 at 23:24