Add level to UTILS logs

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-03-30 21:08:16 +01:00
parent 132a8697b1
commit ea50577946
3 changed files with 8 additions and 8 deletions

View File

@ -4,10 +4,10 @@ const san = require('../utils/sanitizer.utils') // Sanitiser
async function checkCrs(input){ async function checkCrs(input){
var INPUT = input.toUpperCase() var INPUT = input.toUpperCase()
log.out(`ldbUtils.checkCrs: Building database query to find: '${INPUT}'`) log.out(`ldbUtils.checkCrs: Building database query to find: '${INPUT}'`, "info")
var query = {'$or':[{'3ALPHA':INPUT},{'TIPLOC':INPUT},{'STANOX':INPUT}]}; var query = {'$or':[{'3ALPHA':INPUT},{'TIPLOC':INPUT},{'STANOX':INPUT}]};
var result = await db.query("stations", query) var result = await db.query("stations", query)
log.out(`ldbUtils.checkCrs: Query results: ${JSON.stringify(result)}`) log.out(`ldbUtils.checkCrs: Query results: ${JSON.stringify(result)}`, "info")
return result return result
} }
@ -27,9 +27,9 @@ async function cleanMessages(input){ // Needs to be moved to the frontend `ensur
async function cleanServices(input){ // Need to triple check but I don't think this is used anymore. async function cleanServices(input){ // Need to triple check but I don't think this is used anymore.
var out = [] var out = []
if (!Array.isArray(input)) { if (!Array.isArray(input)) {
log.out(`ldbUtils.cleanServices: Transforming input: ${input}`) log.out(`ldbUtils.cleanServices: Transforming input: ${input}`, "depr")
out.push(input) out.push(input)
log.out(`ldbUtils.cleanServices: Returning output: ${out}`) log.out(`ldbUtils.cleanServices: Returning output: ${out}`, "depr")
return out; return out;
} else { } else {
return input; return input;

View File

@ -1,11 +1,11 @@
const environment = process.env.NODE_ENV; const environment = process.env.NODE_ENV;
async function out(msg, level = 'OTHR') { async function out(msg, level = 'othr') {
if (environment === "production" && level === "info") { if (environment === "production" && level === "info") {
return; return;
} else { } else {
const time = new Date().toISOString(); const time = new Date().toISOString();
console.log(`${time} - - ${level.toUpperCase()} - ${msg}`); console.log(`${time} - ${level.toUpperCase()} - ${msg}`);
} }
} }

View File

@ -19,7 +19,7 @@ string.removeSpace("@abcd efgh"); // @abcdefgh
function cleanApiEndpointTxt(input) { function cleanApiEndpointTxt(input) {
var output = clean.sanitize.keepSpace(input) var output = clean.sanitize.keepSpace(input)
if (output != input){ if (output != input){
log.out(`sanitizerUtils.cleanApiEndpoint: WARN: Sanitizing changed string. Input = ${input}`); log.out(`sanitizerUtils.cleanApiEndpoint: WARN: Sanitizing changed string. Input = ${input}`, "warn");
} }
return output return output
} }
@ -27,7 +27,7 @@ function cleanApiEndpointTxt(input) {
function cleanApiEndpointNum(input) { function cleanApiEndpointNum(input) {
var output = clean.sanitize.keepNumber(input) var output = clean.sanitize.keepNumber(input)
if (output != input){ if (output != input){
log.out(`sanitizerUtils.cleanApiEndpointNum: WARN: Sanitizing changed string. Input = ${input}`); log.out(`sanitizerUtils.cleanApiEndpointNum: WARN: Sanitizing changed string. Input = ${input}`, "warn");
} }
return output return output
} }