dereuromark/cakephp-databaselog 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dereuromark/cakephp-databaselog

Composer 安装命令:

composer require dereuromark/cakephp-databaselog

包简介

A CakePHP plugin for storing and viewing application logs in the database

README 文档

README

CI Coverage Status PHPStan Latest Stable Version Minimum PHP Version License Total Downloads Coding Standards

DatabaseLog engine for CakePHP applications.

This branch is for CakePHP 5.2+. See version map for details.

Features

  • Easy setup and almost no dependencies.
  • Detailed log infos added for both Web and CLI log entries.
  • Defaults to SQLite as single app application lightweight approach.
  • Ideal for multi-server or serverless applications where logging to a file is just not convenient.
  • If DB is used, fallback to SQLite in case the DB is not reachable.
  • Simple admin interface to view/delete logs included.
  • Basic monitoring and alert system included.
  • Export to TXT files possible.

Log Rotation

While file handling requires file log rotation and splitting into chunks of (compressed) files, a database approach can more easily keep the logs together in a single database. This is more convinient when looking through them or searching for something specific.

This plugin internally combines log entries of the exact same "content" into a single row with an increased count. Additionally, you would want to add a cronjob triggered cleanup shell to keep the total size and row count below a certain threshold.

Demo

Clone and install the sandbox app, create some errors and browse the admin backend for the logs overview.

Or just attach it to your app directly. Time needed: 5 minutes.

Install

Composer (preferred)

composer require dereuromark/cakephp-databaselog

Setup

Load the plugin:

bin/cake plugin load DatabaseLog

You can simply modify the existing config entries in your config/app.php:

   'Log' => [
   	'debug' => [
   		'className' => 'DatabaseLog.Database',
   	],
   	'error' => [
   		'className' => 'DatabaseLog.Database',
   	],
   	...
   ],

This will use the database_log connection and an SQLite file database by default, stored in your logs folder.

Using an actual database (optional)

Create a config setting in your config/app.php what database connection it should log to:

'DatabaseLog' => [
	'connection' => 'custom',
],

It is recommended to not use the same connection as your production server (default) because when the DB is not reachable logging to it will also not be possible. In that case it will fall back to SQLite file logging on this server instance, though.

Once the connection is reachable, the database table (defaulting to database_logs) will be automatically created. No need to manually run any migration or SQL script here.

You can also manually create the table beforehand, if you prefer:

bin/cake Migrations migrate -p DatabaseLog

If you use a custom connection, make sure to set the connection here for migrations:

bin/cake Migrations migrate -p DatabaseLog -c custom

Fully tested so far are PostgreSQL and MySQL, but by using the ORM all major databases should be supported.

For default connection usage only: You can also just copy the migration file(s) into your app /config/Migrations/, modify if needed, and then run it as part of your app migrations.

Usage

Anywhere in your app where you call $this->log() or Log::write() the DatabaseLog engine will be used.

$this->log('This is a detailed message logged to the database', 'error');
// or
Log::write('error', 'This is a detailed message logged to the database');

There is also a browsable web backend you can view your logs with.

See Docs for more details.

dereuromark/cakephp-databaselog 适用场景与选型建议

dereuromark/cakephp-databaselog 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 171.81k 次下载、GitHub Stars 达 44, 最近一次更新时间为 2014 年 08 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「logging」 「database」 「plugin」 「debugging」 「cakephp」 「monitoring」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dereuromark/cakephp-databaselog 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dereuromark/cakephp-databaselog 我们能提供哪些服务?
定制开发 / 二次开发

基于 dereuromark/cakephp-databaselog 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 171.81k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 44
  • 点击次数: 25
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 44
  • Watchers: 4
  • Forks: 21
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-08-06