Skip to content

Commit fd17ead

Browse files
authored
Merge pull request #242 from lesstif/pr/239
fixed Pr/239
2 parents 1aa205d + e706cbd commit fd17ead

File tree

7 files changed

+57
-7
lines changed

7 files changed

+57
-7
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
JIRA_HOST="https://your-jira.host.com"
22
JIRA_USER="jira-username"
33
JIRA_PASS="jira-password"
4+
JIRA_LOG_ENABLED=true
45
JIRA_LOG_FILE="jira-rest-client.log"
56
JIRA_LOG_LEVEL="WARNING"

src/Configuration/AbstractConfiguration.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ abstract class AbstractConfiguration implements ConfigurationInterface
2828
*/
2929
protected $jiraPassword;
3030

31+
/**
32+
* Enabled write to log.
33+
*
34+
* @var bool
35+
*/
36+
protected $jiraLogEnabled;
37+
3138
/**
3239
* Path to log file.
3340
*
@@ -143,6 +150,14 @@ public function getJiraPassword()
143150
return $this->jiraPassword;
144151
}
145152

153+
/**
154+
* @return bool
155+
*/
156+
public function getJiraLogEnabled()
157+
{
158+
return $this->jiraLogEnabled;
159+
}
160+
146161
/**
147162
* @return string
148163
*/

src/Configuration/ArrayConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ArrayConfiguration extends AbstractConfiguration
1818
*/
1919
public function __construct(array $configuration)
2020
{
21+
$this->jiraLogEnabled = true;
2122
$this->jiraLogFile = 'jira-rest-client.log';
2223
$this->jiraLogLevel = 'WARNING';
2324
$this->curlOptSslVerifyHost = false;

src/Configuration/ConfigurationInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public function getJiraUser();
3434
*/
3535
public function getJiraPassword();
3636

37+
/**
38+
* Enabled write to log.
39+
*
40+
* @return bool
41+
*/
42+
public function getJiraLogEnabled();
43+
3744
/**
3845
* Path to log file.
3946
*

src/Configuration/DotEnvConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function __construct($path = '.')
2424
$this->oauthAccessToken = $this->env('OAUTH_ACCESS_TOKEN');
2525
$this->cookieAuthEnabled = $this->env('COOKIE_AUTH_ENABLED', false);
2626
$this->cookieFile = $this->env('COOKIE_FILE', 'jira-cookie.txt');
27+
$this->jiraLogEnabled = $this->env('JIRA_LOG_ENABLED', true);
2728
$this->jiraLogFile = $this->env('JIRA_LOG_FILE', 'jira-rest-client.log');
2829
$this->jiraLogLevel = $this->env('JIRA_LOG_LEVEL', 'WARNING');
2930
$this->curlOptSslVerifyHost = $this->env('CURLOPT_SSL_VERIFYHOST', false);

src/JiraClient.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class JiraClient
5959
* Constructor.
6060
*
6161
* @param ConfigurationInterface $configuration
62-
* @param Logger $logger
62+
* @param LoggerInterface $logger
6363
* @param string $path
6464
*
6565
* @throws JiraException
@@ -86,14 +86,19 @@ public function __construct(ConfigurationInterface $configuration = null, Logger
8686
$this->json_mapper->classMap['\\'.\DateTimeInterface::class] = \DateTime::class;
8787

8888
// create logger
89-
if ($logger) {
90-
$this->log = $logger;
89+
if ($this->configuration->getJiraLogEnabled()) {
90+
if ($logger) {
91+
$this->log = $logger;
92+
} else {
93+
$this->log = new Logger('JiraClient');
94+
$this->log->pushHandler(new StreamHandler(
95+
$this->configuration->getJiraLogFile(),
96+
$this->convertLogLevel($this->configuration->getJiraLogLevel())
97+
));
98+
}
9199
} else {
92100
$this->log = new Logger('JiraClient');
93-
$this->log->pushHandler(new StreamHandler(
94-
$this->configuration->getJiraLogFile(),
95-
$this->convertLogLevel($this->configuration->getJiraLogLevel())
96-
));
101+
$this->log->pushHandler(new NoOperationMonologHandler());
97102
}
98103

99104
$this->http_response = 200;

src/NoOperationMonologHandler.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace JiraRestApi;
4+
5+
use Monolog\Handler\AbstractProcessingHandler;
6+
7+
class NoOperationMonologHandler extends AbstractProcessingHandler
8+
{
9+
/**
10+
* Writes the record down to the log of the implementing handler.
11+
*
12+
* @param array $record
13+
*
14+
* @return void
15+
*/
16+
protected function write(array $record)
17+
{
18+
// do nothing
19+
}
20+
}

0 commit comments

Comments
 (0)