Add log levels to services
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
45b049714f
commit
c00be2aeda
@ -1,6 +1,6 @@
|
|||||||
const version = {
|
const version = {
|
||||||
api: ["/api/v1/",],
|
api: ["/api/v1/",],
|
||||||
app: "1.1.3"
|
app: "1.1.4"
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = version;
|
module.exports = version;
|
@ -14,17 +14,17 @@ const db = client.db(dbName);
|
|||||||
|
|
||||||
async function query(collection, query){
|
async function query(collection, query){
|
||||||
await client.connect();
|
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 qcoll = db.collection(collection);
|
||||||
var qcursor = qcoll.find(query)
|
var qcursor = qcoll.find(query)
|
||||||
qcursor.project({_id: 0})
|
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)
|
increment(collection)
|
||||||
return (await qcursor.toArray());
|
return (await qcursor.toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
async function increment(target) {
|
async function increment(target) {
|
||||||
log.out(`dbAccess.increment: Incrementing counter for: ${target}`)
|
log.out(`dbAccess.increment: Incrementing counter for: ${target}`, "info")
|
||||||
await client.connect();
|
await client.connect();
|
||||||
let col = db.collection("meta");
|
let col = db.collection("meta");
|
||||||
let update = {}
|
let update = {}
|
||||||
|
@ -10,7 +10,7 @@ const san = require('../utils/sanitizer.utils')
|
|||||||
const col = "corpus"
|
const col = "corpus"
|
||||||
|
|
||||||
async function name(id){
|
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())
|
var name = san.cleanApiEndpointTxt(id.toUpperCase())
|
||||||
query = {NLCDESC: name}
|
query = {NLCDESC: name}
|
||||||
//var data = await db.query(col,query)
|
//var data = await db.query(col,query)
|
||||||
@ -18,7 +18,7 @@ async function name(id){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function crs(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())
|
var crs = san.cleanApiEndpointTxt(id.toUpperCase())
|
||||||
query = {'3ALPHA': crs}
|
query = {'3ALPHA': crs}
|
||||||
//var data = await db.query(col,query)
|
//var data = await db.query(col,query)
|
||||||
@ -26,16 +26,16 @@ async function crs(id){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function nlc(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)
|
var nlc = san.cleanApiEndpointNum(id)
|
||||||
query = {NLC: parseInt(nlc)}
|
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)
|
//var data = await db.query(col,query)
|
||||||
return await db.query(col,query)
|
return await db.query(col,query)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function tiploc(id){
|
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())
|
var tiploc = san.cleanApiEndpointTxt(id.toUpperCase())
|
||||||
query = {TIPLOC: tiploc}
|
query = {TIPLOC: tiploc}
|
||||||
//var data = await db.query(col,query)
|
//var data = await db.query(col,query)
|
||||||
@ -43,7 +43,7 @@ async function tiploc(id){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function stanox(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)
|
var stanox = san.cleanApiEndpointNum(id)
|
||||||
query = {STANOX: String(stanox)}
|
query = {STANOX: String(stanox)}
|
||||||
//var data = await db.query(col,query)
|
//var data = await db.query(col,query)
|
||||||
|
@ -2,7 +2,7 @@ const axios = require('axios')
|
|||||||
const log = require('../utils/log.utils')
|
const log = require('../utils/log.utils')
|
||||||
|
|
||||||
async function processor(data) {
|
async function processor(data) {
|
||||||
log.out(`issueService.processor: Issue received`)
|
log.out(`issueService.processor: Issue received`, "info")
|
||||||
let out = {}
|
let out = {}
|
||||||
out.title = data.subject.replace(/<[^>]+>|[\*\$]/g, '');
|
out.title = data.subject.replace(/<[^>]+>|[\*\$]/g, '');
|
||||||
out.body = data.msg.replace(/<[^>]+>|[\*\$]/g, '')
|
out.body = data.msg.replace(/<[^>]+>|[\*\$]/g, '')
|
||||||
@ -20,10 +20,10 @@ async function sendToGitea(body) {
|
|||||||
var res = await axios.post(url, body, opts)
|
var res = await axios.post(url, body, opts)
|
||||||
// Need to read the output from the POST and pass the result upwards to the client.
|
// Need to read the output from the POST and pass the result upwards to the client.
|
||||||
if (res.status == 201) {
|
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"}
|
return {status: res.status,message:"issue created"}
|
||||||
} else {
|
} 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"}
|
return {status: res.status,message:"issue not created"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
async function getAlive(){
|
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"}}
|
return {code: 200, state: {state: "alive",noise: "twit-twoo"}}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getReady(){
|
async function getReady(){
|
||||||
log.out(`kubeServices.getReady: ready hook checked`)
|
log.out(`kubeServices.getReady: ready hook checked`, "info")
|
||||||
return "not_implemented";
|
return "not_implemented";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,19 +14,19 @@ async function get(body, id){
|
|||||||
var obj = await util.checkCrs(cleanId);
|
var obj = await util.checkCrs(cleanId);
|
||||||
try {
|
try {
|
||||||
var crs = obj[0]['3ALPHA'];
|
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);
|
var data = arrDepBoard(crs);
|
||||||
db.increment("ldbws");
|
db.increment("ldbws");
|
||||||
await data;
|
await data;
|
||||||
} catch (err) {
|
} 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.'};
|
var data = {ERROR:'NOT_FOUND',description:'The entered station was not found. Please check and try again.'};
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function arrDepBoard(CRS){
|
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 {
|
try {
|
||||||
var options = {
|
var options = {
|
||||||
numRows: 10,
|
numRows: 10,
|
||||||
@ -36,7 +36,7 @@ async function arrDepBoard(CRS){
|
|||||||
var reply = api.call("GetArrDepBoardWithDetails", options, false, false)
|
var reply = api.call("GetArrDepBoardWithDetails", options, false, false)
|
||||||
return await reply
|
return await reply
|
||||||
} catch (err) {
|
} 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.`};
|
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.`};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -4,13 +4,13 @@ const os = require('os')
|
|||||||
|
|
||||||
async function getStations(){
|
async function getStations(){
|
||||||
var out = db.query("stations")
|
var out = db.query("stations")
|
||||||
log.out(`listServices.getStations: Fetching stations list`)
|
log.out(`listServices.getStations: Fetching stations list`, "info")
|
||||||
return await out;
|
return await out;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCorpus(){
|
async function getCorpus(){
|
||||||
var out = db.query("corpus")
|
var out = db.query("corpus")
|
||||||
log.out(`listServices.getCorpus: Fetching CORPUS list`)
|
log.out(`listServices.getCorpus: Fetching CORPUS list`, "info")
|
||||||
return await out;
|
return await out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,17 +4,17 @@ const os = require('os')
|
|||||||
const vers = require('../configs/version.configs')
|
const vers = require('../configs/version.configs')
|
||||||
|
|
||||||
async function hits(){
|
async function hits(){
|
||||||
log.out("statsServices.hits: Statistics Requested")
|
log.out("statsServices.hits: Statistics Requested", "info")
|
||||||
var dat = db.query("meta", {target: "counters"});
|
var dat = db.query("meta", {target: "counters"});
|
||||||
var ver = db.query("meta", {target: "versions"});
|
var ver = db.query("meta", {target: "versions"});
|
||||||
log.out(`statsServices.hits: fetched server meta`)
|
log.out(`statsServices.hits: fetched server meta`, "info")
|
||||||
let out = {};
|
let out = {};
|
||||||
out.host = os.hostname();
|
out.host = os.hostname();
|
||||||
out.mode = process.env.NODE_ENV;
|
out.mode = process.env.NODE_ENV;
|
||||||
out.verBkend = vers.app;
|
out.verBkend = vers.app;
|
||||||
out.dat = await dat;
|
out.dat = await dat;
|
||||||
out.ver = await ver;
|
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;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user