kabudu/event-logger
Composer 安装命令:
composer require kabudu/event-logger
包简介
Event logger is a PHP based event logger library that makes it easy to collect and query events in your web application based on user or system actions.
README 文档
README
Event logger is a PHP based event logger library that makes it easy to collect and query events in your web application based on user or system actions.
With event logger you can:
- collect any kind of statistical data such as number of clicks for a certain url, page views, conversions or any kind of user generated action for your web application, API or mobile application
- collect and store human readable event logs such as: Bob smith updated his email address on 12th January, 2015 at 12:30AM
- collect and store human readable user notifications such as: Bob Smith sent you a message on 12th January, 2015 at 12:30AM
- collect and store system events, either human readable or not
- and any other sort of event logging your imagination allows you to come up with
Features
-
Collect any kind of event data
@see EventLogger\Event\EventInterface -
Query and analyse the collected data
-
Multiple persistence strategies (currently ships with an SQLite, MySQL and Null implementation)
-
Extensible architecture
-
Full test coverage with phpunit
Requirements
- PHP 5.6.0+
- SQLite 3.0.7+ (required for the unit tests, you do not have to use the provided SQLite storage implementation)
- Optional but recommended: Composer
Getting Started
The simplest way to work with event-logger is when it is installed as a Composer package in your application. Composer is not required, but it simplifies the usage of this library.
To find out more about Composer, please visit https://getcomposer.org/
a) Add event-logger to your applications composer.json file
// ...
"require": {
"kabudu/event-logger": "1.x" // The most recent tagged version
},
// ...
Run composer install
b) Add the Composer autoload to your projects bootstrap file if you have not done so already. (example)
require 'vendor/autoload.php';
c) If you are not using Composer, simply download the package and copy the "src" folder into your project ensuring that your application can autoload the libraries classes
Log a Single Event
use EventLogger\Event\Event;
use EventLogger\Logger\Logger;
use EventLogger\Storage\SQLiteStorage;
// Initialise an SQLite database/table
$pdo = new \PDO('sqlite:my_event_log.sqlite');
$pdo->exec(sprintf("CREATE TABLE IF NOT EXISTS %s (
id INTEGER PRIMARY KEY,
type TEXT,
sub_type TEXT DEFAULT NULL,
target_type TEXT DEFAULT NULL,
target_id INTEGER DEFAULT 0,
message INTEGER DEFAULT NULL,
data TEXT DEFAULT NULL,
created TEXT DEFAULT '0000-00-00 00:00:00',
action TEXT DEFAULT NULL,
user TEXT DEFAULT NULL
)",SQLiteStorage::TABLE_NAME));
// Create the storage strategy
$storage = new SQLiteStorage($pdo);
// Create the logger
$logger = new Logger($storage);
// Create an event
$event = new Event();
$event->setType('event');
$event->setSubType('pageview');
$event->setMessage('user [foo] viewed a page of interest to you');
$event->setData(array('[foo]' => 'bar'));
$event->setUser(2);
// Log the event
$logger->log($event);
Log Multiple Events
use EventLogger\Event\Event;
use EventLogger\Logger\Logger;
use EventLogger\Storage\SQLiteStorage;
use EventLogger\Event\Collection\EventCollection;
// Initialise an SQLite database/table
$pdo = new \PDO('sqlite:my_event_log.sqlite');
$pdo->exec(sprintf("CREATE TABLE IF NOT EXISTS %s (
id INTEGER PRIMARY KEY,
type TEXT,
sub_type TEXT DEFAULT NULL,
target_type TEXT DEFAULT NULL,
target_id INTEGER DEFAULT 0,
message INTEGER DEFAULT NULL,
data TEXT DEFAULT NULL,
created TEXT DEFAULT '0000-00-00 00:00:00',
action TEXT DEFAULT NULL,
user TEXT DEFAULT NULL
)",SQLiteStorage::TABLE_NAME));
// Create the storage strategy
$storage = new SQLiteStorage($pdo);
// Create the logger
$logger = new Logger($storage);
// Create an event
$event1 = new Event();
$event->setType('event');
$event->setSubType('pageview');
$event->setData(array('[foo]' => 'bar'));
$event->setUser(2);
// Create another event
$event2 = new Event();
$event->setType('event');
$event->setSubType('system');
$event->setMessage('A nominal value of [nominal] has been detected for the pressure release valve');
$event->setData(array('[nominal]' => '120'));
// create an event collection and add your events
$collection = new EventCollection();
$collection->addEvent($event1);
$collection->addEvent($event2);
// Log the events
$logger->log($collection);
Log an Event to Multiple Persistence Back-ends
Note: In a real world application you might have implemented your own persistence strategies, e.g. MongoDB, Elasticsearch, Google Cloud Datastore etc.
use EventLogger\Event\Event;
use EventLogger\Logger\Logger;
use EventLogger\Storage\SQLiteStorage;
use EventLogger\Storage\NullStorage;
use EventLogger\Logger\Collection\LoggerCollection;
// Initialise an SQLite database/table
$pdo = new \PDO('sqlite:my_event_log.sqlite');
$pdo->exec(sprintf("CREATE TABLE IF NOT EXISTS %s (
id INTEGER PRIMARY KEY,
type TEXT,
sub_type TEXT DEFAULT NULL,
target_type TEXT DEFAULT NULL,
target_id INTEGER DEFAULT 0,
message INTEGER DEFAULT NULL,
data TEXT DEFAULT NULL,
created TEXT DEFAULT '0000-00-00 00:00:00',
action TEXT DEFAULT NULL,
user TEXT DEFAULT NULL
)",SQLiteStorage::TABLE_NAME));
// Create a storage strategy
$sqliteStorage = new SQLiteStorage($pdo);
// Create another storage strategy
$nullStorage = new NullStorage();
// Create a logger
$logger1 = new Logger($sqliteStorage);
// Create another logger
$logger2 = new Logger($nullStorage);
// Create a logger collection and add your loggers
$collection = new LoggerCollection();
$collection->addLogger($logger1);
$collection->addLogger($logger2);
// Create an event
$event = new Event();
$event->setType('event');
$event->setSubType('pageview');
$event->setMessage('user [foo] viewed a page of interest to you');
$event->setData(array('[foo]' => 'bar'));
$event->setUser(2);
// Log the event
$collection->log($event);
kabudu/event-logger 适用场景与选型建议
kabudu/event-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 193 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 03 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「event」 「conversion」 「statistic」 「marketing」 「tracking」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kabudu/event-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kabudu/event-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kabudu/event-logger 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A library that provides a simple infrastructure to create your own converters and to perform any conversion you want
A Zend Framework module that sets up Monolog for logging in applications.
Asynchronous Sentry for Symfony - Fire and forget
Symfony bundle for broadway/broadway.
Fixer.io data provider for Peso
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
统计信息
- 总下载量: 193
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache
- 更新时间: 2015-03-24