Skip to content

Commit

Permalink
feat: Use api logger appender instead of ApiLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Mar 30, 2023
1 parent 161362e commit 84f3621
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 65 deletions.
5 changes: 3 additions & 2 deletions api/dicom-web/controller/QIDO-RS/queryAllInstances.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ class QueryAllInstancesController extends Controller {
async mainProcess() {
let apiLogger = new ApiLogger(this.request, "QIDO-RS");

apiLogger.info("[Query all instances]");
apiLogger.addTokenValue();
apiLogger.logger.info("Query all instances");

try {
let qidoRsService = new QidoRsService(this.request, this.response, "instance");

await qidoRsService.getAndResponseDicomJson();
} catch (e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
apiLogger.error(errorStr);
apiLogger.logger.error(errorStr);

this.response.writeHead(500, {
"Content-Type": "application/dicom+json"
Expand Down
5 changes: 3 additions & 2 deletions api/dicom-web/controller/QIDO-RS/queryAllSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class QueryAllSeriesController extends Controller {
async mainProcess() {
let apiLogger = new ApiLogger(this.request, "QIDO-RS");

apiLogger.info("[Query all series]");
apiLogger.addTokenValue();
apiLogger.logger.info("Query all series");

try {

Expand All @@ -22,7 +23,7 @@ class QueryAllSeriesController extends Controller {

} catch (e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
apiLogger.error(errorStr);
apiLogger.logger.error(errorStr);

this.response.writeHead(500, {
"Content-Type": "application/dicom+json"
Expand Down
5 changes: 3 additions & 2 deletions api/dicom-web/controller/QIDO-RS/queryAllStudies.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class QueryAllStudiesController extends Controller {
async mainProcess() {
let apiLogger = new ApiLogger(this.request, "QIDO-RS");

apiLogger.info(`[Query All Studies]`);
apiLogger.addTokenValue();
apiLogger.logger.info(`Query All Studies`);

try {

Expand All @@ -22,7 +23,7 @@ class QueryAllStudiesController extends Controller {

} catch (e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
apiLogger.error(errorStr);
apiLogger.logger.error(errorStr);

this.response.writeHead(500, {
"Content-Type": "application/dicom+json"
Expand Down
5 changes: 3 additions & 2 deletions api/dicom-web/controller/QIDO-RS/queryStudies-Instances.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class QueryInstancesOfStudiesController extends Controller {
async mainProcess() {
let apiLogger = new ApiLogger(this.request, "QIDO-RS");

apiLogger.info(`[Query instances in study, Study UID: ${this.request.params.studyUID}]`);
apiLogger.addTokenValue();
apiLogger.logger.info(`Query instances in study, Study UID: ${this.request.params.studyUID}`);

try {

Expand All @@ -21,7 +22,7 @@ class QueryInstancesOfStudiesController extends Controller {
await qidoRsService.getAndResponseDicomJson();
} catch (e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
apiLogger.error(errorStr);
apiLogger.logger.error(errorStr);

this.response.writeHead(500, {
"Content-Type": "application/dicom+json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class QueryInstancesOfSeriesOfStudiesController extends Controller {
async mainProcess() {
let apiLogger = new ApiLogger(this.request, "QIDO-RS");

apiLogger.info(`[Query instance Level, Study UID: ${this.request.params.studyUID}, Series UID: ${this.request.params.seriesUID}]`);
apiLogger.addTokenValue();
apiLogger.logger.info(`Query instance Level, Study UID: ${this.request.params.studyUID}, Series UID: ${this.request.params.seriesUID}`);

try {

Expand All @@ -23,7 +24,7 @@ class QueryInstancesOfSeriesOfStudiesController extends Controller {

} catch (e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
apiLogger.error(errorStr);
apiLogger.logger.error(errorStr);

this.response.writeHead(500, {
"Content-Type": "application/dicom+json"
Expand Down
5 changes: 3 additions & 2 deletions api/dicom-web/controller/QIDO-RS/queryStudies-Series.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class QuerySeriesOfStudiesController extends Controller {
async mainProcess() {
let apiLogger = new ApiLogger(this.request, "QIDO-RS");

apiLogger.info(`[Query series Level, Study UID: ${this.request.params.studyUID}]`);
apiLogger.addTokenValue();
apiLogger.logger.info(`Query series Level, Study UID: ${this.request.params.studyUID}`);

try {

Expand All @@ -22,7 +23,7 @@ class QuerySeriesOfStudiesController extends Controller {

} catch (e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
apiLogger.error(errorStr);
apiLogger.logger.error(errorStr);

this.response.writeHead(500, {
"Content-Type": "application/dicom+json"
Expand Down
5 changes: 3 additions & 2 deletions api/dicom-web/controller/STOW-RS/storeInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class StoreInstanceController extends Controller {
let retCode;
let storeMessage;
let apiLogger = new ApiLogger(this.request, "STOW-RS");
apiLogger.addTokenValue();

try {
let requestMultipartParser = new StowRsRequestMultipartParser(this.request);
Expand All @@ -31,7 +32,7 @@ class StoreInstanceController extends Controller {
}
let endSTOWTime = performance.now();
let elapsedTime = (endSTOWTime - startSTOWTime).toFixed(3);
apiLogger.info(`[Finished STOW-RS, elapsed time: ${elapsedTime} ms]`);
apiLogger.logger.info(`Finished STOW-RS, elapsed time: ${elapsedTime} ms`);

this.response.writeHead(retCode, {
"Content-Type": "application/dicom"
Expand All @@ -40,7 +41,7 @@ class StoreInstanceController extends Controller {
return this.response.end(JSON.stringify(storeMessage));
} catch (e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
apiLogger.error(errorStr);
apiLogger.logger.error(errorStr);

let errorMessage =
errorResponseMessage.getInternalServerErrorMessage(errorStr);
Expand Down
11 changes: 6 additions & 5 deletions api/dicom-web/controller/WADO-RS/rendered/instanceFrames.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class RetrieveRenderedInstanceFramesController extends Controller {

async mainProcess() {
let apiLogger = new ApiLogger(this.request, "WADO-RS");
apiLogger.addTokenValue();

let {
studyUID,
Expand All @@ -20,7 +21,7 @@ class RetrieveRenderedInstanceFramesController extends Controller {
frameNumber
} = this.request.params;

apiLogger.info(`[Get study's series' rendered instances' frames, study UID: ${studyUID}, series UID: ${seriesUID}, instance UID: ${instanceUID}, frame: ${frameNumber}]`);
apiLogger.logger.info(`Get study's series' rendered instances' frames, study UID: ${studyUID}, series UID: ${seriesUID}, instance UID: ${instanceUID}, frame: ${frameNumber}`);

let headerAccept = _.get(this.request.headers, "accept", "");
if (!headerAccept.includes("*/*") && !headerAccept.includes("image/jpeg")) {
Expand All @@ -47,7 +48,7 @@ class RetrieveRenderedInstanceFramesController extends Controller {

let notFoundMessageStr = JSON.stringify(notFoundMessage);

apiLogger.warning(`[${notFoundMessageStr}]`);
apiLogger.logger.warn(`[${notFoundMessageStr}]`);

return this.response.end(notFoundMessageStr);
}
Expand All @@ -64,7 +65,7 @@ class RetrieveRenderedInstanceFramesController extends Controller {

let badRequestMessageStr = JSON.stringify(badRequestMessage);

apiLogger.warning(badRequestMessageStr);
apiLogger.logger.warn(badRequestMessageStr);

return this.response.end(JSON.stringify(badRequestMessageStr));
}
Expand All @@ -77,7 +78,7 @@ class RetrieveRenderedInstanceFramesController extends Controller {
this.response.writeHead(200, {
"Content-Type": "image/jpeg"
});
apiLogger.info(`[Get instance's frame successfully, instance UID: ${instanceUID}, frame number: ${frameNumber[0]}]`);
apiLogger.logger.info(`Get instance's frame successfully, instance UID: ${instanceUID}, frame number: ${frameNumber[0]}`);
return this.response.end(postProcessResult.magick.toBuffer(), "binary");
}
throw new Error(`Can not process this image, instanceUID: ${instanceFramesObj.instanceUID}, frameNumber: ${this.request.frameNumber[0]}`);
Expand All @@ -86,7 +87,7 @@ class RetrieveRenderedInstanceFramesController extends Controller {
await renderedService.writeSpecificFramesRenderedImages(this.request, frameNumber, instanceFramesObj, multipartWriter);
multipartWriter.writeFinalBoundary();

apiLogger.info(`[Get instance's frame successfully, instance UID: ${instanceUID}, frame numbers: ${frameNumber}]`);
apiLogger.logger.info(`Get instance's frame successfully, instance UID: ${instanceUID}, frame numbers: ${frameNumber}`);

return this.response.end();
}
Expand Down
6 changes: 4 additions & 2 deletions api/dicom-web/controller/WADO-RS/rendered/instances.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ class RetrieveRenderedInstancesController extends Controller {

async mainProcess() {
let apiLogger = new ApiLogger(this.request, "WADO-RS");
apiLogger.addTokenValue();

let headerAccept = _.get(this.request.headers, "accept", "");

apiLogger.info(`[Get study's series' rendered instances, study UID: ${this.request.params.studyUID}, series UID: ${this.request.params.seriesUID}]`);
apiLogger.logger.info(`Get study's series' rendered instances, study UID: ${this.request.params.studyUID}, series UID: ${this.request.params.seriesUID}`);

if (!headerAccept == `multipart/related; type="image/jpeg"`) {
let badRequestMessage = errorResponse.getBadRequestErrorMessage(`header accept only allow \`multipart/related; type="image/jpeg"\`, exception : ${headerAccept}`);
Expand All @@ -37,7 +39,7 @@ class RetrieveRenderedInstancesController extends Controller {
multipartWriter.writeFinalBoundary();
}

apiLogger.info(`[Write Multipart Successfully, study's series' instances' rendered images, study UID: ${this.request.params.studyUID}, series UID: ${this.request.params.seriesUID}, instance UID: ${this.request.params.instanceUID}]`);
apiLogger.logger.info(`Write Multipart Successfully, study's series' instances' rendered images, study UID: ${this.request.params.studyUID}, series UID: ${this.request.params.seriesUID}, instance UID: ${this.request.params.instanceUID}`);
return this.response.end();
} catch(e) {
this.response.writeHead(500, {
Expand Down
7 changes: 4 additions & 3 deletions api/dicom-web/controller/WADO-RS/rendered/study.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class RetrieveRenderedStudyController extends Controller {
async mainProcess() {
let headerAccept = _.get(this.request.headers, "accept", "");
let apiLogger = new ApiLogger(this.request, "WADO-RS");
apiLogger.addTokenValue();

apiLogger.info(`[Get study's rendered instances, study UID: ${this.request.params.studyUID}]`);
apiLogger.logger.info(`Get study's rendered instances, study UID: ${this.request.params.studyUID}`);

if (!headerAccept == `multipart/related; type="image/jpeg"`) {
let badRequestMessage = errorResponse.getBadRequestErrorMessage(`header accept only allow \`multipart/related; type="image/jpeg"\`, exception : ${headerAccept}`);
Expand Down Expand Up @@ -44,11 +45,11 @@ class RetrieveRenderedStudyController extends Controller {
});
}

apiLogger.info(`[Write Multipart Successfully, study's rendered instances, study UID: ${this.request.params.studyUID}]`);
apiLogger.logger.info(`Write Multipart Successfully, study's rendered instances, study UID: ${this.request.params.studyUID}`);

return this.response.end();
} catch(e) {
apiLogger.error(e);
apiLogger.logger.error(e);

this.response.writeHead(500, {
"Content-Type": "application/dicom+json"
Expand Down
6 changes: 4 additions & 2 deletions api/dicom-web/controller/WADO-RS/retrieveInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ class RetrieveInstanceOfSeriesOfStudiesController extends Controller {

async mainProcess() {
let apiLogger = new ApiLogger(this.request, "WADO-RS");
apiLogger.addTokenValue();

apiLogger.info(`[Get study's series' instances, study UID: ${this.request.params.studyUID}, series UID: ${this.request.params.seriesUID}] [Request Accept: ${this.request.headers.accept}]`);
apiLogger.logger.info(`Get study's series' instances, study UID: ${this.request.params.studyUID}, series UID: ${this.request.params.seriesUID}`);
apiLogger.logger.info(`Request Accept: ${this.request.headers.accept}`);

try {

Expand All @@ -23,7 +25,7 @@ class RetrieveInstanceOfSeriesOfStudiesController extends Controller {
return wadoService.sendNotSupportedMediaType(this.response, this.request.headers.accept);
} catch(e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
apiLogger.error(errorStr);
apiLogger.logger.error(errorStr);

this.response.writeHead(500, {
"Content-Type": "application/dicom+json"
Expand Down
5 changes: 3 additions & 2 deletions api/dicom-web/controller/WADO-RS/retrieveStudyMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class RetrieveStudyMetadataController extends Controller {
async mainProcess() {

let apiLogger = new ApiLogger(this.request, "WADO-RS");
apiLogger.addTokenValue();

apiLogger.info(`[WADO-RS] [Get Study's Instances Metadata] [study UID: ${this.request.params.studyUID}]`);
apiLogger.logger.info(`Get Study's Instances Metadata [study UID: ${this.request.params.studyUID}]`);

try {
let responseMetadata = [];
Expand Down Expand Up @@ -49,7 +50,7 @@ class RetrieveStudyMetadataController extends Controller {

} catch(e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
apiLogger.error(errorStr);
apiLogger.logger.error(errorStr);

this.response.writeHead(500, {
"Content-Type": "application/dicom+json"
Expand Down
37 changes: 0 additions & 37 deletions utils/logs/api-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,6 @@ class ApiLogger {
this.logger = getLogger("api");
}

/**
*
* @param {string} message
*/
info(message="") {
let infoMessage = `${this.prefixMessage}`;
if (message) {
infoMessage += ` ${message}`;
}

raccoonLogger.info(infoMessage);
}

/**
*
* @param {string} message
*/
warning(message="") {
let warningMessage = `${this.prefixMessage}`;

if (message) {
warningMessage += ` ${message}`;
}

raccoonLogger.warn(warningMessage);
}

error(message="") {
let errorMessage = `${this.prefixMessage}`;

if (message) {
errorMessage += ` [Error: ${message}]`;
}

raccoonLogger.error(errorMessage);
}

addTokenValue() {
this.logger.addContext("apiName", this.apiName);
this.logger.addContext("originalUrl", this.request.originalUrl);
Expand Down

0 comments on commit 84f3621

Please sign in to comment.