llagerlof/mylogphp
Composer 安装命令:
composer require llagerlof/mylogphp
包简介
MyLogPHP is a single PHP class to easily keep log files in CSV format.
README 文档
README
MyLogPHP is a single PHP class to easily keep log files in CSV format.
Install the latest version
Direct download (just include this file in your script)
MyLogPHP.class.php (1.2.19)Or you can use Composer
Edit your project's **composer.json** and add the required package: **"llagerlof/mylogphp": "dev-master"**Eg:
{
"name": "your/project",
"require": {
"llagerlof/mylogphp": "dev-master"
}
}
How to read the generated log file
Any CSV reader can be used to open the generated logs, but If you need a recomendation, try the CSVFileView or LogExpert. Both can parse/show the CSV columns and watch realtime changes in log file (like tail on Linux).Features
- One single file to rule them all!
- Super easy start.
- Two extra columns are automatically added in the CSV: the number of execution line and the path of host script where the log was called.
- Minimum PHP version: 5.3
Want more features? I am listening!
Create an issue in https://github.com/llagerlof/MyLogPHP/issues/new
Quick start
Include in your script the file "MyLogPHP.class.php" (not needed if you are using the composer version).
include('MyLogPHP.class.php');
Instantiate the object. Optionally you can pass the log file name and the separator as a parameter. Default log file name is "_MyLogPHP-1.2.log.csv" in current folder, and default separator is comma (,).
$log = new MyLogPHP\MyLogPHP('./log/debug.log.csv');
Make sure the directory where the log will be created is writable.
Call method "info", "warning", "error" or "debug" to write the messages.
The first parameter is the message, the optional second parameter is a free tag at your choice to help you filter the log when opened by an spreadsheet software, like OpenOffice Calc or Microsoft Excel.
$log->info('This message will be logged in the file debug.log.csv','TIP');
That's it!
Examples
$log = new MyLogPHP\MyLogPHP(); $log->info('The program starts here.'); $log->warning('This problem can affect the program logic'); $log->warning('Use this software at your own risk!'); $log->info('Lawrence Lagerlof','AUTHOR'); $log->info('Asimov rulez','FACT'); $log->error('Everything crash and burn','IE'); $log->debug("select * from table",'DB');
Writing a variable content to file "_OUT_MyLogPHP.txt"
\MyLogPHP\MyLogPHP::out($data);
\MyLogPHP\MyLogPHP::out($data, array('LABEL' => 'variable $data');
\MyLogPHP\MyLogPHP::out($data, 'variable $data'); // same as above
\MyLogPHP\MyLogPHP::out($data, array('LABEL' => 'variable $data', 'WRITE_MODE' => MyLogPHP::OVERWRITE));
\MyLogPHP\MyLogPHP::out($data, array('LABEL' => 'variable $data', 'WRITE_MODE' => MyLogPHP::APPEND)); // WRITE_MODE can be OVERWRITE or APPEND (APPEND is default)
Changelog
1.2.19
- Read the configuration file only once per instance.
1.2.18
- Namespace added.
1.2.17
- Fixed a debug_backtrace problem when used in Laravel application.
1.2.16
- Put an optional config file (MyLogPHP.conf in the same directory of the class) with one line containing "enabled=false" to disable logging.
1.2.15
- Changed output format of out() method.
1.2.14
- Added method name to output of the out() method.
1.2.13
- Added the file and execution line info to output of the out() method.
1.2.12
- You can define a $_SESSION variable to set where the file will be created by the out() method.
1.2.11
- out() method is now static.
1.2.10
- Can pass a string to act as LABEL to the second parameter of out() method.
1.2.9
- Removed supressed warnings from variable $headers and date() functions.
1.2.8
- Add more options and verbosity to out() method.
1.2.7
- New method out() allow append a variable value to the end of the file _OUT_MyLogPHP.txt
1.2.6
- Class updated for PHP 7 (thanks @clintre).
1.2.5
- Solved a bug that was preventing the replacement of consecutives spaces and tabs for one space.
1.2.4
- All consecutives spaces and tabs are removed from output.
1.2.3
- PHPDOC comment style applied to the class.
- An issue with the newer version of PHP and the date() function was solved.
1.2.2
- Line breaks of VALUE field are converted to spaces to prevent some CSV readers wrongly interpret line breaks as new CSV lines.
- The VALUE field now is trimmed before output.
1.2.1
- Disable a warning message if an internal variable is not set.
1.2
- Two columns added in CSV output: LINE and FILE.
1.1
- Added support to choose the field separator. Comma is still the default.
llagerlof/mylogphp 适用场景与选型建议
llagerlof/mylogphp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.53k 次下载、GitHub Stars 达 29, 最近一次更新时间为 2016 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「logging」 「php」 「csv」 「logger」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 llagerlof/mylogphp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 llagerlof/mylogphp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 llagerlof/mylogphp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Zend Framework module that sets up Monolog for logging in applications.
Asynchronous Sentry for Symfony - Fire and forget
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
Pacote simplificado para persistência de logs
统计信息
- 总下载量: 3.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 29
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2016-02-03