承接 tintonic/php-elog 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tintonic/php-elog

最新稳定版本:v1.0.4

Composer 安装命令:

composer require tintonic/php-elog

包简介

Simple PHP class for enhanced error logging

README 文档

README

Simple PHP solution for enhanced logging.

Installation

composer require tintonic/php-elog

Usage

Simple usage – create instance and log via helpers

This example creates an Elog instance that will log to a file named elog.log in the same directory as executing script (__DIR__). The helper function elog() logs to the instance of Elog that was first created.

create_elog();

/*
Logs to the first instance that was created.
Logs to "__DIR__/elog.log"
*/
elog("I am elog.log");

Logging different data types

  • null is presented as [null]
  • empty string is presented as [empty string]
  • true is presented as [true]
  • false is presented as [false]
  • object and array is described using print_r()
create_elog();

elog(null);  // [null]

elog('');    // [empty string]

elog(true);  // [true]

elog(false); // [false]


elog((object) [
    'id' => 123,
    'foo' => 'bar'
]);

/*
stdClass Object
(
    [id] => 123
    [foo] => bar
)
*/


elog([
    'id' => 123,
    'foo' => 'bar'
]);

/*
Array
(
    [id] => 123
    [foo] => bar
)
*/

Include label and / or data type

elog(123, 'Current value', true);

/*
--- Current value {integer} ---
123
*/

Named instances

This example creates two named Elog instances – one that logs to _DIR__/first.log and another that logs to /path/to/log/second_log_file (without file extension).

create_elog(__DIR__, 'first');
create_elog('/path/to/log', 'second', 'second_log_file', null);

// Log to named instances using elogn().
elogn('first', "I am first.log");         //  ———>  __DIR__/first.log
elogn('second', "I am second_log_file");  //  ———>  /path/to/log/second_log_file

Using the Elog class

Of course you may use the Elog class directly.

This example also demonstrates how you can configure a default value for $include_type to always include the data type in the output.

use Tintonic/PhpElog/Elog;

/*
Create an instance named "notes" that logs to "/path/to/log/elog.txt" with data type by default.
*/
$logger = new Elog('/path/to/log', 'notes', 'elog', 'txt');
$logger->set_default_include_type(true);

/*
Log to named instance somewhere else in the application.
*/
Elog::logn('notes', 123);

/*
{integer} 
123
*/


Elog::logn('notes' 'bar', 'Foo?');

/*
--- Foo? {string} ---
bar
*/

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-21