stackify/monolog
Composer 安装命令:
composer require stackify/monolog
包简介
Stackify logs and errors for Monolog
README 文档
README
Monolog handler for sending log messages and exceptions to Stackify. Monolog >= 3.0.0 is supported.
For Monolog V1
Use the 1.x branch
For Monolog V2
Use the 2.x branch
- Errors and Logs Overview: http://support.stackify.com/errors-and-logs-overview/
- Sign Up for a Trial: http://www.stackify.com/sign-up/
Installation
Install the latest version with composer require stackify/monolog "~2.0"
Installation with Linux Agent
This is the suggested installation option, offering the best logging performance.
PHP:
use Monolog\Logger; use Stackify\Log\Monolog\Handler as StackifyHandler; $handler = new StackifyHandler('application_name', 'environment_name'); $logger = new Logger('logger'); $logger->pushHandler($handler);
Symfony:
services: stackify_handler: class: "Stackify\\Log\\Monolog\\Handler" arguments: ["application_name", "environment_name"] monolog: handlers: stackify: type: service id: stackify_handler
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.
$handler = new StackifyHandler('application_name', 'environment_name', null, true);
Installation without Linux Agent
This option does not require a 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):
PHP:
use Stackify\Log\Transport\ExecTransport; use Stackify\Log\Monolog\Handler as StackifyHandler; $transport = new ExecTransport('api_key'); $handler = new StackifyHandler('application_name', 'environment_name', $transport); $logger = new Logger('logger'); $logger->pushHandler($handler);
Symfony:
services: stackify_transport: class: "Stackify\\Log\\Transport\ExecTransport" arguments: ["api_key"] stackify_handler: class: "Stackify\\Log\\Monolog\\Handler" arguments: ["application_name", "environment_name", "@stackify_transport"] monolog: handlers: stackify: type: service id: stackify_handler
Optional Configuration
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.
$handler = new StackifyHandler('application_name', 'environment_name', $transport, true);
Notes
To get more error details pass Exception objects to the logger if available:
try { $db->connect(); catch (DbException $ex) { // you may use any key name $logger->addError('DB is not available', ['ex' => $ex]); }
Additional Configuration
For additional configurations, you can set on the XML or the PHP File Configuration. Reference for the additional options are located on the stackify logger repository Stackify PHP Logger - Configuration Settings
Transport Level
- This applies to all the transports
(ExecTransport, CurlTransport, AgentTransport, AgentSocketTransport)
use Monolog\Logger; use Stackify\Log\Monolog\Handler as StackifyHandler; $config = array( 'CaptureServerVariables' => false, 'CaptureServerVariablesWhitelist' => '*', 'CaptureServerVariablesBlacklist' => 'REMOTE_ADDR,SERVER_ADDR', ... ); $transport = new ExecTransport($apiKey, [ 'config' => $config ]); $handler = new StackifyHandler('application_name', 'environment_name', $transport); $logger = new Logger('logger'); $logger->pushHandler($handler);
Handler Level
- This applies to the current Monolog Handler
use Monolog\Logger; use Stackify\Log\Monolog\Handler as StackifyHandler; $transport = new ExecTransport($apiKey); // Your selected transport (Can be null which defaults to AgentSocketTransport) $logServerVariables = false; // Default $config = array( 'CaptureServerVariables' => false, 'CaptureServerVariablesWhitelist' => '*', 'CaptureServerVariablesBlacklist' => 'REMOTE_ADDR,SERVER_ADDR', ... ); $handler = new StackifyHandler('application_name', 'environment_name', $transport, $logServerVariables, $config); $logger = new Logger('logger'); $logger->pushHandler($handler);
Handler Level Option
- Include Channel
- This will include the logger name or the channel set for the log entry.
use Monolog\Logger; use Stackify\Log\Monolog\Handler as StackifyHandler; $transport = new ExecTransport($apiKey); // Your selected transport (Can be null which defaults to AgentSocketTransport) $logServerVariables = false; // Default $config = array( 'IncludeChannel' => true, ... ); $handler = new StackifyHandler('application_name', 'environment_name', $transport, $logServerVariables, $config); $logger = new Logger('logger'); $logger->pushHandler($handler);
- Include Extra In Context
- This will include the extra property to the context (merging extra to context)
use Monolog\Logger; use Stackify\Log\Monolog\Handler as StackifyHandler; $transport = new ExecTransport($apiKey); // Your selected transport (Can be null which defaults to AgentSocketTransport) $logServerVariables = false; // Default $config = array( 'IncludeExtraInContext' => true, ... ); $handler = new StackifyHandler('application_name', 'environment_name', $transport, $logServerVariables, $config); $logger = new Logger('logger'); $logger->pushProcessor(function ($record) { if (empty($record['extra'])) { $record['extra'] = []; } $record['extra']['dummy'] = 1; return $record; }); $logger->pushHandler($handler);
Symfony
services: stackify_transport: class: "Stackify\\Log\\Transport\\CurlTransport" arguments: ["api_key"] # Square/Curly Brackets stackify_handler: class: "Stackify\\Log\\Monolog\\Handler" arguments: ["application_name", "environment_name", "@stackify_transport", false, { CaptureServerVariables: false, ... }] # or # Dash/Colon Space stackify_handler: class: "Stackify\\Log\\Monolog\\Handler" arguments: - "application_name" - "environment_name" - "@stackify_transport" - false - CaptureServerVariables: false CaptureServerWhitelist: "*" CaptureServerBlacklist: null monolog: handlers: stackify: type: service id: stackify_handler
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 StackifyHandler('application_name', 'environment_name', $transport, $logServerVariables, $config);
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/monolog 适用场景与选型建议
stackify/monolog 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 271.2k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2014 年 12 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「logging」 「monolog」 「psr-3」 「log4php」 「stackify」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 stackify/monolog 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stackify/monolog 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 stackify/monolog 相关的其它包
同方向 / 同关键字的高下载量 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
统计信息
- 总下载量: 271.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2014-12-29