Skip to content

Commit

Permalink
[FEATURE][SOLUI-195] Added support for new format of Logs in Alumio
Browse files Browse the repository at this point in the history
  • Loading branch information
florisschreuder committed Mar 1, 2022
1 parent ee5ba61 commit f5cfa49
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
39 changes: 38 additions & 1 deletion Block/Adminhtml/TaskLog/View/ExportLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,47 @@ public function getLogs()
$exportLogArray = [];
try {
foreach($this->getExportInfo() as $exportLog) {
// Set Request Info
if (isset($exportLog['_source']['@fields']['ctxt_alumio-http']['request']['headers'])) {
foreach ($exportLog['_source']['@fields']['ctxt_alumio-http']['request']['headers'] as $key => $header) {
$key = htmlspecialchars($key, ENT_QUOTES);
$header = htmlspecialchars($header, ENT_QUOTES);
$requestHeaders .= "<strong>{$key}:</strong> {$header}<br/>";
}
} else {
$requestHeaders = null;
}
$requestBody = $exportLog['_source']['@fields']['ctxt_alumio-http']['request']['requestBody'] ?? null;
$requestMethod = $exportLog['_source']['@fields']['ctxt_alumio-http']['request']['requestMethod'] ?? null;
$requestUri = $exportLog['_source']['@fields']['ctxt_alumio-http']['request']['uri'] ?? null;

// Set Response info
if (isset($exportLog['_source']['@fields']['ctxt_alumio-http']['response']['headers'])) {
foreach ($exportLog['_source']['@fields']['ctxt_alumio-http']['response']['headers'] as $key => $header) {
$key = htmlspecialchars($key, ENT_QUOTES);
$header = htmlspecialchars($header, ENT_QUOTES);
$responseHeaders .= "<strong>{$key}:</strong> {$header}<br/>";
}
} else {
$responseHeaders = null;
}
$responseBody = $exportLog['_source']['@fields']['ctxt_alumio-http']['response']['responseBody'] ?? null;
$responseStatusCode = $exportLog['_source']['@fields']['ctxt_alumio-http']['response']['statusCode'] ?? null;
$responseReasonPhrase = $exportLog['_source']['@fields']['ctxt_alumio-http']['response']['reasonPhrase'] ?? null;

// Set everything else
$exportLogArray[] = [
'message' => $exportLog['_source']['@message'],
'status' => $exportLog['_source']['@fields']['level'],
'timestamp' => $exportLog['_source']['@timestamp']
'timestamp' => $exportLog['_source']['@timestamp'],
'requestHeaders' => $requestHeaders,
'requestBody' => $requestBody,
'requestMethod' => $requestMethod,
'requestUri' => $requestUri,
'responseHeaders' => $responseHeaders,
'responseBody' => $responseBody,
'responseStatusCode' => $responseStatusCode,
'responseReasonPhrase' => $responseReasonPhrase
];
}
} catch (\Exception $e) {
Expand Down
39 changes: 38 additions & 1 deletion Block/Adminhtml/TaskLog/View/ImportLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,47 @@ public function getLogs()
$importLogArray = [];
try {
foreach ($this->getImportInfo() as $importLog) {
// Set Request Info
if (isset($exportLog['_source']['@fields']['ctxt_alumio-http']['request']['headers'])) {
foreach ($exportLog['_source']['@fields']['ctxt_alumio-http']['request']['headers'] as $key => $header) {
$key = htmlspecialchars($key, ENT_QUOTES);
$header = htmlspecialchars($header, ENT_QUOTES);
$requestHeaders .= "<strong>{$key}:</strong> {$header}<br/>";
}
} else {
$requestHeaders = null;
}
$requestBody = $exportLog['_source']['@fields']['ctxt_alumio-http']['request']['requestBody'] ?? null;
$requestMethod = $exportLog['_source']['@fields']['ctxt_alumio-http']['request']['requestMethod'] ?? null;
$requestUri = $exportLog['_source']['@fields']['ctxt_alumio-http']['request']['uri'] ?? null;

// Set Response info
if (isset($exportLog['_source']['@fields']['ctxt_alumio-http']['response']['headers'])) {
foreach ($exportLog['_source']['@fields']['ctxt_alumio-http']['response']['headers'] as $key => $header) {
$key = htmlspecialchars($key, ENT_QUOTES);
$header = htmlspecialchars($header, ENT_QUOTES);
$responseHeaders .= "<strong>{$key}:</strong> {$header}<br/>";
}
} else {
$responseHeaders = null;
}
$responseBody = $exportLog['_source']['@fields']['ctxt_alumio-http']['response']['responseBody'] ?? null;
$responseStatusCode = $exportLog['_source']['@fields']['ctxt_alumio-http']['response']['statusCode'] ?? null;
$responseReasonPhrase = $exportLog['_source']['@fields']['ctxt_alumio-http']['response']['reasonPhrase'] ?? null;

// Set everything else
$importLogArray[] = [
'message' => $importLog['_source']['@message'],
'status' => $importLog['_source']['@fields']['level'],
'timestamp' => $importLog['_source']['@timestamp']
'timestamp' => $importLog['_source']['@timestamp'],
'requestHeaders' => $requestHeaders,
'requestBody' => $requestBody,
'requestMethod' => $requestMethod,
'requestUri' => $requestUri,
'responseHeaders' => $responseHeaders,
'responseBody' => $responseBody,
'responseStatusCode' => $responseStatusCode,
'responseReasonPhrase' => $responseReasonPhrase
];
}
} catch (\Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "experius/module-alumiolog",
"description": "Shows Alumio logs in Magento 2 backend",
"version": "1.1.2",
"version": "1.2.0",
"type": "magento2-module",
"license": "GPL-3.0",
"authors": [
Expand Down
23 changes: 23 additions & 0 deletions view/adminhtml/templates/sub-logs.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,30 @@

<div id="modal-<?= $counter ?>-<?= $type ?>">
<div class="modal-<?= $counter ?>-<?= $type ?>-body-content">
<h3>Message:</h3>
<p><?php echo nl2br($log['message']) ?></p>
<br />

<?php if($log['requestBody']) : ?>
<h3>Request Info:</h3>
<p><strong>Request Headers:</strong></p>
<p style="margin-left: 40px;"><?php echo nl2br($log['requestHeaders']) ?></p>
<p><strong>Request Method:</strong> <?php echo nl2br($log['requestMethod']) ?></p>
<p><strong>Request Uri:</strong> <?php echo nl2br($log['requestUri']) ?></p>
<p><strong>Request Body:</strong></p>
<p style="margin-left: 40px"><?php echo htmlspecialchars($log['requestBody'], ENT_QUOTES) ?></p>
<br />
<?php endif; ?>

<?php if($log['responseBody']) : ?>
<h3>Response Info:</h3>
<p><strong>Response Headers:</strong></p>
<p style="margin-left: 40px;"><?php echo nl2br($log['responseHeaders']) ?></p>
<p><strong>Response Answer:</strong> <?php echo nl2br($log['responseReasonPhrase']) ?></p>
<p><strong>Response Status Code:</strong> <?php echo nl2br($log['responseStatusCode']) ?></p>
<p><strong>Response Body:</strong></p>
<p style="margin-left: 40px"><?php echo htmlspecialchars($log['responseBody'], ENT_QUOTES) ?></p>
<?php endif; ?>
</div>
</div>

Expand Down

0 comments on commit f5cfa49

Please sign in to comment.