Skip to content

Commit

Permalink
avniproject/avni-webapp#1225 - set log levels and app name change.
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed May 14, 2024
1 parent ee27fc8 commit fa395cf
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ app.use(function (err, req, res, next) {
})

app.listen(3000, function(){
console.log('Example application listening on port 3000!')
})
console.log('Avni Rule Server listening on port 3000!')
})
6 changes: 3 additions & 3 deletions src/controllers/rulesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const delegateTo = (fn) => async (req, res, next) => {
}

function catchRuleError(err, res) {
console.log(err);
console.warn("rulesController", "catchRuleError", err);
res.status(222)
.json({
status: 'failure',
Expand All @@ -44,7 +44,7 @@ const setGlobalAxiosHeaders = (req) => {
const userName = req.get(USER_NAME_HEADER);
const authToken = req.get(AUTH_TOKEN_HEADER);
const orgUuid = req.get(ORGANISATION_UUID_HEADER);
console.log(`Headers from req: ${userName} ${authToken} ${orgUuid}`);
console.debug(`Headers from req: ${userName} ${authToken} ${orgUuid}`);

if(userName)
axios.defaults.headers.common[USER_NAME_HEADER] = userName;
Expand All @@ -62,7 +62,7 @@ export const buildObservationAndRunRules = async (req, res, next) => {
const responseContract = await BuildObservations(req.body);
res.status(200).json(responseContract);
} catch (err) {
console.log(err);
console.error("rulesController", "buildObservationAndRunRules", err);
res.status(222)
.json({
errors: [`Error in rule server. Message: "${get(err, 'message')}", Stack: "${get(err, 'stack')}"`]
Expand Down
2 changes: 1 addition & 1 deletion src/observationBuilder/BuildObservations.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ async function addObservationValue(observationsHolder, concept, fe, row, errors,
return s3Urls;
})
})).catch(error => errors.push(`Column: "${concept.name}" Error message: "${error}"`));
console.log("s3Urls =>>", s3Urls);
console.debug("s3Urls =>>", s3Urls);
addOrUpdateObs(fe, s3Urls, observationsHolder);
} else {
const oldValue = observationsHolder.getObservationReadableValue(concept);
Expand Down
8 changes: 4 additions & 4 deletions src/services/AuthService.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import _ from 'lodash';
// During CSV upload token sent by the java server might expire so we use upload-user for
// communicating the java server
export const setUploadUser = async () => {
console.log("Cognito details ", cognitoDetails);
console.debug("Cognito details ", cognitoDetails);
if (cognitoDetails.isEmpty()) {
const details = await api.getCognitoDetails();
console.log("Fetched details ", details);
console.debug("Fetched details ", details);
cognitoDetails.setDetails(details);
}
if (!cognitoDetails.isDummy()) {
console.log("Setting up upload user");
console.debug("Setting up upload user");
await setupUploadUser();
}
};
Expand All @@ -25,7 +25,7 @@ const setupUploadUser = async () => {
userPoolWebClientId: cognitoDetails.clientId
});
const currentUser = await Auth.currentUserInfo();
console.log("Current user info ", currentUser);
console.debug("Current user info ", currentUser);
if (_.isEmpty(currentUser) || currentUser.username !== 'upload-user') {
await signIn();
}
Expand Down
6 changes: 3 additions & 3 deletions src/services/RuleEvalService.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export const visitScheduleRule = async (rule, entity, scheduledVisits) => {
} else if (!isEmpty(rulesFromTheBundle)) {
const nextVisits = rulesFromTheBundle
.reduce((schedule, rule) => {
console.log(`RuleEvaluationService`, `Executing Rule: ${rule.name} Class: ${rule.fnName}`);
console.info(`RuleEvaluationService`, `Executing Rule: ${rule.name} Class: ${rule.fnName}`);
return runRuleAndSaveFailure(rule, entityName, entity, schedule);
}, scheduledVisits);
console.log("RuleEvaluationService - Next Visits", nextVisits);
console.debug("RuleEvaluationService - Next Visits", nextVisits);
return nextVisits;
}
return scheduledVisits;
Expand Down Expand Up @@ -170,7 +170,7 @@ const runRuleAndSaveFailure = (rule, entityName, entity, ruleTypeValue, config,
: rule.fn.exec(entity, ruleTypeValue, context, config);
}
} catch (error) {
console.log("Rule-Failure", `Rule failed: ${rule.name}, uuid: ${rule.uuid}`);
console.error("Rule-Failure", `Rule failed: ${rule.name}, uuid: ${rule.uuid}`);
return ruleTypeValue;
}
};
Expand Down
14 changes: 7 additions & 7 deletions src/services/RuleService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {defaults, identity, isFunction, isEmpty} from "lodash";
import { common, motherCalculations } from "avni-health-modules";
import {common, motherCalculations} from "avni-health-modules";
import * as models from "openchs-models";
import api from "./api";
import cache from "./cache";
Expand All @@ -12,7 +12,7 @@ class RuleService {
}

async getApplicableRules(entityUuid, ruleType, ruledEntityType) {
console.log("RuleService",
console.debug("RuleService",
`Getting Rules of Type ${ruleType} for ${ruledEntityType} - ${entityUuid}`);
const rules = await this._getRules();
const matchingRules = rules
Expand All @@ -24,7 +24,7 @@ class RuleService {
}

async _getRuleFunctions(rules = []) {
if (isEmpty(rules)) return [];
if (isEmpty(rules)) return [];
const allRules = await this._getRuleFunctionsFromBundle();
return defaults(rules, [])
.filter(ar => isFunction(allRules[ar.fnName]) && isFunction(allRules[ar.fnName].exec))
Expand All @@ -34,11 +34,11 @@ class RuleService {
async _getRuleFunctionsFromBundle() {
const orgUuid = axios.defaults.headers.common[ORGANISATION_UUID_HEADER];
let result = cache[orgUuid];
if(result) {
console.log("RuleService", "Cache hit successful");
if (result) {
console.debug("RuleService", "Cache hit successful");
return result;
} else {
console.log("RuleService", "Cache hit unsuccessful");
console.debug("RuleService", "Cache hit unsuccessful");
let bundleCode = await api.getLegacyRulesBundle();
let ruleServiceLibraryInterfaceForSharingModules = {
log: console.log,
Expand All @@ -62,4 +62,4 @@ class RuleService {
}

let ruleService = new RuleService();
export default ruleService;
export default ruleService;

0 comments on commit fa395cf

Please sign in to comment.