Skip to content
This repository has been archived by the owner on Nov 16, 2019. It is now read-only.

Commit

Permalink
Adds beginnings of query logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nullstyle committed Jul 5, 2014
1 parent 338da71 commit 01df521
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/initializers/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ var initializer = module.exports;
initializer.boot = function(stex) {
var Knex = require('knex');
stex.db = global.db = Knex.initialize(stex.conf.get("db"));

stex.db.on("query", function(query) {
log.info({

This comment has been minimized.

Copy link
@matschaffer

matschaffer Dec 16, 2014

Contributor

Was taking a log stroll and noticed a whole lot of output from this line. Any chance we could default this to log.debug or make it configurable?

This comment has been minimized.

Copy link
@nullstyle

nullstyle Dec 16, 2014

Author Contributor

Yeah, I think switching it to debug makes a lot of sense

type: 'query',
sql: query.sql
})
})
};

initializer.shutdown = function(stex) {
Expand Down
5 changes: 5 additions & 0 deletions lib/util/json-log-humanizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ typeProcessors.error = function(data) {
return initialLine + "\n" + stackLines;
};

typeProcessors.query = function(data) {
//TODO: figure out how to get timing info from knex
return "SQL: " + data.sql;
};

humanizer.target = function(options, severity, date, message) {
process.stdout.write(humanizer.processLine(message));
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"db-migrate": "~0.6.4",
"express": "^4.4.5",
"kexec": "^0.2.0",
"knex": "^0.5.14",
"knex": "^0.6.20",
"lodash": "^2.4.1",
"mysql": "^2.2.0",
"nconf": "^0.6.9",
Expand Down

0 comments on commit 01df521

Please sign in to comment.