Skip to content

Commit

Permalink
Make the logging process output two files - one with the full log, an…
Browse files Browse the repository at this point in the history
…other with just the most important events (notably, NOT including saccades)
  • Loading branch information
adelizkeith committed Mar 21, 2023
1 parent 83539c3 commit 3c82188
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var skimForwardCharacterSpaces = 8; // This default gets changed to a calibrated
var endTime = 0;

var dataLoggingArray = [];
var dataLoggingArrayCondensed = [];

export default class App extends Component {

Expand Down Expand Up @@ -618,7 +619,7 @@ export default class App extends Component {

setPage(page) {
this.setState({page: page});
logData("Moving to page: " + page, "PAGE");
logData("Moving to page: " + page, "PAGE", true);
}

createTutorialIntro() {
Expand Down Expand Up @@ -1931,29 +1932,35 @@ export function logSusResponses(condition) {
logData(condition + " condition, usability survey question 14 user answered: " + answerFourteen, "QUESTION", true);
}

export function logData(data, dataType = "GENERIC", consolePrint = false) {
export function logData(data, dataType = "GENERIC", includeInCondensedLog = false) {
//format:
//1519211809934 FIXATION: my message here

const timestamp = Date.now();
const logLine = timestamp + " " + dataType + ": " + data;
dataLoggingArray.push(logLine);

if (consolePrint) {
if (includeInCondensedLog) {
dataLoggingArrayCondensed.push(logLine);
console.log(data);
}
}

export function writeLogFile() {
writeSingleArrayToFile(dataLoggingArray, "logfile");
writeSingleArrayToFile(dataLoggingArrayCondensed, "logfile_condensed");
}

export function writeSingleArrayToFile(array, name) {
// copy/pasted from first result on stackoverflow
const fs = require("fs");

const fileName = "./log_files/logfile_" + Date.now() + ".txt"
const fileName = "./log_files/"+ name + "_" + Date.now() + ".txt"
const writeStream = fs.createWriteStream(fileName);
const pathName = writeStream.path;

// write each value of the array on the file breaking line
dataLoggingArray.forEach(value => writeStream.write(`${value}\n`));
array.forEach(value => writeStream.write(`${value}\n`));

// the finish event is emitted when all data has been flushed from the stream
writeStream.on('finish', () => {
Expand Down

0 comments on commit 3c82188

Please sign in to comment.