giacomofurlan/php-graylog-gelf
Composer 安装命令:
composer require giacomofurlan/php-graylog-gelf
包简介
A PHP PSR-3 compliant logger to send data to graylog2 (GELF format)
README 文档
README
This library aims to help the developer with both a PSR-3 compliant and a custom (extended) logger to send data to Graylog 2 via the Graylog Extended Log Format.
Class information
GiacomoFurlan\Graylog\GELFLogger
It implements the Psr\Log\LoggerInterface interface, so use it as a standard logger.
It can set the short message, the context and the log level.
GiacomoFurlan\Graylog\ExtendedGELFLogger
It extends the previous class, but add gelf* functions to send more complex information.
It also allows the logs to be enqueued, rather than being sent immediately.
gelfLoggelfAlertgelfCriticalgelfDebuggelfEmergencygelfErrorgelfInfogelfNoticegelfWarningflush
These function accept a GELF object and the possibility to flush the messages instantly (default true).
The flush function flushes eventual messages previously enqueued.
GiacomoFurlan\Graylog\GELF
A data-transfer object used by ExtendedGELFLogger. It allows to set the short and full messages, to overwrite
the host information and to add variables to the context.
GiacomoFurlan\Graylog\UDPWriter
UDP implementation of the WriterInterface used to instantiate the loggers.
If there are enqueued messages (writing with flush set to false, changeable using the extended logger),
it will try to run flush when destroyed.
GiacomoFurlan\Graylog\TCPWriter
UDP implementation of the WriterInterface used to instantiate the loggers.
If there are enqueued messages (writing with flush set to false, changeable using the extended logger),
it will try to run flush when destroyed.
GiacomoFurlan\Graylog\GELFException
It can be thrown trying to send the information.
- Code
GELFException::CODE_MISSING_HOST: the host is's not set or empty - Code
GELFException::CODE_CANT_SEND_MESSAGE: an error occurred trying to send the packet
More information may be gathered reading the exception's message.
Usage example
use GiacomoFurlan\Graylog\ExtendedGELFLogger; use GiacomoFurlan\Graylog\GELF; use GiacomoFurlan\Graylog\GELFException; use GiacomoFurlan\Graylog\GELFLogger; use GiacomoFurlan\Graylog\UDPWriter; use Psr\Log\LogLevel; // ... $address = 'ip.or.dns.of.graylog.server'; $port = 12201; // or whatever port is configured in Graylog 2 $hostId = 'MyHost'; // host identifier // Instantiate the writer $writer = new UDPWriter($address, $port); // Instantiate the logger (use one or the other... or both) $simpleLogger = new GELFLogger($writer, $hostId); $extendedLogger = new ExtendedGELFLogger($writer, $hostId); // ... // GELFLogger usage example try { // ... } catch (\Throwable $exception) { $simpleLogger->log(LogLevel::ERROR, $exception->getMessage(), ['code' => $exception->getCode()]); // or $simpleLogger->error($exception->getMessage(), ['code' => $exception->getCode()]); } // ExtendedGELFLogger usage example try { // ... } catch (\Throwable $exception) { $message = new GELF($exception->getMessage(), ['code' => $exception->getCode()]); $message->setHost('Overwritten host'); $message->setFullMessage($exception->getTraceAsString()); $message->setContextEntryset('fileName', $exception->getFile()); $message->setContextEntryset('fileLine', $exception->getLine()); $extendedLogger->gelfError($message); }
giacomofurlan/php-graylog-gelf 适用场景与选型建议
giacomofurlan/php-graylog-gelf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.88k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 08 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logger」 「udp」 「psr」 「graylog2」 「gelf」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 giacomofurlan/php-graylog-gelf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 giacomofurlan/php-graylog-gelf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 giacomofurlan/php-graylog-gelf 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple, event-driven multicast UDP message client and server for ReactPHP.
Simple PSR-16 cache implementations for WordPress transient the OOP way
Workflow logger
HTTP request logger middleware for Laravel
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
A Laravel package to send logs to a gelf compatible backend like graylog
统计信息
- 总下载量: 7.88k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-08-29