定制 aternos/codex 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

aternos/codex

Composer 安装命令:

composer require aternos/codex

包简介

PHP library to read, parse, print and analyse log files.

README 文档

README

About

Codex (lat. roughly for "log") is a PHP library to read, parse, print and analyse log files to find problems and suggest possible solutions. It was created mainly for Minecraft server logs but could be used for any other logs as well. This library provides a set up for a structured log parsing implementation and provides some useful basic implementation, mainly based on RegEx. Every part of this library can or even must be extended/overwritten while still following the interfaces, which ensure interoperability between the different parts of this library.

Installation

composer require aternos/codex

Usage

This is a short introduction to the idea of Codex, for some more examples check the test folder and/or read the code.

Logfile

A LogFile object implementing the LogFileInterface object is required to start reading a log. There are currently three different log file classes in this library.

<?php

$logFile = new \Aternos\Codex\Log\File\StringLogFile("This is the log content");
$logFile = new \Aternos\Codex\Log\File\PathLogFile("/path/to/log");
$logFile = new \Aternos\Codex\Log\File\StreamLogFile(fopen("/path/to/log", "r"));

Log

A Log object implementing the LogInterface is the most important object for the different operations. It represents the log content, which is split in Entries and Lines. And it offers quick access to the detection, parsing and analysing functions and can define which classes are used for those functions. If you know which log type you have or just want to test the default Log class, you can directly create a new instance, otherwise you can use detection as described below.

<?php

$log = new \Aternos\Codex\Log\Log();
$log->setLogFile($logFile);

Detection

If the log type (specifically the class name of the log type) is unknown you can use the Detective class to automatically detect the log type. The Detective class gets a list of possible log class names and executes their given Detectors.

<?php

$detective = new \Aternos\Codex\Detective\Detective();
$detective->addPossibleLogClass(\Aternos\Codex\Log\Log::class);
$log = $detective->detect();

The detect() function always returns a log object, if necessary it defaults to Log.

Parsing

Parsing reads the entire log and creates the Entry and Line objects which are parts of a Log object. Different log types can use different parsers by overwriting the LogInterface::getDefaultParser() function or by passing a parser object to the parse function.

<?php

$log->parse();

Analysing

An analysis is performed by an Analyser on an AnalysableLog and returns an Analysis object containing various Insight objects, e.g. a Problem or an Information object. Different log types can use different analysers by overwriting the AnalysableLogInterface::getDefaultAnalyser() function or by passing an analyser object to the analyse function.

<?php

$analysis = $log->analyse();

Printing

The entire Log or just an Entry can be printed through a Printer. The basic DefaultPrinter only prints the plain content line by line. The ModifiableDefaultPrinter allows Modification, e.g. to highlight certain characters/words.

<?php

$printer = new \Aternos\Codex\Printer\DefaultPrinter();
$printer->setLog($log);
$printer->print();

$printer = new \Aternos\Codex\Printer\DefaultPrinter();
$printer->setEntry($entry);
$printer->print();

$printer = new \Aternos\Codex\Printer\ModifiableDefaultPrinter();
$printer->setLog($log);
$modification = new \Aternos\Codex\Printer\PatternModification();
$modification->setPattern('/foo/');
$modification->setReplacement('bar');
$printer->addModification($modification);
$printer->print();

aternos/codex 适用场景与选型建议

aternos/codex 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 71.22k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2019 年 02 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 aternos/codex 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 11
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-15