csun-metalab/laravel-multiple-logs 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

csun-metalab/laravel-multiple-logs

Composer 安装命令:

composer require csun-metalab/laravel-multiple-logs

包简介

Composer package for Laravel 5 that adds a few additional log files as well as facades to write to them.

README 文档

README

Composer package for Laravel 5 that adds a few additional log files as well as facades to write to them.

Writing to laravel.log is fairly easy but sometimes it is a bit cumbersome to write to additional logs.

Table of Contents

Installation

To install from Composer, use the following command:

composer require csun-metalab/laravel-multiple-logs

Now, add the following optional line(s) to your .env file:

# Number of days for which the "daily" logs should be kept; default is 7
LOG_MAX_DAYS=7

Next, add the service provider to your providers array in Laravel as follows:

'providers' => [
   //...

   CSUNMetaLab\MultipleLogs\Providers\LoggingServiceProvider::class,

   // You can also use the following depending on Laravel convention:
   // 'CSUNMetaLab\MultipleLogs\Providers\LoggingServiceProvider',

   //...
],

Add the two facades for the new loggers to your aliases array in Laravel as follows:

'aliases' => [
    //...

    'AuditLog' => CSUNMetaLab\MultipleLogs\Facades\AuditLog::class,
    'AuthLog' => CSUNMetaLab\MultipleLogs\Facades\AuthLog::class,

    // You can also use the following depending on Laravel convention:
    //'AuditLog' => 'CSUNMetaLab\MultipleLogs\Facades\AuditLog',
    //'AuthLog' => 'CSUNMetaLab\MultipleLogs\Facades\AuthLog',

    //...
],

Finally, run the following Artisan command to publish the configuration:

php artisan vendor:publish

Facades

The two facades you added to your config/app.php file are the following:

AuditLog

This writes to a file called audit.log in your storage/logs directory.

This supports all of the same methods the native Log facade does.

The matching auditLogger() helper method also supports them as instance methods.

AuthLog

This writes to a file called auth.log in your storage/logs directory.

This supports all of the same methods the native Log facade does.

The matching authLogger() helper method also supports them as instance methods.

Usage Examples

Writing INFO Data

AuditLog::info("User performed some action");
AuthLog::info("User authenticated successfully");

auditLogger()->info("User performed some action");
authLogger()->info("User authenticated successfully");

Writing ERROR Data

AuditLog::error("User tried to perform an action unsuccessfully");
AuthLog::error("User could not authenticate");

auditLogger()->error("User tried to perform an action unsuccessfully");
authLogger()->error("User could not authenticate");

Creating Custom File Loggers

You can create your own custom file loggers by extending the Logger class:

<?php
namespace App\Logging;
use CSUNMetaLab\MultipleLogs\Loggers\Logger;

class PurchaseLogger extends Logger
{
	/**
	 * Constructs a new PurchaseLogger object.
	 *
	 * @param string $path The path to the log file
	 * @param string $logLevel Optional parameter to specify minimum log level
	 */
	public function __construct($path, $logLevel="debug") {
		parent::__construct($path, 'purchase', $logLevel);
	}
}
?>

Now, you can just construct it and immediately use the methods, for example:

<?php
use App\Logging\PurchaseLogger;
$pLogger = new PurchaseLogger(storage_path('logs/purchases.log'));

$pLogger->info("Successfully made a purchase");
?>

It is now significantly easier to add multiple log files and additional logging capabilities in Laravel.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固