Skip to content

Commit 8d07ddc

Browse files
authored
Merge pull request #97 from mcode/add-default-log-file
Create default log file if one does not exist
2 parents 4bf88aa + 6ef2fd7 commit 8d07ddc

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ If the `notificationInfo` object is provided in configuration, an email will be
120120

121121
### Logging Successful Extractions
122122

123-
Whenever the mCODE Extraction Client successfully runs, a log is kept of the given date range of the extraction. Users will need to specify the location of the file to save this information. The default location is in a `logs` directory in a file called `run-logs.json`. Initially, this file's contents should be an empty array, `[]`. Users will need to create this file before running the mCODE Extraction Client with `from-date` and/or `to-date` for the first time.
123+
Whenever the mCODE Extraction Client successfully runs with the `--entries-filter` flag, a log is kept of the given date range of the extraction. The default location of the log is in a `logs` directory in a file called `run-logs.json`. If there is no log file at that location, the file will be created the first time the user runs the program with the `--entries-filter` flag.
124124

125-
Users can specify a different location for the file by using the `--run-log-filepath <path>` CLI option. For example:
125+
Users can specify a different location for the file by using the `--run-log-filepath <path>` CLI option. Users will need to create this file before running the mCODE Extraction Client with `--entries-filter` and a date range. Initially, this file's contents should be an empty array, `[]`. For example:
126126

127127
```bash
128-
node src/cli/cli.js --run-log-filepath path/to/file.json
128+
node src/cli/cli.js --entries-filter --from-date YYYY-MM-DD --to-date YYY-MM-DD --run-log-filepath path/to/file.json
129129
```
130130

131131
### Masking Patient Data

src/cli/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ function checkInputAndConfig(config, fromDate, toDate) {
3838
}
3939

4040
function checkLogFile(pathToLogs) {
41+
// If no custom log file was specified and no default log file exists, create one
42+
if (pathToLogs === path.join('logs', 'run-logs.json') && !fs.existsSync(pathToLogs)) {
43+
logger.info(`No log file found. Creating default log file at ${pathToLogs}`);
44+
if (!fs.existsSync('logs')) fs.mkdirSync('logs');
45+
fs.appendFileSync(pathToLogs, '[]');
46+
}
4147
// Check that the given log file exists
4248
try {
4349
const logFileContent = JSON.parse(fs.readFileSync(pathToLogs));

0 commit comments

Comments
 (0)