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

Use separate SUSHI and GoFSH logger and stats #143

Merged
merged 2 commits into from
Sep 20, 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
21 changes: 12 additions & 9 deletions src/utils/FSHHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { fhirdefs, sushiExport, sushiImport, utils } from 'fsh-sushi';
import { gofshExport, processor, utils as gofshUtils } from 'gofsh';
import { fillTank, loadAndCleanDatabase } from './Processing';
import { sliceDependency } from './helpers';
import { fshOnlineLogger as logger, setCurrentLogger } from './logger';

const FSHTank = sushiImport.FSHTank;
const RawFSH = sushiImport.RawFSH;
const exportFHIR = sushiExport.exportFHIR;
const logger = utils.logger;
const stats = utils.stats;
const sushiStats = utils.stats;
const gofshStats = gofshUtils.stats;
const getRandomPun = utils.getRandomPun;
const Type = utils.Type;
const FHIRDefinitions = fhirdefs.FHIRDefinitions;
Expand All @@ -26,7 +27,8 @@ const FHIRDefinitions = fhirdefs.FHIRDefinitions;
* @returns {string} the FSH
*/
export async function runGoFSH(input, options) {
stats.reset();
gofshStats.reset();
setCurrentLogger('gofsh');

// Read in the resources as strings
const docs = [];
Expand Down Expand Up @@ -88,7 +90,8 @@ export async function runGoFSH(input, options) {
* @returns Package with FHIR resources
*/
export async function runSUSHI(input, config, dependencies = []) {
stats.reset();
sushiStats.reset();
setCurrentLogger('sushi');

// Load dependencies
let defs = new FHIRDefinitions();
Expand Down Expand Up @@ -148,8 +151,8 @@ export async function runSUSHI(input, config, dependencies = []) {
}

function printSUSHIResults(pkg) {
const numError = stats.numError;
const numWarn = stats.numWarn;
const numError = sushiStats.numError;
const numWarn = sushiStats.numWarn;
// NOTE: These variables are creatively names to align well in the strings below while keeping prettier happy
const profileNum = pad(pkg.profiles.length.toString(), 13);
const extentNum = pad(pkg.extensions.length.toString(), 12);
Expand Down Expand Up @@ -197,9 +200,9 @@ function printGoFSHresults(pkg) {
const instNum = pad(pkg.instances.length.toString(), 18);
const invNum = pad(pkg.invariants.length.toString(), 17);
const mapNum = pad(pkg.mappings.length.toString(), 18);
const errNumMsg = pad(`${stats.numError} Error${stats.numError !== 1 ? 's' : ''}`, 12);
const wrnNumMsg = padStart(`${stats.numWarn} Warning${stats.numWarn !== 1 ? 's' : ''}`, 12);
const aWittyMessageInvolvingABadFishPun = padEnd(getRandomPun(stats.numError, stats.numWarn), 37);
const errNumMsg = pad(`${gofshStats.numError} Error${gofshStats.numError !== 1 ? 's' : ''}`, 12);
const wrnNumMsg = padStart(`${gofshStats.numWarn} Warning${gofshStats.numWarn !== 1 ? 's' : ''}`, 12);
const aWittyMessageInvolvingABadFishPun = padEnd(getRandomPun(gofshStats.numError, gofshStats.numWarn), 37);

// prettier-ignore
const results = [
Expand Down
3 changes: 1 addition & 2 deletions src/utils/Load.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import tarStream from 'tar-stream';
import zlib from 'zlib';
import https from 'https';
import { utils } from 'fsh-sushi';
const logger = utils.logger;
import { fshOnlineLogger as logger } from './logger';

export function unzipDependencies(resources, dependency, id) {
let returnPackage = { resourceArr: resources, emptyDependencies: [] };
Expand Down
6 changes: 3 additions & 3 deletions src/utils/Processing.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { fhirdefs, sushiImport, utils } from 'fsh-sushi';
import { getLatestVersionNumber, loadAsFHIRDefs, loadDependenciesInStorage, unzipDependencies } from './Load';
import { flatten } from 'lodash';
import { fhirdefs, sushiImport } from 'fsh-sushi';
import { getLatestVersionNumber, loadAsFHIRDefs, loadDependenciesInStorage, unzipDependencies } from './Load';
import { fshOnlineLogger as logger } from './logger';

const logger = utils.logger;
const FHIRDefinitions = fhirdefs.FHIRDefinitions;
const FSHTank = sushiImport.FSHTank;
const importText = sushiImport.importText;
Expand Down
14 changes: 14 additions & 0 deletions src/utils/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { utils as sushiUtils } from 'fsh-sushi';
import { utils as gofshUtils } from 'gofsh';

// Default the logger to SUSHI's logger, but support switching
// between the loggers so that any file can import one logger
// and have the stats tracked correctly
export let fshOnlineLogger = sushiUtils.logger;
export function setCurrentLogger(loggerName) {
if (loggerName === 'sushi') {
fshOnlineLogger = sushiUtils.logger;
} else if (loggerName === 'gofsh') {
fshOnlineLogger = gofshUtils.logger;
}
}
Loading