Skip to content

Commit 176b304

Browse files
homiedopieMichael Mantos
andauthored
Able to add custom configuration for loggers (#15)
* Add initial commit for configurable logger * Add wildcard checking * Add debug setting * Fix namespace * Transport fixes * Add fix config and request details * Update is int to numeric * Add request body debug * Update README file * Add logger changes * Add note for get debug transport level * Update readme * Update fallback request map parameters based on default settings Co-authored-by: Michael Mantos <mmantos@stackify.com>
1 parent dc96f2c commit 176b304

12 files changed

Lines changed: 1624 additions & 42 deletions

README.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,81 @@ system environment variables; do not enable if sensitive information such as pas
6262
$logger = new Logger('application_name', 'environment_name', $transport, true);
6363
```
6464

65-
65+
### **Configuration Settings**
66+
- This allow users to override default settings of the logger (Masking Request Variables, Session, Cookie or Updating connection properties to different Transports etc.)
67+
- **Note** - For the `Whitelist/Blackist` setting. Anything `falsy` (`null`, `false`, `array()` etc. - Refer to php [empty](https://www.php.net/manual/en/function.empty.php) function checking) will be considered as `Do Not Track` - No variable data will be processed.
68+
69+
#### Logger Level
70+
```php
71+
$config = array(
72+
'CaptureServerVariables' => false,
73+
'CaptureServerVariablesWhitelist' => '*',
74+
'CaptureServerVariablesBlacklist' => 'REMOTE_ADDR,SERVER_ADDR',
75+
...
76+
);
77+
78+
$logger = new Logger('application_name', 'environment_name', $transport, true, $config);
79+
```
80+
81+
#### Transport Level
82+
- This applies to all the transports `(ExecTransport, CurlTransport, AgentTransport, AgentSocketTransport)`
83+
```php
84+
$config = array(
85+
'CaptureServerVariables' => false,
86+
'CaptureServerVariablesWhitelist' => '*',
87+
'CaptureServerVariablesBlacklist' => 'REMOTE_ADDR,SERVER_ADDR',
88+
...
89+
);
90+
91+
$transport = new ExecTransport($apiKey, [
92+
'config' => $config
93+
]);
94+
```
95+
### Available Options:
96+
#### Server Variables
97+
- `CaptureServerVariables` - `Boolean` - Capture `$_SERVER` variables
98+
- `CaptureServerVariablesWhitelist` - `Array` or `Comma-delimited string` - Whitelist `$_SERVER` attributes
99+
- `CaptureServerVariablesBlacklist` - `Array` or `Comma-delimited string` - Mask `$_SERVER` attributes (e.g. `attribute => 'X-MASKED-X'`)
100+
#### Get Variables
101+
- `CaptureGetVariables` - `Boolean` - Capture `$_GET` variables
102+
- `CaptureGetVariablesWhitelist` - `Array` or `Comma-delimited string` - Whitelist `$_GET` attributes
103+
- `CaptureGetVariablesBlacklist` - `Array` or `Comma-delimited string` - Mask `$_GET` attributes (e.g. `attribute => 'X-MASKED-X'`)
104+
#### Post Variables
105+
- `CapturePostVariables` - `Boolean` - Capture `$_POST` variables
106+
- `CapturePostVariablesWhitelist` - `Array` or `Comma-delimited string` - Whitelist `$_POST` attributes
107+
- `CapturePostVariablesBlacklist` - `Array` or `Comma-delimited string` - Mask `$_POST` attributes (e.g. `attribute => 'X-MASKED-X'`)
108+
#### Session Variables
109+
- `CaptureSessionVariables` - `Boolean` - Capture `$_SESSION` variables
110+
- `CaptureSessionVariablesWhitelist` - `Array` or `Comma-delimited string` - Whitelist `$_SESSION` attributes
111+
- `CaptureSessionVariablesBlacklist` - `Array` or `Comma-delimited string` - Mask `$_SESSION` attributes (e.g. `attribute => 'X-MASKED-X'`)
112+
#### Error Headers
113+
- `CaptureErrorHeaders` - `Boolean` - Capture `HEADER` attributes available in `$_SERVER` variable
114+
- `CaptureErrorHeadersWhitelist` - `Array` or `Comma-delimited string` - Whitelist `HEADER` attributes in `$_SERVER` variable
115+
- `CaptureErrorHeadersBlacklist` - `Array` or `Comma-delimited string` - Mask `HEADER` attributes in `$_SERVER` variable (e.g. `attribute => 'X-MASKED-X'`)
116+
#### Error Cookies
117+
- `CaptureErrorCookies` - `Boolean` - Capture `$_COOKIE` variables
118+
- `CaptureErrorCookiesWhitelist` - `Array` or `Comma-delimited string` - Whitelist `$_COOKIE` attributes
119+
- `CaptureErrorCookiesBlacklist` - `Array` or `Comma-delimited string` - Mask `$_COOKIE` attributes
120+
#### Capture Raw Post Data
121+
- `CaptureRawPostData` - `Boolean` - Capture `php://input` stream data `(e.g. file_get_contents("php://input"))`
122+
#### Debug Settings
123+
- `Debug` - `Boolean` - Enable DEBUG in the logger
124+
- `DebugLogPath` - `String` - A qualified path for the log file produced during debug or error
125+
#### Agent Transport Settings
126+
- `Protocol` - `String` - Protocol can be `tcp` or `udp`
127+
- `Host` - `String` - Server Hostname
128+
- `Port` - `Numeric` - Port
129+
- `SocketTimeoutConnect` - `Numeric` - Connection Request Timeout
130+
- `SocketTimeoutWrite` - `Numeric` - Connection Write Timeout
131+
- `SocketMaxConnectAttempts` - `Numeric` - Connection Attempts
132+
#### Agent Socket Transport Settings
133+
- `DomainSocketPath` - `String` - Stackify Agent unix socket path
134+
#### API or Curl Exec Socket Transport Settings
135+
- `ApiBaseUrl` - `String` - Stackify API base url
136+
- `ApiCallLogsEndpoint` - `String` - Stackify API Call Logs endpoint
137+
- `ApiMaxTimeout` - `Numeric` - Stackify API Call Max Timeout
138+
- `ApiVersionHeader` - `String` - Stackify API Version Header
139+
66140
#### Troubleshooting
67141

68142
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).
@@ -71,6 +145,17 @@ Note that ExecTransport does not produce any errors at all, but you can switch i
71145
$transport = new ExecTransport($apiKey, ['debug' => true]);
72146
```
73147

148+
You can set it also on the `Logger` level. Setting the `Debug` and `DebugLogPath`
149+
150+
```php
151+
$config = array(
152+
'DebugLogPath' => '/path/to/log.log',
153+
'Debug' => true
154+
);
155+
156+
$logger = new Logger('application_name', 'environment_name', $transport, true, $config);
157+
```
158+
74159
## License
75160

76161
Copyright 2019 Stackify, LLC.

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Stackify\Log\Entities\Api;
44

5+
use Stackify\Log\Transport\Config\Agent;
6+
57
class StackifyError
68
{
79
/**
@@ -50,9 +52,20 @@ public function __construct($appName, $environmentName, $logServerVariables = fa
5052
}
5153
}
5254

55+
/**
56+
* Get server environment variables
57+
*
58+
* @return array
59+
*/
5360
private function getEnvironmentVariables()
5461
{
55-
return isset($_SERVER) ? WebRequestDetail::getRequestMap($_SERVER) : null;
62+
$agentConfig = Agent::getInstance();
63+
if ($agentConfig) {
64+
return isset($_SERVER) && $agentConfig->getCaptureServerVariables()
65+
? WebRequestDetail::getRequestMap($_SERVER, $agentConfig->getCaptureServerVariablesBlacklist(), $agentConfig->getCaptureServerVariablesWhitelist())
66+
: null;
67+
}
68+
return isset($_SERVER) ? WebRequestDetail::getRequestMap($_SERVER, null, array('*')) : null;
5669
}
5770

5871
}

0 commit comments

Comments
 (0)