定制 lfphp/logger 二次开发

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

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

lfphp/logger

Composer 安装命令:

composer require lfphp/logger

包简介

A lite logger for PHP. make log easier to use.

README 文档

README

The current library is tested based on PHP5.6 and above.

Install

composer require lfphp/logger

Using

The library provides Logger methods for simple log collection. External callers register event handlers through the registration method Logger::register. Internal objects can use the object method $logger->register to register event handling

example:

Business code: business.php

<?php
use LFPhp\Logger\Logger;

//Business start ...
class MyClass {
private $logger;
	public function __construct(){
$this->logger = Logger::instance(__CLASS__);

//Register specific log object event processing
$this->logger->register(function($messages){
echo "Log from internal";
var_dump($messages);
echo PHP_EOL;
});

$this->logger->debug('class construct.'); //Logging in the object
	}

	public function foo() {
		$msg = "I'm calling foo()";
		$this->logger->info($msg); //Logging in the object
		return $msg;
	}

	public function castError(){
		$this->logger->warning('warning, error happens'); //Logging in the object
	}

	public function __destruct(){
		$this->logger->warning('class destruct.'); //Logging in the object
	}
}

//Global logging
Logger::debug('Global logging start...');

$obj = new MyClass();
Logger::info('Object created', $obj);

$obj->foo();
$obj->castError();
unset($obj);

//Global logging
Logger::warning('Object destructed');

Business call, log monitoring code: test.php

<?php
use LFPhp\Logger\LoggerLevel;
use LFPhp\Logger\Output\ConsoleOutput;
use LFPhp\Logger\Output\FileOutput;
use LFPhp\Logger\Logger;
use LFPhp\Logger\test\MyClass;

require_once "autoload.php";

//Print all log information to the console (screen)
Logger::registerGlobal(new ConsoleOutput, LoggerLevel::DEBUG);

//Record information with a level greater than or equal to INFO to the file
Logger::registerGlobal(new FileOutput(__DIR__.'/log/Lite.debug.log'), LoggerLevel::INFO);

//Record all log information of the registration ID Curl::class (generally the class name is used as the registration ID) to the file
Logger::registerGlobal(new FileOutput(__DIR__.'/log/Lite.curl.log'), LoggerLevel::DEBUG, MyClass::class);

//Only when a WARNING level log event occurs, log all information with a level greater than or equal to INFO to the file
Logger::registerWhileGlobal(LoggerLevel::WARNING, new FileOutput(__DIR__.'/log/Lite.error.log'), LoggerLevel::INFO);

//Process the information yourself
Logger::registerGlobal(function($messages, $level){
	var_dump($messages);
	//Execute processing logic
}, LoggerLevel::INFO);

//Start normal business
require_once "business.php";

统计信息

  • 总下载量: 669
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 2
  • 依赖项目数: 9
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固