From c00be2aeda2f098fb5f788aa1e2b2feb475a1e5e Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Thu, 30 Mar 2023 21:15:21 +0100 Subject: [PATCH] Add log levels to services Signed-off-by: Fred Boniface --- src/configs/version.configs.js | 2 +- src/services/dbAccess.services.js | 6 +++--- src/services/find.services.js | 12 ++++++------ src/services/issue.services.js | 6 +++--- src/services/kube.services.js | 4 ++-- src/services/ldb.services.js | 8 ++++---- src/services/list.services.js | 4 ++-- src/services/stats.services.js | 6 +++--- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/configs/version.configs.js b/src/configs/version.configs.js index fa807a7..184e16b 100644 --- a/src/configs/version.configs.js +++ b/src/configs/version.configs.js @@ -1,6 +1,6 @@ const version = { api: ["/api/v1/",], - app: "1.1.3" + app: "1.1.4" }; module.exports = version; \ No newline at end of file diff --git a/src/services/dbAccess.services.js b/src/services/dbAccess.services.js index 4816a65..d17b5fd 100644 --- a/src/services/dbAccess.services.js +++ b/src/services/dbAccess.services.js @@ -14,17 +14,17 @@ const db = client.db(dbName); async function query(collection, query){ await client.connect(); - log.out(`dbAccess.query: Connecting to collection: '${collection}'`) + log.out(`dbAccess.query: Connecting to collection: '${collection}'`, "info") var qcoll = db.collection(collection); var qcursor = qcoll.find(query) qcursor.project({_id: 0}) - log.out(`dbAccess.query: Running Query: ${JSON.stringify(query)}`) + log.out(`dbAccess.query: Running Query: ${JSON.stringify(query)}`, "info") increment(collection) return (await qcursor.toArray()); } async function increment(target) { - log.out(`dbAccess.increment: Incrementing counter for: ${target}`) + log.out(`dbAccess.increment: Incrementing counter for: ${target}`, "info") await client.connect(); let col = db.collection("meta"); let update = {} diff --git a/src/services/find.services.js b/src/services/find.services.js index c57903a..e2c6349 100644 --- a/src/services/find.services.js +++ b/src/services/find.services.js @@ -10,7 +10,7 @@ const san = require('../utils/sanitizer.utils') const col = "corpus" async function name(id){ - log.out(`findServices.name: Finding station name: ${id}`) + log.out(`findServices.name: Finding station name: ${id}`, "info") var name = san.cleanApiEndpointTxt(id.toUpperCase()) query = {NLCDESC: name} //var data = await db.query(col,query) @@ -18,7 +18,7 @@ async function name(id){ } async function crs(id){ - log.out(`findServices.crs: Finding crs: ${id}`) + log.out(`findServices.crs: Finding crs: ${id}`, "info") var crs = san.cleanApiEndpointTxt(id.toUpperCase()) query = {'3ALPHA': crs} //var data = await db.query(col,query) @@ -26,16 +26,16 @@ async function crs(id){ } async function nlc(id){ - log.out(`findServices.nlc: Finding nlc: ${id}`) + log.out(`findServices.nlc: Finding nlc: ${id}`, "info") var nlc = san.cleanApiEndpointNum(id) query = {NLC: parseInt(nlc)} - log.out(`findServices.nlc: NLC Converted to int: ${query}`) + log.out(`findServices.nlc: NLC Converted to int: ${query}`, "info") //var data = await db.query(col,query) return await db.query(col,query) } async function tiploc(id){ - log.out(`findServices.tiploc: Finding tiploc: ${id}`) + log.out(`findServices.tiploc: Finding tiploc: ${id}`, "info") var tiploc = san.cleanApiEndpointTxt(id.toUpperCase()) query = {TIPLOC: tiploc} //var data = await db.query(col,query) @@ -43,7 +43,7 @@ async function tiploc(id){ } async function stanox(id){ - log.out(`findServices.stanox: Finding stanox: ${id}`) + log.out(`findServices.stanox: Finding stanox: ${id}`, "info") var stanox = san.cleanApiEndpointNum(id) query = {STANOX: String(stanox)} //var data = await db.query(col,query) diff --git a/src/services/issue.services.js b/src/services/issue.services.js index e10597a..c6d5669 100644 --- a/src/services/issue.services.js +++ b/src/services/issue.services.js @@ -2,7 +2,7 @@ const axios = require('axios') const log = require('../utils/log.utils') async function processor(data) { - log.out(`issueService.processor: Issue received`) + log.out(`issueService.processor: Issue received`, "info") let out = {} out.title = data.subject.replace(/<[^>]+>|[\*\$]/g, ''); out.body = data.msg.replace(/<[^>]+>|[\*\$]/g, '') @@ -20,10 +20,10 @@ async function sendToGitea(body) { var res = await axios.post(url, body, opts) // Need to read the output from the POST and pass the result upwards to the client. if (res.status == 201) { - log.out("issueService.sendToGitea: Issue sent to Gitea") + log.out("issueService.sendToGitea: Issue sent to Gitea", "info") return {status: res.status,message:"issue created"} } else { - log.out(`issueService.sendToGitea: Failed to send issue to Gitea: ${res.body}`) + log.out(`issueService.sendToGitea: Failed to send issue to Gitea: ${res.body}`, "err") return {status: res.status,message:"issue not created"} } } diff --git a/src/services/kube.services.js b/src/services/kube.services.js index 16bb61c..9eb5388 100644 --- a/src/services/kube.services.js +++ b/src/services/kube.services.js @@ -1,10 +1,10 @@ async function getAlive(){ - log.out(`kubeServices.getAlive: alive hook checked`) + log.out(`kubeServices.getAlive: alive hook checked`, "info") return {code: 200, state: {state: "alive",noise: "twit-twoo"}} } async function getReady(){ - log.out(`kubeServices.getReady: ready hook checked`) + log.out(`kubeServices.getReady: ready hook checked`, "info") return "not_implemented"; }; diff --git a/src/services/ldb.services.js b/src/services/ldb.services.js index 1b8b498..13cde66 100644 --- a/src/services/ldb.services.js +++ b/src/services/ldb.services.js @@ -14,19 +14,19 @@ async function get(body, id){ var obj = await util.checkCrs(cleanId); try { var crs = obj[0]['3ALPHA']; - log.out(`ldbService.get: Determined CRS for lookup to be: ${crs}`); + log.out(`ldbService.get: Determined CRS for lookup to be: ${crs}`, "info"); var data = arrDepBoard(crs); db.increment("ldbws"); await data; } catch (err) { - log.out(`ldbService.get: Error, Unable to find CRS: ${err}`) + log.out(`ldbService.get: Error, Unable to find CRS: ${err}`, "info") var data = {ERROR:'NOT_FOUND',description:'The entered station was not found. Please check and try again.'}; } return data; } async function arrDepBoard(CRS){ - log.out(`ldbService.arrDepBoard: Trying to fetch ArrDep Board for ${CRS}`) + log.out(`ldbService.arrDepBoard: Trying to fetch ArrDep Board for ${CRS}`, "info") try { var options = { numRows: 10, @@ -36,7 +36,7 @@ async function arrDepBoard(CRS){ var reply = api.call("GetArrDepBoardWithDetails", options, false, false) return await reply } catch (err) { - log.out(`ldbService.arrDepBoard: Lookup Failed for: ${CRS}`) + log.out(`ldbService.arrDepBoard: Lookup Failed for: ${CRS}`, "warn") return {GetStationBoardResult: "not available", Reason: `The CRS code ${CRS} is not valid`, Why: `Sometimes a station will have more than one CRS - for example Filton Abbey Wood has FIT and FAW however schedules are only available when looking up with FIT - this is how the National Rail Enquiries systems work.`}; } }; diff --git a/src/services/list.services.js b/src/services/list.services.js index 613d692..89b9036 100644 --- a/src/services/list.services.js +++ b/src/services/list.services.js @@ -4,13 +4,13 @@ const os = require('os') async function getStations(){ var out = db.query("stations") - log.out(`listServices.getStations: Fetching stations list`) + log.out(`listServices.getStations: Fetching stations list`, "info") return await out; } async function getCorpus(){ var out = db.query("corpus") - log.out(`listServices.getCorpus: Fetching CORPUS list`) + log.out(`listServices.getCorpus: Fetching CORPUS list`, "info") return await out; } diff --git a/src/services/stats.services.js b/src/services/stats.services.js index 05af60e..8238e4a 100644 --- a/src/services/stats.services.js +++ b/src/services/stats.services.js @@ -4,17 +4,17 @@ const os = require('os') const vers = require('../configs/version.configs') async function hits(){ - log.out("statsServices.hits: Statistics Requested") + log.out("statsServices.hits: Statistics Requested", "info") var dat = db.query("meta", {target: "counters"}); var ver = db.query("meta", {target: "versions"}); - log.out(`statsServices.hits: fetched server meta`) + log.out(`statsServices.hits: fetched server meta`, "info") let out = {}; out.host = os.hostname(); out.mode = process.env.NODE_ENV; out.verBkend = vers.app; out.dat = await dat; out.ver = await ver; - log.out(`statsServices.hits: Sending Data: ${JSON.stringify(out)}`) + log.out(`statsServices.hits: Sending Data: ${JSON.stringify(out)}`, "info") return out; }