GithubHelp home page GithubHelp logo

easy-logger's Introduction

简介

基于monolog/monolog简单封装的日志扩展包。

Build Status codecov Latest Stable Version Latest Unstable Version Total Downloads License

功能

  • 支持多种策略进行日志记录
  • 支持自定义扩展日志记录通道
  • 可自定义日志配置行为,无配置的情况下,日志写入到系统临时目录下

安装

通过composer引入扩展包

composer require f-oris/easy-logger:^1.1

配置

参考config.example.php文件

基本用法

1. 写入日志

<?php

use Foris\Easy\Logger\Logger;

$config = [
    // ...
];
$logger = new Logger($config);

/**
 * 写入日志信息
 * 
 * 可以使用不同的方法写入不同级别的日志信息
 * 下面两种写法等价
 */
$logger->debug('调试日志', ['context' => 'context']);
$logger->log('debug', '调试日志', ['context' => 'context']);

/**
 * 日志信息信息写入指定通道 
 */
$logger->channel('channel')->debug('日志信息写入channel通道', ['context' => 'context']);

2. 扩展自定义Logger driver

<?php

// 扩展的driver需要实现Psr\Log\LoggerInterface接口规范

$callback = function ($channel) {
    $logger = new \Monolog\Logger($channel);
    return $logger->pushHandler(new \Monolog\Handler\TestHandler());
};

$factory = new \Foris\Easy\Logger\Driver\Factory();
$factory->extend($callback, 'test_driver');

$config = [
    // ...
    
    "channels" => [
        // ...
        
        "test" => [
            "driver" => "test_driver",    
        ]    
    ]
];

$logger = new \Foris\Easy\Logger\Logger($factory, $config);
$logger->channel('test')->debug('This is a debug message');

License

MIT License

Copyright (c) 2019-present F.oris [email protected]

easy-logger's People

Contributors

itsanr-oris avatar

Stargazers

Pitozoo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.