From 22bf8365f1b833ebe6a5ee9f0ec2febf8172ed59 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 14 Jul 2022 23:07:50 +0200 Subject: [PATCH] add line count --- api.php | 22 ++++++++++++++++++++-- classen/docker.php | 4 ++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/api.php b/api.php index 17cf94b..ab1ca93 100644 --- a/api.php +++ b/api.php @@ -69,13 +69,31 @@ if(strtoupper($_REQUEST['METODE']) == "LOG") { - $logOutput = $dockerClient->getContainerLogs($currentContainer['Id']); + $lines = 350; + if(isset($_REQUEST['LINES'])) + { + if(trim($_REQUEST['LINES']) != "") + { + $lines = intval($_REQUEST['LINES']); + } + } + + $logOutput = $dockerClient->getContainerLogs($currentContainer['Id'], $lines); echo clean($logOutput); } if(strtoupper($_REQUEST['METODE']) == "HTMLLOG") { - $logOutput = $dockerClient->getContainerLogs($currentContainer['Id']); + $lines = 350; + if(isset($_REQUEST['LINES'])) + { + if(trim($_REQUEST['LINES']) != "") + { + $lines = intval($_REQUEST['LINES']); + } + } + + $logOutput = $dockerClient->getContainerLogs($currentContainer['Id'], $lines); echo html_entity_decode(clean($logOutput))."\n"; } diff --git a/classen/docker.php b/classen/docker.php index edb65ce..4fc570b 100644 --- a/classen/docker.php +++ b/classen/docker.php @@ -18,9 +18,9 @@ return json_decode($jsonRAWData, TRUE); } - public function getContainerLogs($container){ + public function getContainerLogs($container, $lines = 350){ curl_setopt($this->CurlClient, CURLOPT_POST, FALSE); - curl_setopt($this->CurlClient, CURLOPT_URL, "http:/v1.24/containers/".$container."/logs?stdout=1&tail=350"); + curl_setopt($this->CurlClient, CURLOPT_URL, "http:/v1.24/containers/".$container."/logs?stdout=1&tail=".$lines); $rawOutput = curl_exec($this->CurlClient); return $rawOutput;