gupalo/monolog-dbal-logger
Composer 安装命令:
composer require gupalo/monolog-dbal-logger
包简介
Monolog Handler for DBAL
README 文档
README
Installation
Add to your project via composer:
composer require gupalo/monolog-dbal-logger
Create log table.
CREATE TABLE `_log` (
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
`created_at` datetime NOT NULL,
`level` smallint NOT NULL DEFAULT 0,
`level_name` enum('debug','info','notice','warning','error','critical','alert','emergency') NULL DEFAULT NULL,
`channel` varchar(255) NOT NULL DEFAULT '',
`message` varchar(1024) NOT NULL DEFAULT '',
`context` text NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `log_created_at_level` (`created_at`, `level`) USING BTREE
) DEFAULT CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci;
Example
$connection is Doctrine\DBAL\Connection
$handler = new \Gupalo\MonologDbalLogger\MonologDbalLogger($connection);
$logger = new \Monolog\Logger();
$logger->pushHandler($handler);
$logger->addWarning('You might not read the docs', ['page' => 17, 'username' => 'guest']);
Symfony
Configuration example:
services.yaml
Gupalo\MonologDbalLogger\Symfony\ErrorLogListener:
tags: [ {name: 'kernel.event_subscriber'} ]
monolog.dbal_handler:
class: 'Gupalo\MonologDbalLogger\MonologDbalLogger'
public: true
bind:
$connection: '@doctrine.dbal.default_connection'
$level: 200
tags: ['monolog.logger']
monolog.yaml
monolog:
handlers:
db:
type: service
id: 'monolog.dbal_handler' # note - no "@"
channels: ["!event", "!request", "!security"]
Configure
Params in MonologDbalLogger::__construct:
string $table = '_log': table nameint $maxRows = 100000: if you have more rows than$maxRowsthen cleaner will eventually (1 in 100 chances) remove them
Params in MonologDbalCleaner::__construct:
string $table = '_log': table nameint $maxRows = 100000: keep at most this many rows (only deletes info-level rows,level < 250)int $infoRetentionDays = 1: delete info logs (level < 250) older than this many daysint $warningRetentionDays = 7: delete warnings (250 <= level < 400) older than this many daysint $errorRetentionDays = 30: delete errors (level >= 400) older than this many days- Set any retention to
0to disable that rule
Extend
You may extend MonologDbalLogger and add your own logic. See MyMonologDbalLogger as an example.
If you add additional fields, remember to change table creation SQL.
Table:
CREATE TABLE `_log` (
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
`created_at` datetime NOT NULL,
`level` smallint NOT NULL DEFAULT 0,
`level_name` enum('debug','info','notice','warning','error','critical','alert','emergency') NULL DEFAULT NULL,
`channel` varchar(255) NOT NULL DEFAULT '',
`message` varchar(1024) NOT NULL DEFAULT '',
`context` text NULL DEFAULT NULL,
`method` varchar(255) NULL DEFAULT NULL,
`cmd` varchar(255) NULL DEFAULT NULL,
`uid` varchar(32) NULL DEFAULT NULL,
`count` int NULL DEFAULT NULL,
`time` float NULL DEFAULT NULL,
`exception_class` varchar(1024) NULL DEFAULT NULL,
`exception_message` varchar(1024) NULL DEFAULT NULL,
`exception_line` varchar(1024) NULL DEFAULT NULL,
`exception_trace` text NULL,
PRIMARY KEY (`id`),
INDEX `log_created_at_level` (`created_at`, `level`) USING BTREE
) DEFAULT CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci;
EasyAdmin
Add to menu
yield MenuItem::linkToCrud('Log', 'fa-solid fa-file-waveform', Log::class);
Add to config/packages/doctrine.yaml
doctrine:
orm:
mappings:
# ...here is "App", add below
Gupalo:
is_bundle: false
dir: '%kernel.project_dir%/vendor/gupalo/monolog-dbal-logger/src/Entity'
prefix: 'Gupalo\MonologDbalLogger\Entity'
alias: Gupalo
Create controller. Override if needed
class LogCrudController extends \Gupalo\MonologDbalLogger\EasyAdmin\Controller\LogCrudController
{
}
Add to config/services.yaml
services:
Gupalo\MonologDbalLogger\Repository\LogRepository:
tags: [ 'doctrine.repository_service' ]
Other
See tests.
gupalo/monolog-dbal-logger 适用场景与选型建议
gupalo/monolog-dbal-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.16k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 07 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 gupalo/monolog-dbal-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gupalo/monolog-dbal-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 18.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-23