Skip to content

Commit 73b4e67

Browse files
authored
Merge pull request stackify#12 from stackify/feature/RT-1844
RT-1844 - adding in logServerVariables toggle (defaults to disabled)
2 parents 3a22e1d + 536a975 commit 73b4e67

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

README.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,28 @@ $logger = new Logger('application_name', 'environment_name', $transport);
3737

3838
#### Optional Settings
3939

40-
<b>Proxy</b>
40+
41+
**Proxy**
4142
- ExecTransport supports data delivery through proxy. Specify proxy using [libcurl format](http://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html): <[protocol://][user:password@]proxyhost[:port]>
4243
```php
4344
$transport = new ExecTransport($apiKey, ['proxy' => 'https://55.88.22.11:3128']);
4445
```
4546

46-
<b>Curl path</b>
47+
**Curl path**
4748
- It can be useful to specify ```curl``` destination path for ExecTransport. This option is set to 'curl' by default.
4849
```php
4950
$transport = new ExecTransport($apiKey, ['curlPath' => '/usr/bin/curl']);
5051
```
5152

53+
**Log Server Environment Variables**
54+
- Server environment variables can be added to error log message metadata. **Note:** This will log all
55+
system environment variables; do not enable if sensitive information such as passwords or keys are stored this way.
56+
57+
```php
58+
$logger = new Logger('application_name', 'environment_name', $transport, true);
59+
```
60+
61+
5262
### CurlTransport
5363
CurlTransport does not require a Stackify agent to be installed and it also sends data directly to Stackify services. It collects log entries in a single batch and sends data using native [PHP cURL](http://php.net/manual/en/book.curl.php) functions. This way is a blocking one, so it should not be used on production environments. To configure CurlTransport you need to pass environment name and API key (license key):
5464
```php
@@ -61,22 +71,41 @@ $logger = new Logger('application_name', 'environment_name', $transport);
6171

6272
#### Optional Settings
6373

64-
<b>Proxy</b>
74+
**Proxy**
6575
- CurlTransport supports data delivery through proxy. Specify proxy using [libcurl format](http://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html): <[protocol://][user:password@]proxyhost[:port]>
6676
```php
6777
$transport = new CurlTransport($apiKey, ['proxy' => 'https://55.88.22.11:3128']);
6878
```
79+
80+
**Log Server Environment Variables**
81+
- Server environment variables can be added to error log message metadata. **Note:** This will log all
82+
system environment variables; do not enable if sensitive information such as passwords or keys are stored this way.
83+
84+
```php
85+
$logger = new Logger('application_name', 'environment_name', $transport, true);
86+
```
87+
6988
### AgentTransport
7089

7190
AgentTransport does not require additional configuration in your PHP code because all data is passed to the [Stackify agent](http://support.stackify.com/hc/en-us/articles/205419575). The agent must be installed on the same machine. Local TCP socket on port 10515 is used, so performance of your application is affected minimally.
7291
```php
7392
use Stackify\Log\Standalone\Logger;
7493

75-
$logger = new Logger('appname.com');
94+
$logger = new Logger('application_name', 'environment_name');
7695
```
7796

7897
You will need to enable the TCP listener by checking the "PHP App Logs (Agent Log Collector)" in the server settings page in Stackify. See [Log Collectors Page](http://support.stackify.com/hc/en-us/articles/204719709) for more details.
7998

99+
#### Optional Settings
100+
101+
**Log Server Environment Variables**
102+
- Server environment variables can be added to error log message metadata. **Note:** This will log all
103+
system environment variables; do not enable if sensitive information such as passwords or keys are stored this way.
104+
105+
```php
106+
$logger = new Logger('application_name', 'environment_name', null, true);
107+
```
108+
80109
## Troubleshooting
81110

82111
If transport does not work, try looking into ```vendor\stackify\logger\src\Stackify\debug\log.log``` file (if it is available for writing). Errors are also written to global PHP [error_log](http://php.net/manual/en/errorfunc.configuration.php#ini.error-log).
@@ -87,7 +116,7 @@ $transport = new ExecTransport($apiKey, ['debug' => true]);
87116

88117
## License
89118

90-
Copyright 2015 Stackify, LLC.
119+
Copyright 2018 Stackify, LLC.
91120

92121
Licensed under the Apache License, Version 2.0 (the "License");
93122
you may not use this file except in compliance with the License.

src/Stackify/Log/Builder/MessageBuilder.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ class MessageBuilder implements BuilderInterface
1919
protected $loggerName;
2020
protected $appName;
2121
protected $environmentName;
22+
protected $logServerVariables;
2223

23-
public function __construct($loggerName, $appName, $environmentName = null)
24+
public function __construct($loggerName, $appName, $environmentName = null, $logServerVariables = false)
2425
{
2526
if (!function_exists('json_encode')) {
2627
throw new InitializationException('JSON extension is required for Stackify logger');
2728
}
2829
$this->loggerName = $loggerName;
2930
$this->appName = $this->validateNotEmpty('AppName', $appName);
3031
$this->environmentName = $environmentName;
32+
$this->logServerVariables = $logServerVariables;
3133
// set state for environment details
3234
EnvironmentDetail::getInstance()->init($appName, $environmentName);
3335
}
@@ -71,7 +73,7 @@ public function createLogMsg(LogEntryInterface $logEntry)
7173
$errorWrapper = new ErrorWrapper($logEntry);
7274
}
7375
if (null !== $errorWrapper) {
74-
$error = new StackifyError($this->appName, $this->environmentName);
76+
$error = new StackifyError($this->appName, $this->environmentName, $this->logServerVariables);
7577
$error->OccurredEpochMillis = $logEntry->getMilliseconds();
7678
$error->Error = $this->getErrorItem($errorWrapper);
7779
$logMsg->setError($error);
@@ -120,4 +122,4 @@ protected function validateNotEmpty($name, $value)
120122
return $result;
121123
}
122124

123-
}
125+
}

src/Stackify/Log/Entities/Api/StackifyError.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,20 @@ class StackifyError
3939
*/
4040
public $UserName;
4141

42-
public function __construct($appName, $environmentName)
42+
public function __construct($appName, $environmentName, $logServerVariables = false)
4343
{
4444
$this->EnvironmentDetail = EnvironmentDetail::getInstance()
4545
->init($appName, $environmentName);
4646
$this->WebRequestDetail = WebRequestDetail::getInstance();
47-
$this->ServerVariables = $this->getEnvironmentVariables();
47+
48+
if ($logServerVariables) {
49+
$this->ServerVariables = $this->getEnvironmentVariables();
50+
}
4851
}
4952

5053
private function getEnvironmentVariables()
5154
{
5255
return isset($_SERVER) ? WebRequestDetail::getRequestMap($_SERVER) : null;
5356
}
5457

55-
}
58+
}

src/Stackify/Log/Standalone/Logger.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class Logger extends AbstractLogger
1616
*/
1717
private $transport;
1818

19-
public function __construct($appName, $environmentName = null, TransportInterface $transport = null)
19+
public function __construct($appName, $environmentName = null, TransportInterface $transport = null, $logServerVariables = false)
2020
{
21-
$messageBuilder = new MessageBuilder('Stackify PHP Logger v.1.0', $appName, $environmentName);
21+
$messageBuilder = new MessageBuilder('Stackify PHP Logger v.1.0', $appName, $environmentName, $logServerVariables);
2222
if (null === $transport) {
2323
$transport = new AgentTransport();
2424
}
@@ -42,4 +42,4 @@ public function log($level, $message, array $context = array())
4242
$this->transport->addEntry(new LogEntry($logEvent));
4343
}
4444

45-
}
45+
}

0 commit comments

Comments
 (0)