Migrate more console messages to debug()

This commit is contained in:
D. Berge
2022-05-12 22:09:08 +02:00
parent 1b925502bc
commit 3ed8339aa3
4 changed files with 58 additions and 10 deletions

View File

@@ -6,6 +6,7 @@ const cookieParser = require('cookie-parser')
const maybeSendAlert = require("../lib/alerts");
const mw = require('./middleware');
const { ERROR, INFO, DEBUG } = require('DOUGAL_ROOT/debug')(__filename);
const verbose = process.env.NODE_ENV != 'test';
const app = express();
app.locals.version = "0.3.1"; // API version
@@ -22,7 +23,7 @@ app.map = function(a, route){
} // else drop through
// get: function(){ ... }
case 'function':
if (verbose) console.log('%s %s', key, route);
if (verbose) INFO('%s %s', key, route);
app[key](route, a[key]);
break;
}
@@ -297,10 +298,12 @@ app.use(function (err, req, res, next) {
const alert = {title, message, description, error: err};
console.log("Error:", err);
ERROR("%O", err)
res.set("Content-Type", "application/json");
if (err instanceof Error && err.name != "UnauthorizedError") {
console.error(err.stack);
// console.error(err.stack);
ERROR(err.stack);
res.set("Content-Type", "text/plain");
res.status(500).send('General internal error');
maybeSendAlert(alert);
@@ -317,7 +320,7 @@ app.use(function (err, req, res, next) {
app.disable('x-powered-by');
app.enable('trust proxy');
console.log('trust proxy is ' + (app.get('trust proxy')? 'on' : 'off'));
INFO('trust proxy is ' + (app.get('trust proxy')? 'on' : 'off'));
const addr = "127.0.0.1";
@@ -325,7 +328,7 @@ if (!module.parent) {
var port = process.env.HTTP_PORT || 3000;
var server = http.createServer(app).listen(port, addr);
console.log('API started on port ' + port);
INFO('API started on port ' + port);
} else {
app.start = function (port = 3000, path) {
@@ -338,7 +341,8 @@ if (!module.parent) {
const server = http.createServer(root).listen(port, addr);
if (server) {
console.log(`API started on port ${port}, prefix: ${path || "/"}`);
// console.log(`API started on port ${port}, prefix: ${path || "/"}`);
INFO(`API started on port ${port}, prefix: ${path || "/"}`);
}
return server;
}