Skip to content

Commit d1fa257

Browse files
author
Dmitry Tarasov
committed
Make environment name optional
1 parent fb1da45 commit d1fa257

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/Stackify/Log/MessageBuilder.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ class MessageBuilder
2020
protected $appName;
2121
protected $environmentName;
2222

23-
public function __construct($loggerName, $appName, $environmentName)
23+
public function __construct($loggerName, $appName, $environmentName = null)
2424
{
2525
if (!function_exists('json_encode')) {
2626
throw new InitializationException('JSON extension is required for Stackify logger');
2727
}
28-
// @TODO validate $appName and $environmentName ?
2928
$this->loggerName = $loggerName;
30-
$this->appName = $appName;
29+
$this->appName = $this->validateNotEmpty('AppName', $appName);
3130
$this->environmentName = $environmentName;
3231
// set state for environment details
3332
EnvironmentDetail::getInstance()->init($appName, $environmentName);
@@ -116,4 +115,13 @@ protected function encodeJSON($data)
116115
return json_encode($data);
117116
}
118117

118+
protected function validateNotEmpty($name, $value)
119+
{
120+
$result = trim($value);
121+
if (empty($result)) {
122+
throw new InitializationException("$name cannot be empty");
123+
}
124+
return $result;
125+
}
126+
119127
}

src/Stackify/Log/Monolog/Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Handler extends AbstractHandler
1717
*/
1818
private $transport;
1919

20-
public function __construct($appName, $environmentName, TransportInterface $transport = null, $level = Logger::DEBUG, $bubble = true)
20+
public function __construct($appName, $environmentName = null, TransportInterface $transport = null, $level = Logger::DEBUG, $bubble = true)
2121
{
2222
parent::__construct($level, $bubble);
2323
$messageBuilder = new MessageBuilder('Stackify Monolog v.1.0', $appName, $environmentName);

src/Stackify/Log/Standalone/Logger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Logger extends AbstractLogger
1616
*/
1717
private $transport;
1818

19-
public function __construct($appName, $environmentName, TransportInterface $transport = null)
19+
public function __construct($appName, $environmentName = null, TransportInterface $transport = null)
2020
{
2121
$messageBuilder = new MessageBuilder('Stackify PHP Logger v.1.0', $appName, $environmentName);
2222
if (null === $transport) {

0 commit comments

Comments
 (0)