stackify/logger
Composer 安装命令:
composer require stackify/logger
包简介
Stackify logs and errors for PHP
README 文档
README
Stackify PHP Logger
Standalone Stackify PHP PSR-3 Logger.
- Errors and Logs Overview: http://support.stackify.com/errors-and-logs-overview/
- Sign Up for a Trial: http://www.stackify.com/sign-up/
PHP Logging Framework Integrations
- Monolog Handler: https://github.com/stackify/stackify-log-monolog
- log4php Appender: https://github.com/stackify/stackify-log-log4php
Installation
Install the latest version with composer require stackify/logger
Requirements
- Stackify PHP Logger ^2.0 works with PHP 7.1 or above.
- Stackify PHP Logger ^1.0 works with PHP 5.3 or above.
Installation with Linux Agent
This is the suggested installation option, offering the best logging performance.
use Stackify\Log\Standalone\Logger; $logger = new Logger('application_name', 'environment_name');
Installation without Linux Agent
This option does not require the Stackify Agent to be installed because it sends data directly to Stackify services. It collects log entries in batches, calls curl using the exec function, and sends data to the background immediately [exec('curl ... &')]. This will affect the performance of your application minimally, but it requires permissions to call exec inside the PHP script and it may cause silent data loss in the event of any network issues. This transport method does not work on Windows. To configure ExecTransport you need to pass the environment name and API key (license key):
use Stackify\Log\Transport\ExecTransport; use Stackify\Log\Standalone\Logger; $transport = new ExecTransport('api_key'); $logger = new Logger('application_name', 'environment_name', $transport);
Optional Settings
Proxy
- ExecTransport supports data delivery through proxy. Specify proxy using libcurl format:
<[protocol://][user:password@]proxyhost[:port]>
$transport = new ExecTransport($apiKey, ['proxy' => 'https://55.88.22.11:3128']);
Curl path
- It can be useful to specify
curldestination path for ExecTransport. This option is set to 'curl' by default.
$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.
$logger = new Logger('application_name', 'environment_name', $transport, true);
Configuration Settings
- This allow users to override default settings of the logger (Masking Request Variables, Session, Cookie or Updating connection properties to different Transports etc.)
- Note - By default capturing raw post data
(e.g. file_get_contents("php://input"))and$_POSTvariables areDISABLEDby default- To enable you can set the following options to
true CapturePostVariables-Boolean- Capture$_POSTvariablesCaptureRawPostData-Boolean- Capturephp://inputstream data(e.g. file_get_contents("php://input"))$config = array( 'CapturePostVariables' => true, 'CaptureRawPostData' => true, ... );
- To enable you can set the following options to
- Note - For the
Whitelist/Blackistsetting. Anythingfalsy(null,false,array()etc. - Refer to php empty function checking) will be considered asDo Not Track- No variable data will be processed.
Logger Level
$config = array( 'CaptureServerVariables' => false, 'CaptureServerVariablesWhitelist' => '*', 'CaptureServerVariablesBlacklist' => 'REMOTE_ADDR,SERVER_ADDR', ... ); $logger = new Logger('application_name', 'environment_name', $transport, true, $config);
Transport Level
- This applies to all the transports
(ExecTransport, CurlTransport, AgentTransport, AgentSocketTransport)
$config = array( 'CaptureServerVariables' => false, 'CaptureServerVariablesWhitelist' => '*', 'CaptureServerVariablesBlacklist' => 'REMOTE_ADDR,SERVER_ADDR', ... ); $transport = new ExecTransport($apiKey, [ 'config' => $config ]);
Available Options:
Server Variables
CaptureServerVariables-Boolean- Capture$_SERVERvariablesCaptureServerVariablesWhitelist-ArrayorComma-delimited string- Whitelist$_SERVERattributesCaptureServerVariablesBlacklist-ArrayorComma-delimited string- Mask$_SERVERattributes (e.g.attribute => 'X-MASKED-X')
Get Variables
CaptureGetVariables-Boolean- Capture$_GETvariablesCaptureGetVariablesWhitelist-ArrayorComma-delimited string- Whitelist$_GETattributesCaptureGetVariablesBlacklist-ArrayorComma-delimited string- Mask$_GETattributes (e.g.attribute => 'X-MASKED-X')
Post Variables
CapturePostVariables-Boolean- Capture$_POSTvariablesCapturePostVariablesWhitelist-ArrayorComma-delimited string- Whitelist$_POSTattributesCapturePostVariablesBlacklist-ArrayorComma-delimited string- Mask$_POSTattributes (e.g.attribute => 'X-MASKED-X')
Session Variables
CaptureSessionVariables-Boolean- Capture$_SESSIONvariablesCaptureSessionVariablesWhitelist-ArrayorComma-delimited string- Whitelist$_SESSIONattributesCaptureSessionVariablesBlacklist-ArrayorComma-delimited string- Mask$_SESSIONattributes (e.g.attribute => 'X-MASKED-X')
Error Headers
CaptureErrorHeaders-Boolean- CaptureHEADERattributes available in$_SERVERvariableCaptureErrorHeadersWhitelist-ArrayorComma-delimited string- WhitelistHEADERattributes in$_SERVERvariableCaptureErrorHeadersBlacklist-ArrayorComma-delimited string- MaskHEADERattributes in$_SERVERvariable (e.g.attribute => 'X-MASKED-X')
Error Cookies
CaptureErrorCookies-Boolean- Capture$_COOKIEvariablesCaptureErrorCookiesWhitelist-ArrayorComma-delimited string- Whitelist$_COOKIEattributesCaptureErrorCookiesBlacklist-ArrayorComma-delimited string- Mask$_COOKIEattributes
Capture Raw Post Data
CaptureRawPostData-Boolean- Capturephp://inputstream data(e.g. file_get_contents("php://input"))
Debug Settings
Debug-Boolean- Enable DEBUG in the loggerDebugLogPath-String- A qualified path for the log file produced during debug or error
Agent Transport Settings
Protocol-String- Protocol can betcporudpHost-String- Server HostnamePort-Numeric- PortSocketTimeoutConnect-Numeric- Connection Request TimeoutSocketTimeoutWrite-Numeric- Connection Write TimeoutSocketMaxConnectAttempts-Numeric- Connection Attempts
Agent Socket Transport Settings
DomainSocketPath-String- Stackify Agent unix socket path
API or Curl Exec Socket Transport Settings
ApiBaseUrl-String- Stackify API base urlApiCallLogsEndpoint-String- Stackify API Call Logs endpointApiMaxTimeout-Numeric- Stackify API Call Max TimeoutApiVersionHeader-String- Stackify API Version Header
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.
Note that ExecTransport does not produce any errors at all, but you can switch it to debug mode:
$transport = new ExecTransport($apiKey, ['debug' => true]);
You can set it also on the Logger level. Setting the Debug and DebugLogPath
$config = array( 'DebugLogPath' => '/path/to/log.log', 'Debug' => true ); $logger = new Logger('application_name', 'environment_name', $transport, true, $config);
Real User Monitoring (RUM)
Real user monitoring injects a script tag containing the RUM JS that is responsible for capturing information about the http requests on the browser. This approach is manual and needs to be configured.
RUM - Setup
/** Requires composer **/ $applicationName = 'Your Application Name'; $environment = 'YourEnvironment'; $rumKey = 'YourRumKey'; \Stackify\Utils\Rum::getInstance()->setupConfiguration( $applicationName, $environment, $rumKey );
RUM - Application
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <?php echo \Stackify\Utils\Rum::getInstance()->insertRumScript(); ?> <title>Title</title> </head> ...
License
Copyright 2019 Stackify, LLC.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
stackify/logger 适用场景与选型建议
stackify/logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 282.25k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2014 年 12 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「logging」 「monolog」 「psr-3」 「log4php」 「stackify」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 stackify/logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stackify/logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 stackify/logger 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A GeoIP decorator/processor for monolog
A Zend Framework module that sets up Monolog for logging in applications.
Laravel 5.6 Monolog custom telegram channel
A Monolog processor to add X-Request-Id or UNIQUE_ID env to monolog stack if present, provide a default one otherwise. Optionally, add a forwarded request-id list.
PSR-3 compatible logger with dynamic file naming and hourly rotation, powered by Monolog
Asynchronous Sentry for Symfony - Fire and forget
统计信息
- 总下载量: 282.25k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 27
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2014-12-29