Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,28 @@ $logger = new Logger('application_name', 'environment_name', $transport);

#### Optional Settings

<b>Proxy</b>

**Proxy**
- 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]>
```php
$transport = new ExecTransport($apiKey, ['proxy' => 'https://55.88.22.11:3128']);
```

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

**Log Server Environment Variables**
- Server environment variables can be added to error log message metadata. **Note:** This will log all
system environment variables; do not enable if sensitive information such as passwords or keys are stored this way.

```php
$logger = new Logger('application_name', 'environment_name', $transport, true);
```


### CurlTransport
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):
```php
Expand All @@ -61,22 +71,41 @@ $logger = new Logger('application_name', 'environment_name', $transport);

#### Optional Settings

<b>Proxy</b>
**Proxy**
- 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]>
```php
$transport = new CurlTransport($apiKey, ['proxy' => 'https://55.88.22.11:3128']);
```

**Log Server Environment Variables**
- Server environment variables can be added to error log message metadata. **Note:** This will log all
system environment variables; do not enable if sensitive information such as passwords or keys are stored this way.

```php
$logger = new Logger('application_name', 'environment_name', $transport, true);
```

### AgentTransport

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.
```php
use Stackify\Log\Standalone\Logger;

$logger = new Logger('appname.com');
$logger = new Logger('application_name', 'environment_name');
```

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.

#### Optional Settings

**Log Server Environment Variables**
- Server environment variables can be added to error log message metadata. **Note:** This will log all
system environment variables; do not enable if sensitive information such as passwords or keys are stored this way.

```php
$logger = new Logger('application_name', 'environment_name', null, true);
```

## Troubleshooting

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).
Expand All @@ -87,7 +116,7 @@ $transport = new ExecTransport($apiKey, ['debug' => true]);

## License

Copyright 2015 Stackify, LLC.
Copyright 2018 Stackify, LLC.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
8 changes: 5 additions & 3 deletions src/Stackify/Log/Builder/MessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ class MessageBuilder implements BuilderInterface
protected $loggerName;
protected $appName;
protected $environmentName;
protected $logServerVariables;

public function __construct($loggerName, $appName, $environmentName = null)
public function __construct($loggerName, $appName, $environmentName = null, $logServerVariables = false)
{
if (!function_exists('json_encode')) {
throw new InitializationException('JSON extension is required for Stackify logger');
}
$this->loggerName = $loggerName;
$this->appName = $this->validateNotEmpty('AppName', $appName);
$this->environmentName = $environmentName;
$this->logServerVariables = $logServerVariables;
// set state for environment details
EnvironmentDetail::getInstance()->init($appName, $environmentName);
}
Expand Down Expand Up @@ -71,7 +73,7 @@ public function createLogMsg(LogEntryInterface $logEntry)
$errorWrapper = new ErrorWrapper($logEntry);
}
if (null !== $errorWrapper) {
$error = new StackifyError($this->appName, $this->environmentName);
$error = new StackifyError($this->appName, $this->environmentName, $this->logServerVariables);
$error->OccurredEpochMillis = $logEntry->getMilliseconds();
$error->Error = $this->getErrorItem($errorWrapper);
$logMsg->setError($error);
Expand Down Expand Up @@ -120,4 +122,4 @@ protected function validateNotEmpty($name, $value)
return $result;
}

}
}
9 changes: 6 additions & 3 deletions src/Stackify/Log/Entities/Api/StackifyError.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,20 @@ class StackifyError
*/
public $UserName;

public function __construct($appName, $environmentName)
public function __construct($appName, $environmentName, $logServerVariables = false)
{
$this->EnvironmentDetail = EnvironmentDetail::getInstance()
->init($appName, $environmentName);
$this->WebRequestDetail = WebRequestDetail::getInstance();
$this->ServerVariables = $this->getEnvironmentVariables();

if ($logServerVariables) {
$this->ServerVariables = $this->getEnvironmentVariables();
}
}

private function getEnvironmentVariables()
{
return isset($_SERVER) ? WebRequestDetail::getRequestMap($_SERVER) : null;
}

}
}
6 changes: 3 additions & 3 deletions src/Stackify/Log/Standalone/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class Logger extends AbstractLogger
*/
private $transport;

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

}
}