Skip to content

Commit

Permalink
feat: add logging (#34)
Browse files Browse the repository at this point in the history
* feat: logs to file

* feat: logs to file

* fix: lint issue
  • Loading branch information
kobenguyent authored Aug 14, 2024
1 parent 7ac279c commit d3b0f47
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 186 deletions.
14 changes: 14 additions & 0 deletions helpers/logging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs');
const path = require('path');

module.exports = function logToFile(message) {
const logFilePath = path.join(output_dir, 'codeceptjs-reportportal.log');
const timestamp = new Date().toISOString();
const logMessage = `[${timestamp}] ${message}\n`;

fs.appendFile(logFilePath, logMessage, (err) => {
if (err) {
console.error('Failed to write to log file:', err);
}
});
};
36 changes: 22 additions & 14 deletions helpers/rpHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,35 @@ const { STATUSES } = require('../constants/statuses');
const fs = require('fs');
const path = require('path');
const RestClient = require('./restClient');
const logToFile = require('./logging');
const debug = require('debug')('codeceptjs:reportportal');
const restClient = new RestClient();
const { output, event } = codeceptjs;
let rpClient;

async function startLaunch(config, suiteTitle) {
rpClient = new RPClient({
apiKey: config.token,
endpoint: config.endpoint,
project: config.projectName,
debug: config.debug,
});
try {
rpClient = new RPClient({
apiKey: config.token,
endpoint: config.endpoint,
project: config.projectName,
debug: config.debug,
});

return rpClient.startLaunch({
name: config.launchName || suiteTitle,
description: config.launchDescription,
attributes: config.launchAttributes,
rerun: config.rerun,
rerunOf: config.rerunOf,
mode: LAUNCH_MODES.DEFAULT,
});
logToFile(`Creating new RP Client: ${JSON.stringify(rpClient, null, 2)}`);

const launchObj = rpClient.startLaunch({
name: config.launchName || suiteTitle,
description: config.launchDescription,
attributes: config.launchAttributes,
rerun: config.rerun,
rerunOf: config.rerunOf,
mode: LAUNCH_MODES.DEFAULT,
});
return launchObj;
} catch (e) {
logToFile(`Could not start launch due to: ${e.message}`);
}
}

async function finishLaunch(launchObj, launchStatus) {
Expand Down
Loading

0 comments on commit d3b0f47

Please sign in to comment.