Skip to content

Commit 776436a

Browse files
Add logging to Environment model
1 parent dbdbf0a commit 776436a

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Models/Environment.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,15 @@ public function sftpConnectionInfo()
10041004
*/
10051005
public function wake(int $maxRetries = 3, int $delay = 5): array
10061006
{
1007+
$this->logger->debug(
1008+
'Waking {site} environment {env} with {maxRetries} retries and {delay} seconds delay',
1009+
[
1010+
'site' => $this->getSite()->getName(),
1011+
'env' => $this->id,
1012+
'maxRetries' => $maxRetries,
1013+
'delay' => $delay,
1014+
]
1015+
);
10071016
$domains = array_filter(
10081017
$this->getDomains()->all(),
10091018
function ($domain) {
@@ -1022,12 +1031,24 @@ function ($domain) {
10221031
$lastError = null;
10231032

10241033
while ($attempt < $maxRetries && !$success) {
1034+
$this->logger->debug(
1035+
'Attempt {attempt} to wake {site} environment {env}',
1036+
[
1037+
'attempt' => $attempt + 1,
1038+
'site' => $this->getSite()->getName(),
1039+
'env' => $this->id,
1040+
]
1041+
);
10251042
$lastError = null;
10261043
$attempt++;
10271044
try {
10281045
$response = $this->request()->request(
10291046
"https://{$domain->id}/pantheon_healthcheck"
10301047
);
1048+
$this->logger->debug(
1049+
'Response: {response}',
1050+
['response' => $response]
1051+
);
10311052
$success = ($response['status_code'] === 200);
10321053
if ($success) {
10331054
return [

src/Models/TerminusModel.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use Pantheon\Terminus\Request\RequestAwareInterface;
88
use Pantheon\Terminus\Request\RequestAwareTrait;
99
use Robo\Contract\ConfigAwareInterface;
10+
use Psr\Log\LoggerAwareInterface;
11+
use Psr\Log\LoggerAwareTrait;
12+
use Psr\Log\LoggerInterface;
1013

1114
/**
1215
* Class TerminusModel
@@ -15,10 +18,12 @@
1518
*/
1619
abstract class TerminusModel implements
1720
ConfigAwareInterface,
18-
RequestAwareInterface
21+
RequestAwareInterface,
22+
LoggerAwareInterface
1923
{
2024
use ConfigAwareTrait;
2125
use RequestAwareTrait;
26+
use LoggerAwareTrait;
2227

2328
public const PRETTY_NAME = 'terminus model';
2429

@@ -68,6 +73,16 @@ public function __construct($attributes = null, array $options = [])
6873
}
6974
}
7075

76+
/**
77+
* Returns a logger object for use
78+
*
79+
* @return LoggerInterface
80+
*/
81+
protected function log()
82+
{
83+
return $this->logger;
84+
}
85+
7186
/**
7287
* Fetches this object from Pantheon
7388
*

0 commit comments

Comments
 (0)