Add custom debug logs

This commit is contained in:
cgonzalez 2021-03-19 10:33:47 +00:00
parent 62558e1c7f
commit b9d7cb7cb6
3 changed files with 19 additions and 1 deletions

View File

@ -73,7 +73,7 @@ module.exports = class QueryController {
function handleQuery ({ stats } = {}) { function handleQuery ({ stats } = {}) {
return function handleQueryMiddleware (req, res, next) { return function handleQueryMiddleware (req, res, next) {
const { user: username, userDbParams: dbopts, userLimits } = res.locals; const { user: username, userDbParams: dbopts, userLimits, logger } = res.locals;
const { orderBy, sortOrder, limit, offset } = res.locals.params; const { orderBy, sortOrder, limit, offset } = res.locals.params;
const { sql, skipfields, decimalPrecision, filename, callback } = res.locals.params; const { sql, skipfields, decimalPrecision, filename, callback } = res.locals.params;
@ -107,6 +107,8 @@ function handleQuery ({ stats } = {}) {
res.header('X-Served-By-DB-Host', dbopts.host); res.header('X-Served-By-DB-Host', dbopts.host);
} }
logger.info({ custom: true }, 'Starting formatter handler');
formatter.sendResponse(opts, (err) => { formatter.sendResponse(opts, (err) => {
formatter = null; formatter = null;

View File

@ -1,5 +1,7 @@
'use strict'; 'use strict';
const serverOptions = require('./../../server-options');
const { logger } = serverOptions();
var crypto = require('crypto'); var crypto = require('crypto');
var step = require('step'); var step = require('step');
var fs = require('fs'); var fs = require('fs');
@ -93,9 +95,13 @@ OgrFormat.prototype.toOGR = function (options, outFormat, outFilename, callback)
step( step(
function fetchColumns () { function fetchColumns () {
logger.info({custom: true}, 'Getting dataset columns');
var colsql = 'SELECT * FROM (' + sql + ') as _cartodbsqlapi LIMIT 0'; var colsql = 'SELECT * FROM (' + sql + ') as _cartodbsqlapi LIMIT 0';
pg = new PSQL(dbopts); pg = new PSQL(dbopts);
pg.query(colsql, this); pg.query(colsql, this);
logger.info({ custom: true, colsql: colsql }, 'Dataset columns query done');
}, },
function findSRS (err, result) { function findSRS (err, result) {
if (err) { if (err) {
@ -177,6 +183,8 @@ OgrFormat.prototype.toOGR = function (options, outFormat, outFilename, callback)
ogrargs.push('-nln', outLayername); ogrargs.push('-nln', outLayername);
logger.info({ custom: true }, 'Executing ogr2ogr command');
// TODO: research if `exec` could fit better than `spawn` // TODO: research if `exec` could fit better than `spawn`
var child = spawn(ogr2ogr, ogrargs); var child = spawn(ogr2ogr, ogrargs);
@ -226,6 +234,8 @@ OgrFormat.prototype.toOGR = function (options, outFormat, outFilename, callback)
}; };
OgrFormat.prototype.toOGR_SingleFile = function (options, fmt, callback) { OgrFormat.prototype.toOGR_SingleFile = function (options, fmt, callback) {
logger.info({ custom: true }, 'Generating filename');
var dbname = options.dbopts.dbname; var dbname = options.dbopts.dbname;
var userId = options.dbopts.user; var userId = options.dbopts.user;
var gcol = options.gcol; var gcol = options.gcol;
@ -246,6 +256,8 @@ OgrFormat.prototype.toOGR_SingleFile = function (options, fmt, callback) {
var outdirpath = tmpdir + '/sqlapi-' + process.pid + '-' + reqKey; var outdirpath = tmpdir + '/sqlapi-' + process.pid + '-' + reqKey;
var dumpfile = outdirpath + ':cartodb-query.' + ext; var dumpfile = outdirpath + ':cartodb-query.' + ext;
logger.info({ custom: true, dumpfile: dumpfile }, 'File name generated');
// TODO: following tests: // TODO: following tests:
// - fetch query with no "the_geom" column // - fetch query with no "the_geom" column
this.toOGR(options, fmt, dumpfile, callback); this.toOGR(options, fmt, dumpfile, callback);

View File

@ -1,6 +1,8 @@
'use strict'; 'use strict';
var Ogr = require('./../ogr'); var Ogr = require('./../ogr');
const serverOptions = require('./../../../server-options');
const { logger } = serverOptions();
function CsvFormat () {} function CsvFormat () {}
@ -10,6 +12,8 @@ CsvFormat.prototype._contentType = 'text/csv; charset=utf-8; header=present';
CsvFormat.prototype._fileExtension = 'csv'; CsvFormat.prototype._fileExtension = 'csv';
CsvFormat.prototype.generate = function (options, callback) { CsvFormat.prototype.generate = function (options, callback) {
logger.info({ custom: true }, 'Generating CSV format');
this.toOGR_SingleFile(options, 'CSV', callback); this.toOGR_SingleFile(options, 'CSV', callback);
}; };