Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inspect 2.6 logger additions 2 #1148

Merged
merged 4 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion api/api_sources/sources/AppConfig/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as path from 'path';
import * as assert from 'assert';
import { Logger } from '../../../api_sources/sources/server/logger';
import { Logger } from '../server/logger';
declare const process: any;
declare const __dirname: any;

Expand All @@ -22,6 +22,8 @@ class AppConfiguration {
public appName: string = process.env.PROJECT_NAME || 'lucy';
public dbs: string[] = ['templateDB'];

logger: Logger;

/**
* @description Getter for shard instance
* @return AppConfiguration
Expand All @@ -34,6 +36,7 @@ class AppConfiguration {
* @description Constructing
*/
constructor() {
this.logger = new Logger(this.constructor.name);
this.port = (process.env.PORT || 3001);
this.host = process.env.HOST || '127.0.0.1';
}
Expand Down
16 changes: 11 additions & 5 deletions api/api_sources/sources/libs/utilities/bc.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import * as assert from 'assert';
import AppConfig from '../../AppConfig';
import axios from 'axios';
const getPem = require('rsa-pem-from-mod-exp');
import { Logger } from '../../../../api_sources/sources/server/logger';
import { Logger } from '../../server/logger';

/**
* @description Require common utility module as any
Expand All @@ -35,7 +35,14 @@ const commonUtility = require('@bcgov/nodejs-common-utils');
* @export class BCHelperLib
*/
export class BCHelperLib {
logger: Logger;
static logger: Logger;

/**
* @description Constructing
*/
constructor() {
BCHelperLib.logger = new Logger(this.constructor.name);
}

/**
* @description Get certificate for JWT token validation
Expand Down Expand Up @@ -91,14 +98,13 @@ export class BCHelperLib {
});
} catch (error) {
const message = 'Unable to parse certificate(s)';
this.logger.error('algorithm exception ', algorithm);
this.logger.error('certificate exception ', certificate);
reject(new Error(message));
}
});
assert(certificate, 'No getJwtCertificate');
assert(algorithm, 'No algorithm');
this.logger.error('certificate exception ', certificate);
this.logger.error('algorithm exception ', algorithm);
return {algorithm, certificate};
}

/**
Expand Down
3 changes: 2 additions & 1 deletion api/api_sources/sources/server/core/base.route.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,10 @@ export class RouteController {
return async (req: express.Request, resp: express.Response, next: any) => {
const tag = `authHandler-(${this.apiName(req)})`;
try {
passport.authenticate('jwt', {session: false}, (err, user) => {
passport.authenticate('jwt', {session: false}, (err, user, errorAlpha) => {
this.logger.error('user exception ', user);
this.logger.error('error exception', err);
this.logger.error('errorAlpha exception', errorAlpha);
if (err) {
const msg = `Authorization fail with error ${err}`;
this.commonError(401, tag, err, resp, msg);
Expand Down