Skip to content

Commit

Permalink
Save log file immediately after getting the api response
Browse files Browse the repository at this point in the history
  • Loading branch information
lcampos committed Jul 23, 2020
1 parent 039f1f4 commit aefc0ac
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
7 changes: 2 additions & 5 deletions packages/apex-node/src/logs/logService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ApexLogGetOptions } from '../types';
import { QueryResult } from '../types/common';
import { nls } from '../i18n';
import * as path from 'path';
import { createFiles } from '../utils';
import { createFile } from '../utils';

const MAX_NUM_LOGS = 25;

Expand All @@ -29,19 +29,16 @@ export class LogService {
logIdList.push(options.logId);
}

const saveLogsMap = new Map();

const connectionRequests = logIdList.map(async id => {
const url = `${this.connection.tooling._baseUrl()}/sobjects/ApexLog/${id}/Body`;
const logRecord = await this.toolingRequest(url);
if (options.outputDir) {
saveLogsMap.set(path.join(options.outputDir, `${id}.log`), logRecord);
createFile(path.join(options.outputDir, `${id}.log`), logRecord);
}
return logRecord;
});

const result = await Promise.all(connectionRequests);
createFiles(saveLogsMap);

return result;
}
Expand Down
12 changes: 5 additions & 7 deletions packages/apex-node/src/utils/fileSystemHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ export function ensureFileExists(filePath: string): void {
}

/**
* Method to save multiple files on disk.
* Method to save a file on disk.
*
* @param fileMap key = filePath, value = file contents
* @param filePath path where to
* @param fileContent file contents
*/
export function createFiles(fileMap: Map<string, string>): void {
for (const filePath of fileMap.keys()) {
export function createFile(filePath: string, fileContent: string): void {
ensureFileExists(filePath);

const writeStream = fs.createWriteStream(filePath);
writeStream.write(fileMap.get(filePath));
writeStream.end();
}
writeStream.write(fileContent);
}
2 changes: 1 addition & 1 deletion packages/apex-node/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

export { createFiles } from './fileSystemHandler';
export { createFile } from './fileSystemHandler';

0 comments on commit aefc0ac

Please sign in to comment.