Skip to content

Commit 43fd0b1

Browse files
committed
Replace most console.log with larkin.trace (which can be silenced in production)
1 parent 51640c1 commit 43fd0b1

26 files changed

+93
-81
lines changed

v2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ unusable parameters.
6767

6868
### .log(type, messsage)
6969

70-
Simply log something to the console. A convinience for `console.log`.
70+
Simply log something to the console. A convinience for `larkin.trace`.
7171

7272
### .defineFields(route, callback)
7373

v2/_legacy_code/_units.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ module.exports = function (req, res, next, cb) {
570570

571571
larkin.query(sql, params, function (error, result) {
572572
if (error) {
573-
console.log(error);
573+
larkin.trace(error);
574574
callback(error);
575575
} else {
576576
if (req.query.response === "long" || cb) {
@@ -659,7 +659,7 @@ module.exports = function (req, res, next, cb) {
659659
],
660660
function (error, data, result) {
661661
if (error) {
662-
console.log(error);
662+
larkin.trace(error);
663663
if (cb) {
664664
cb(error);
665665
} else {

v2/columns.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = function (req, res, next, callback) {
3737
if (!result || !result.length) {
3838
return callback(null, null);
3939
}
40-
console.log(result[0]);
40+
larkin.trace(result[0]);
4141
var cols = _.groupBy(result, function (d) {
4242
return d.col_id;
4343
});
@@ -234,7 +234,7 @@ module.exports = function (req, res, next, callback) {
234234
],
235235
function (error, unit_data, column_data) {
236236
if (error) {
237-
console.log(error);
237+
larkin.trace(error);
238238
if (callback) {
239239
return callback(error);
240240
}

v2/credentials.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ const dotenv = require("dotenv");
22
// Load environment variables from .env file
33
dotenv.config();
44

5+
// Set up debug mode if needed
6+
exports.debug = process.env.NODE_ENV === "development";
7+
if (exports.debug) {
8+
// eslint-disable-next-line no-console
9+
console.log("Debug mode enabled");
10+
}
11+
512
// Keep old TLS handling for now
613
if (process.env.NODE_TLS_REJECT_UNAUTHORIZED == null) {
714
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

v2/definitions/autocomplete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module.exports = function (req, res, next) {
6969
"SELECT id::integer, name, type, category FROM macrostrat.autocomplete WHERE name ILIKE :query AND type = ANY(:types) LIMIT :limit",
7070
{ query: query, types: types, limit: limit },
7171
function (error, result) {
72-
console.log(result);
72+
larkin.trace(result);
7373
if (error) {
7474
larkin.error(req, res, next, error);
7575
} else {

v2/definitions/drilling_sites.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ module.exports = function (req, res, next, cb) {
6363
if ("sample" in req.query) {
6464
sql += " LIMIT 5";
6565
}
66-
console.log(
66+
larkin.trace(
6767
"print format BEFORE submitting query",
6868
api.acceptedFormats.geo[req.query.format],
6969
);
70-
console.log("printing params before they go through larkin", params);
70+
larkin.trace("printing params before they go through larkin", params);
7171

7272
larkin.queryPg("burwell", sql, params, function (error, result) {
7373
if (error) {
@@ -81,7 +81,7 @@ module.exports = function (req, res, next, cb) {
8181
// if a geographic format is requested
8282
if (req.query.format && api.acceptedFormats.geo[req.query.format]) {
8383
//there is an error here we need to figure out
84-
console.log("printing results before geoparse", result);
84+
larkin.trace("printing results before geoparse", result);
8585
dbgeo.parse(
8686
result.rows,
8787
{

v2/definitions/econs.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ module.exports = function (req, res, next, cb) {
88
return larkin.info(req, res, next);
99
}
1010

11-
let sql = `SELECT econs.id AS econ_id,
12-
econ AS name,
11+
let sql = `SELECT econs.id AS econ_id,
12+
econ AS name,
1313
econ_type AS type,
14-
econ_class AS class,
15-
econ_color AS color,
16-
COUNT(distinct units_sections.unit_id) AS t_units
17-
FROM macrostrat.econs
18-
LEFT JOIN macrostrat.unit_econs ON unit_econs.econ_id = econs.id
19-
LEFT JOIN macrostrat.units_sections ON units_sections.unit_id = unit_econs.unit_id
14+
econ_class AS class,
15+
econ_color AS color,
16+
COUNT(distinct units_sections.unit_id) AS t_units
17+
FROM macrostrat.econs
18+
LEFT JOIN macrostrat.unit_econs ON unit_econs.econ_id = econs.id
19+
LEFT JOIN macrostrat.units_sections ON units_sections.unit_id = unit_econs.unit_id
2020
`;
2121
//changed params from array back to dict.
2222
let params = {};
@@ -45,9 +45,9 @@ module.exports = function (req, res, next, cb) {
4545
}
4646

4747
larkin.queryPg("burwell", sql, params, function (error, data) {
48-
console.log("CALLBACK DATA ", cb);
48+
larkin.trace("CALLBACK DATA ", cb);
4949
if (error) {
50-
console.log("The error still returned from larkin");
50+
larkin.trace("The error still returned from larkin");
5151
if (cb) {
5252
cb(error);
5353
} else {

v2/definitions/lithologies.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ module.exports = function (req, res, next, cb) {
3636
params["lith"] = larkin.parseMultipleStrings(req.query.lith);
3737
}
3838
if (req.query.lith_id) {
39-
console.log("LITH ID", req.query.lith_id);
40-
console.log("LITH ID TYPESSS", typeof req.query.lith_id);
39+
larkin.trace("LITH ID", req.query.lith_id);
40+
larkin.trace("LITH ID TYPESSS", typeof req.query.lith_id);
4141

4242
where.push("liths.id = ANY(:lith_id)");
4343
params["lith_id"] = larkin.parseMultipleIds(req.query.lith_id);
44-
console.log("PARAMS", params);
44+
larkin.trace("PARAMS", params);
4545
}
4646
if (req.query.lith_like) {
4747
where.push("lith LIKE :lith");

v2/definitions/strat_names.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ module.exports = function (req, res, next, cb) {
133133

134134
larkin.queryPg("burwell", sql, params, function (error, response) {
135135
if (error) {
136-
console.log(error);
136+
larkin.trace(error);
137137
if (cb) {
138138
cb(error);
139139
} else {

v2/eodp.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ module.exports = function (req, res, next) {
2525
STRING_AGG(trim(concat_WS(' ',principal_lith_prefix_cleaned,cleaned_lith,principal_lith_suffix_cleaned)),'|' ORDER BY top_depth) as primary_lith,
2626
STRING_AGG(lith_id::text,'|' ORDER BY top_depth) as lith_id,
2727
STRING_AGG(standard_minor_lith,'|' ORDER BY top_depth) as minor_lith
28-
FROM macrostrat.offshore_baggage ob
29-
JOIN macrostrat.offshore_sites USING (col_id)
28+
FROM macrostrat.offshore_baggage ob
29+
JOIN macrostrat.offshore_sites USING (col_id)
3030
JOIN macrostrat.col_groups on col_group_id=col_groups.id
3131
`;
3232
var where = [];
@@ -71,13 +71,13 @@ module.exports = function (req, res, next) {
7171
}
7272

7373
larkin.queryPg("burwell", sql, params, function (error, response) {
74-
console.log("RESPONSE FROM LARKIN", response);
74+
larkin.trace("RESPONSE FROM LARKIN", response);
7575
if (error) {
7676
larkin.error(req, res, next, error);
7777
} else {
7878
//all parameter isn't formatted properly.
7979
if (req.query.format === undefined || req.query.format !== "csv") {
80-
console.log("RESPONSE FROM LARKIN 3", response);
80+
larkin.trace("RESPONSE FROM LARKIN 3", response);
8181

8282
for (var i = 0; i < response.rows.length; i++) {
8383
response.rows[i].top_depth = larkin.jsonifyPipes(
@@ -127,8 +127,8 @@ module.exports = function (req, res, next) {
127127
},
128128
})),
129129
};
130-
console.log("RESPONSE FROM LARKIN", response);
131-
console.log("GEOJSON FROM GEO LARKIN", geoJson);
130+
larkin.trace("RESPONSE FROM LARKIN", response);
131+
larkin.trace("GEOJSON FROM GEO LARKIN", geoJson);
132132
// Send transformed GeoJSON data
133133
larkin.sendData(
134134
req,

0 commit comments

Comments
 (0)