rawphp/raw-log

RawLog 是 Monolog 的包装器,由 RawPHP 框架和其他应用程序使用。

dev-master / 0.x-dev 2014-12-16 09:52 UTC

This package is auto-updated.

Last update: 2024-09-20 08:25:57 UTC


README

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

SensioLabsInsight

包功能

  • 支持将日志记录到单个文件或每日轮换的文件中
  • 支持发送电子邮件(可选 SMTP)

安装

Composer

RawLog 通过 Composer/Packagist 提供。

"rawphp/raw-log": "0.*@dev" 添加到 composer.json 中的 require 块,然后运行 composer install

{
        "require": {
            "rawphp/raw-log": "0.*@dev"
        }
}

您也可以直接从命令行运行以下命令

composer require rawphp/raw-log "0.*@dev"

存档文件

或者,只需将 RawLog 文件夹的内容复制到 PHP 的 include_path 设置中。如果您不熟悉 git 或只想获取存档文件,请点击 GitHub 页面顶部的 'zip' 按钮。

基本用法

<?php

use RawPHP\RawLog\Log;

// configuration
// email settings obviously not required if not using MailHandler

$config = array(
    
    class => 'RawPHP\\RawLog\\Log',
    debug =>  FALSE,
    $handlers = array(
        'standard_log' = array( 
            class     => 'RawPHP\\RawLog\\Handlers\\FileHandler',
            file      => '/path/to/log.txt',
            formatter => 'RawPHP\\RawLog\\Formatters\\ErrorLogFormatter',
            level     => 0, // debug
        ),
        rotate_log = array(
            class     => 'RawPHP\\RawLog\\Handlers\\RotatingFileHandler',
            file      => '/path/to/rotate.txt',
            formatter => 'RawPHP\\RawLog\\Formatters\\ErrorLogFormatter',
            level     => 2, // notice
        ),
        mail = array( 
            class     => 'RawPHP\\RawLog\\Handlers\\MailHandler',
            formatter => 'RawPHP\\RawLog\\Formatters\\MailLogFormatter',
            level     => 4, // error
        ),
    ),

    'from_email'  => 'no-reply@rawphp.org',              // default from email to use in log emails
    'from_name'   => 'RawPHP',                           // default from name to use in log emails
    'to_address'  => 'test@example.com',                 // default email address to use in log emails
    'to_name'     => 'RawPHP',                           // default name 
    'subject'     => 'RawPHP Error Log Message',         // log email subject line

    'smtp' => array( 'auth'      => TRUE ),              // enable SMTP authentication
    'smtp' => array( 'host'      => 'smtp.gmail.com' ),  // main and backup SMTP servers
    'smtp' => array( 'username'  => 'username' ),        // SMTP username
    'smtp' => array( 'password'  => 'password' ),        // SMTP password
    'smtp' => array( 'security'  => 'ssl' ),             // Enable TLS encryption, 'ssl' also accepted
    'smtp' => array( 'port'      => '465' ),             // SMTP port
);

// get new instance
$log = new Log( $config );

// use cases
$log->debug( 'message' );
$log->info( 'message' );
$log->notice( 'message' );
$log->warning( 'message' );
$log->error( 'message' );
$log->critical( 'message' );
$log->alert( 'message' );
$log->emergency( 'message' );

许可协议

本软件包遵循 MIT 许可协议。阅读 LICENSE 了解有关软件可用性和分发的信息。

贡献

请将错误报告、建议和拉取请求提交到 GitHub 问题跟踪器

变更日志

01-10-2014

  • 移除了对 Monolog 的依赖。
  • 从头开始重建日志 - 受 Monolog 功能的启发

22-09-2014

  • 更新到 PHP 5.3。

20-09-2014

  • 用 yaml 替换了 php 数组配置

18-09-2014

  • 更新以支持最新的 rawphp/rawbase 包。

14-09-2014

  • 首次代码提交