Skip to content

Commit

Permalink
Log tool output to a single file in $workdir
Browse files Browse the repository at this point in the history
For each tool run, log information about the run into a single file
in $workdir. This simplifies debugging and troubleshooting.
  • Loading branch information
cpeel committed Dec 12, 2020
1 parent 4e54cc4 commit 1495464
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
8 changes: 8 additions & 0 deletions base.inc
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ function log_tool_access($tool, $upid)
file_put_contents("$base_workdir/access.log", $s, FILE_APPEND);
}

function log_tool_action($workdir, $label, $message)
{
file_put_contents("$workdir/messages.log", "$label: $message\n", FILE_APPEND);
}

class UploadError extends Exception {}

function process_file_upload($formid, $workdir, $allowed_extensions=[])
Expand Down Expand Up @@ -261,6 +266,8 @@ function process_file_upload($formid, $workdir, $allowed_extensions=[])
throw $e;
}

log_tool_action($workdir, "uploaded file", $final_filepath);

return $final_filepath;
}

Expand All @@ -277,6 +284,7 @@ function ensure_utf8_file($filename) {
);
exec(escapeshellcmd($cmd), $ppf_output, $ppf_exitcode);
rename($tmpfname, $filename);
log_tool_action(dirname($filename), "UTF-8 conversion", "$filename converted from ISO-8859-1");
return true;
}
return false;
Expand Down
11 changes: 6 additions & 5 deletions ppcomp-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@
"2>&1"
]);

// echo $command;
file_put_contents("$workdir/command.txt", $command);
log_tool_action($workdir, "command", $command);

$output = shell_exec($command);

log_tool_action($workdir, "output", $output);

// ----- display results -------------------------------------------

output_header("ppcomp Results");
Expand All @@ -81,11 +82,11 @@
$reportok = true;
}
if ($reportok) {
echo "Left click to view. Right click to download.</p>";
echo "Left click to view. Right click to download.";
} else {
echo "<p>Whoops! Something went wrong and no output was generated.
The error message was<br/><br/>
<tt>${output}</tt></p>
</p>For more assistance, ask in the <a href='$help_url'>discussion topic</a> and include this identifier: ${upid}</p>";
<p>For more assistance, ask in the <a href='$help_url'>discussion topic</a> and include this identifier: ${upid}</p>";
}

echo "</p>";
11 changes: 6 additions & 5 deletions pphtml-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@
"2>&1"
]);

// echo $command;
file_put_contents("$workdir/command.txt", $command);
log_tool_action($workdir, "command", $command);

// and finally, run pphtml
$output = shell_exec($command);

log_tool_action($workdir, "output", $output);

// ----- display results -------------------------------------------

output_header("pphtml Results");
Expand All @@ -82,11 +83,11 @@
$reportok = true;
}
if ($reportok) {
echo "Left click to view. Right click to download.</p>";
echo "Left click to view. Right click to download.";
} else {
echo "<p>Whoops! Something went wrong and no output was generated.
The error message was<br/><br/>
<tt>${output}</tt></p>
</p>For more assistance, ask in the <a href='$help_url'>discussion topic</a> and include this identifier: ${upid}</p>";
<p>For more assistance, ask in the <a href='$help_url'>discussion topic</a> and include this identifier: ${upid}</p>";
}

echo "</p>";
10 changes: 6 additions & 4 deletions ppsmq-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
"2>&1"
]);

// echo $command;
log_tool_action($workdir, "command", $command);

// and finally, run ppsmq
$output = shell_exec($command);

log_tool_action($workdir, "output", $output);

// ----- display results -------------------------------------------

output_header("ppsmq Results");
Expand All @@ -44,11 +46,11 @@
$reportok = true;
}
if ($reportok) {
echo "Left click to view. Right click to download.</p>";
echo "Left click to view. Right click to download.";
} else {
echo "<p>Whoops! Something went wrong and no output was generated.
The error message was<br/><br/>
<tt>${output}</tt></p>
</p>For more assistance, ask in the <a href='$help_url'>discussion topic</a> and include this identifier: ${upid}</p>";
<p>For more assistance, ask in the <a href='$help_url'>discussion topic</a> and include this identifier: ${upid}</p>";
}

echo "</p>";
19 changes: 9 additions & 10 deletions pptext-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
// ----- user has option of uploading a Latin-1 file -------------------

// main file
if(ensure_utf8_file($target_name)) {
file_put_contents("$workdir/converted-main.txt", "text file converted from ISO-8859\n");
}
ensure_utf8_file($target_name);

// good words file
if ($gtarget_name && ensure_utf8_file($gtarget_name)) {
file_put_contents("$workdir/converted-gwf.txt", "good words file converted from ISO-8859\n");
if ($gtarget_name) {
ensure_utf8_file($gtarget_name);
}

// ----- process user options ------------------------------------------
Expand Down Expand Up @@ -104,12 +102,13 @@
"2>&1"
]);

// echo $command;
file_put_contents("$workdir/command.txt", $command);
log_tool_action($workdir, "command", $command);

// and finally, run pptext
$output = shell_exec($command);

log_tool_action($workdir, "output", $output);

// ----- display results -------------------------------------------

output_header("pptext Results");
Expand All @@ -126,11 +125,11 @@
$reportok = true;
}
if ($reportok) {
echo "Left click to view. Right click to download.</p>";
echo "Left click to view. Right click to download.";
} else {
echo "<p>Whoops! Something went wrong and no output was generated.
The error message was<br/><br/>
<tt>${output}</tt></p>
</p>For more assistance, ask in the <a href='$help_url'>discussion topic</a> and include this identifier: ${upid}</p>";
<p>For more assistance, ask in the <a href='$help_url'>discussion topic</a> and include this identifier: ${upid}</p>";
}

echo "</p>";

0 comments on commit 1495464

Please sign in to comment.