noflash/shout 问题修复 & 功能扩展

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

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

noflash/shout

Composer 安装命令:

composer require noflash/shout

包简介

Simple yet powerful logging library with rotation support.

README 文档

README

The code should still work. However, this project is no longer maintained. Use Symfony Logger or Monolog instead.

Shout! Build Status

Small, fast and PSR-3 compliant logging library. Yes, it was created to blame you for every failure (which may not even be yours).

Features

  • Logging to any files/streams (including php://stdout)
  • Customizable line format
  • RFC 5424 & user defined log levels
  • Limiting logging to maximum level

Requirements

Installation

Using composer

Composer is recommended method of installation due to it's simplicity and automatic dependencies management.

  1. You need composer of course - installation takes less than a minute
  2. Run php composer.phar require noflash/shout in your favourite terminal to install Shout with dependencies
  3. Include vendor/autoload.php in your application source code

Manual

Details will be available soon.
Basically you need to download PSR-3 interfaces, put them in directory (eg. vendor) and include all files (or use PSR-4 compliant autoloader).

Usage

Most of the time you will use Shout with other libraries requiring PSR-3 logger. Configuring logger to use with other project isn't different than using it in your own project. Basic usage requires few lines:

<?php
require_once("vendor/autoload.php");

use noFlash\Shout\Shout;
$logger = new Shout();
$logger->info("Hello world");

This example (also found in examples directory as BasicUsage.php) will print <01.01.2015 13:22:46> [INFO] Hello world! with trailing new line (\n) to stdout.
For more examples you should check various examples - they're well commented.

Available methods:

  • emergency/alert/...(message, context) - Every log level have method named after it. So if you want to log "warning" just use Shout->warning("Be warned!"). Second argument can be array with any informations possible to represent as string by (formatted by print_r()).
  • log(level, message, context) - It have the same effect as methods described below, so calling Shout->log("warning", "Be warned!") produces the same result as example above.
  • rotate() - Performs manual log rotation. By default it also resets rotation timer, to prevent it pass false as first argument.
  • flush() - Tries to send remaining buffer in non-blocking mode. It will return true if buffer was written completely.

Configuration

Shout comes preconfigured by default, but allows to configure almost anything. List below specifies configuration methods along with default values (specified in brackets).

  • setDestination(php://stdout) - Specifies log destination, you can use any valid file path or stream location supports writing. You can also use %1$s for current unix timestamp or %2$s for current date (formatted according to datetimeFormat). Destination can also be specified using first argument passed to Shout class constructor.
  • setWriteMode(Shout::FILE_APPEND) - Opening new file Shout can either append to it (Shout::FILE_APPEND) or truncate and write from beginning (Shout::FILE_OVERWRITE). This method accepts any valid fopen() mode which allows writting. Using this method will re-open file. You can also pass mode as second constructor argument.
  • setBlocking(true) - Log destination can be opened either in blocking or non-blocking mode. Blocking mode is mostly faster, but sometimes can lock whole app until full log message is written. Using non-blocking mode have another drawback - after sending log message to Shout it's internally buffered and than pushed to destination, if only part of buffer can be written next attempt will be made on next message or after calling Shout->flush().
  • setRotate(false) - Disable/enable automatic log rotation (based on RotateInterval). Log rotation can be used even with destination without modifiers (but it only makes sense if WriteMode is set to Shout::FILE_OVERWRITE), but it's designed to be used destination set to eg. /var/log/awesome_app_%d.log
  • setRotateInterval(86400) - Defines how often, in seconds, rotation occurs. Be aware that Shout doesn't fire rotation unless new message is passed, so if you start logging at 00:00:00, set rotation to 1 hour, send first message at 00:59:59 and next at 03:00:05 log will rotate at 03:00:05 - no empty files will be created.
  • setLineFormat(<%1$s> [%2$s] %3$s [%4$s] [%5$s]\n) - How line should be formated. You can use 6 modifiers:
    • %1$s - date
    • %2$s - log level (uppercased)
    • %3$s - message text
    • %4$s - context (formatted by print_r())
    • %5$s - unix timestamp
  • setDatetimeFormat(d.m.Y H:i:s) - It accepts any date() compliant format.
  • setMaximumLogLevel(999) - Every log level contains it's numeric value (default ones are defined by Table 2. Syslog Message Severities of RFC 5424). This method allows to specify maximum log level delivered to destination, eg. if you set it to 1 only ALERT and EMERGENCY message will pass.
  • setLevelPriority(level, value) - In fact PSR-3 states custom log levels are forbidden, but I Shout supports them. By default messages with custom level don't have priority (so they're ignore MaximumLogLevel). This method allows setting priority (and even change builtin levels priority, which is NOT recommended).

noflash/shout 适用场景与选型建议

noflash/shout 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 275 次下载、GitHub Stars 达 6, 最近一次更新时间为 2015 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「log」 「logging」 「logger」 「rotate」 「psr-3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 noflash/shout 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 noflash/shout 我们能提供哪些服务?
定制开发 / 二次开发

基于 noflash/shout 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 275
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 23
  • 依赖项目数: 1
  • 推荐数: 2

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-08