I am starting a project with sails and mysql, and I do'nt know how configurate it to show the queries executed in the console.
8 Answers
The mysql adapter has a debug variable LOG_QUERIES to send all queries to the console.
LOG_QUERIES=true node myFile.js

- 861
- 6
- 9
-
3This works fine, that variable is in file: sails-mysql/lib/adapter.js Thank you!!! :D – mzalazar Jan 06 '15 at 16:39
-
This work great thanks, @user1278519 and at mzalazar. – Vishnu Mishra Apr 27 '16 at 06:04
-
Note that this is an environment variable. – Tyler Collier Jul 15 '16 at 00:28
Unfortunately this isn't possible with Sails at this time, although the feature has been requested. Your best bet is to inspect the log file provided by your database:
Postgres: How to log PostgreSQL queries?
MySQL: Log all queries in mysql
MongoDB: MongoDB logging all queries
-
4
-
-
This answer is no longer valid with Sails >= 1.1. See below. – NeoNexus DeMortis Dec 15 '22 at 07:23
This solution works for sails >= 1.1.
The sails-mysql
(as of v1.0.0) adapter uses the machinepack-mysql
driver which logs queries to debug
. So all that's needed to log all native queries is to enable the debug flag:
DEBUG=query node app.js

- 384
- 3
- 9
If you're doing Sails.js development on Mac OS with Postgresql.app, you can enable all query logging as follows:
In a new Terminal, edit ~/Library/Application Support/Postgres/var/postgresql.conf
and set:
logging_collector = on
log_directory = 'pg_log'
log_statement = 'all'
Then restart Postgresql.app (click on menubar icon, Quit, then use Spotlight to relaunch).
Then tail the log with:
tail -F ~/Library/Application\ Support/Postgres/var/pg_log/postgresql-2014-10-30_104957.log
You'll have to find the newest postgresql-*log to tail and substitute that above.

- 6,156
- 5
- 39
- 40
My answer might me very late but just found a solution which might help people sails version = 0.12.14
to log quires do following
navigate to node_modules\sails-mysql\lib\adapter.js
locate variable declaration of "log"
then change "process.env.LOG_QUERIES" to "sails.config.LOG_QUERIES"
navigate to
[sails root]/config/env/[development or production].js
add
LOG_QUERIES = 'true',
NOTE :- remember to put ""or '' for true

- 81
- 5
Or add log to sql module.
In mysql this is:
working_dir/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js
function **createQuery** (33)

- 11,356
- 9
- 22
- 40

- 11
- 1
Just add this to your datastore
debug: ["ComQueryPacket"]
config/datastores.js should be look like this
module.exports.datastores = {
default: {
adapter: 'sails-mysql',
user: '*****',
password: "****",
host: '*****',
database: '****',
debug: ["ComQueryPacket"]
}
}

- 1
- 1