centagon/papertrail 问题修复 & 功能扩展

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

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

centagon/papertrail

最新稳定版本:9.1.0

Composer 安装命令:

composer require centagon/papertrail

包简介

Integrate Papertrail log monitor in your PHP applications

README 文档

README

Build Status

Easily integrate Papertrail log monitor in your PHP applications. This package provides integration for plain vanilla PHP and Laravel.

Installation

composer require centagon/papertrail

Configuration

It is good practice not to include credentials in your code so passwords are not stored in version control. Keeping sensitive info in your code could become an issue when you need to open source or share your code with other developers. For this reason, this package will get your papertrail log server details from environment variables PAPERTRAIL_HOST, PAPERTRAIL_PORT and PAPERTRAIL_HOSTNAME by default.

This package ships with 2 drivers:

  • Php for plain PHP applications
  • Laravel for Laravel applications from version 4.2 to 5.6

Plain Vanilla PHP

For plain PHP applications, we recommend also installing Monolog:

composer require monolog/monolog

then integrate the papertrail package like so:

require __DIR__ . '/vendor/autoload.php';

use StephaneCoinon\Papertrail\Php as Papertrail;

// Boot using default settings (ie Papertrail log server and port
// from environment variables and no log message prefix).
// It also gives you a monolog instance in the process.
$logger = Papertrail::boot();

// Now your logs will appear in Papertrail dashboard.
$logger->info('test log');

Laravel 4

Add these lines in your start/global.php:

// Pass all parameters
\StephaneCoinon\Papertrail\Laravel::boot($host, $port, $prefix);

or

// Grab log server details from environment variables and use a prefix
\StephaneCoinon\Papertrail\Laravel::bootWithPrefix('MY_APP');

Laravel 5

Edit app/Providers/AppServiceProvider.php and add this line in boot method:

\StephaneCoinon\Papertrail\Laravel::boot();

then test it's working:

// routes/web.php

Route::get('log', function () {
    Log::info('test log', ['foo' => 'bar']);

    return 'Logged';
});

API reference

All drivers provide the following interface:

/**
 * Boot connector with given host, port and log message prefix.
 * 
 * If host or port are omitted, we'll try to get them from the environment
 * variables PAPERTRAIL_HOST and PAPERTRAIL_PORT.
 * 
 * @param  string $host   Papertrail log server, ie log.papertrailapp.com
 * @param  int $port      Papertrail port number for log server
 * @param  string $prefix Prefix to use for each log message
 * @return \Psr\Log\LoggerInterface
 */
public static function boot($host = null, $port = null, $prefix = '')
/**
 * Boot connector using credentials set in environment variables and the
 * given log message prefix.
 * 
 * @param string $prefix Prefix to use for each log message
 * @return \Psr\Log\LoggerInterface
 */
public static function bootWithPrefix($prefix)

Tests

First, copy .env.dist as .env and set your Papertrail host, port and API key in it.

Then run PHPUnit:

./vendor/bin/phpunit

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固