Skip to content

Commit dcd2cb8

Browse files
committed
log to file
1 parent 5e292aa commit dcd2cb8

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

src/main/wrapper/CxWrapper.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {CxParamType} from "./CxParamType";
33
import {CxConstants} from "./CxConstants";
44
import {ExecutionService} from "./ExecutionService";
55
import {CxCommandOutput} from "./CxCommandOutput";
6-
import { logger } from "./loggerConfig";
6+
import { getLoggerWithFilePath, logger } from "./loggerConfig";
77
import * as fs from "fs"
88
import * as os from "os";
99
import CxBFL from "../bfl/CxBFL";
@@ -13,8 +13,11 @@ type ParamTypeMap = Map<CxParamType, string>;
1313
export class CxWrapper {
1414
config: CxConfig = new CxConfig();
1515

16-
constructor(cxScanConfig: CxConfig) {
16+
constructor(cxScanConfig: CxConfig, logFilePath?: string) {
1717
let path = require("path");
18+
19+
getLoggerWithFilePath(logFilePath)
20+
1821
if (cxScanConfig.clientId && cxScanConfig.clientSecret) {
1922
logger.info("Received clientId and clientSecret");
2023
this.config.clientId = cxScanConfig.clientId;
@@ -119,7 +122,7 @@ export class CxWrapper {
119122

120123
async scanCancel(id: string): Promise<CxCommandOutput> {
121124
const commands: string[] = [CxConstants.CMD_SCAN, CxConstants.SUB_CMD_CANCEL, CxConstants.SCAN_ID, id];
122-
commands.push(...this.initializeCommands(true));
125+
commands.push(...this.initializeCommands(false));
123126
const exec = new ExecutionService();
124127
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.SCAN_TYPE);
125128
}

src/main/wrapper/loggerConfig.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
import { configure, getLogger } from 'log4js';
22

3-
// Appenders
4-
configure({
5-
appenders: {
6-
console: { type: 'stdout', layout: { type: "messagePassThrough" } },
7-
},
8-
categories: {
9-
default: { appenders: ['console'], level: "info" }
3+
export function getLoggerWithFilePath(logFilePath ?: string) {
4+
5+
if(logFilePath) {
6+
configure({
7+
appenders: {
8+
file: { type: 'fileSync', filename: logFilePath ? logFilePath : "" },
9+
console: { type: 'stdout', layout: { type: "messagePassThrough" } },
10+
},
11+
categories: {
12+
default: { appenders: ['console', 'file'], level: "info" }
13+
}
14+
});
15+
16+
} else {
17+
configure({
18+
appenders: {
19+
console: { type: 'stdout', layout: { type: "messagePassThrough" } },
20+
},
21+
categories: {
22+
default: { appenders: ['console'], level: "info" }
23+
}
24+
});
1025
}
11-
});
26+
}
1227

13-
// Fetch logger and export
1428
export const logger = getLogger();

src/tests/ScanTest.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,19 @@ describe("ScanCreate cases",() => {
7272
console.log(" Json object from successful no wait mode case: " + JSON.stringify(scanShowObject));
7373
expect(scanShowObject.payload.pop().status).toEqual("Running");
7474
})
75+
76+
it('ScanCancel Successful case', async () => {
77+
const params = new Map();
78+
params.set(CxParamType.PROJECT_NAME, "ast-cli-javascript-integration-cancel");
79+
params.set(CxParamType.S, "./src");
80+
params.set(CxParamType.BRANCH, "master");
81+
params.set(CxParamType.FILTER, "*.ts,!**/node_modules/**/*");
82+
params.set(CxParamType.ADDITIONAL_PARAMETERS, "--async");
83+
const auth = new CxWrapper(cxScanConfig);
84+
const cxCommandOutput: CxCommandOutput = await auth.scanCreate(params);
85+
const scanObject = cxCommandOutput.payload.pop();
86+
await auth.scanCancel(scanObject.id)
87+
const scanShowObject = await auth.scanShow(scanObject.id);
88+
expect(scanShowObject.exitCode).toEqual(0);
89+
})
7590
});

0 commit comments

Comments
 (0)