camspiers / silverstripe-loggerbridge
Provides a bridge between PSR-3 loggers (like monolog) and SilverStripe
Installs: 61 311
Dependents: 0
Suggesters: 0
Security: 0
Stars: 13
Watchers: 4
Forks: 10
Open Issues: 7
Type:silverstripe-module
Requires
- composer/installers: ~1.0
- filp/whoops: ^2.0
- monolog/monolog: ^1.7
- silverstripe/framework: ^3.1
Requires (Dev)
- phpunit/phpunit: ~3.7
- symfony/class-loader: ~2.3
README
Provides easy usage of PSR-3
loggers (like monolog) in SilverStripe 3.x.
In SilverStripe 4.x and newer, PSR-3
support is built into the core system and this module is no longer required.
Installation (composer required)
$ composer require camspiers/silverstripe-loggerbridge:dev-master
Usage
-
Create a config file in your
mysite
, e.g. "mysite/_config/logging.yml" -
Set up a
PSR-3
logger service and add to theLoggerBridge
constructorInjector: Monolog: class: Monolog\Logger constructor: 0: App 1: - '%$StreamHandler' StreamHandler: class: Monolog\Handler\StreamHandler constructor: 0: '../../error.log' LoggerBridge: class: Camspiers\LoggerBridge\LoggerBridge constructor: 0: '%$Monolog'
Changing the way errors display in development
By default Logger Bridge uses Whoops
for the display of errors and exceptions. You can change to using SilverStripe
error display by adding the following to your yml:
Injector:
LoggerBridge:
properties:
ErrorReporter: '%$LoggerBridgeDebugErrorReporter'
Advanced-style setup
This setup provides the following:
- Logging to a Sentry server, through a raven client (
composer require raven/raven
)- Uses one Sentry project for
live
and one Sentry project fortest
anddev
- Uses one Sentry project for
- Logging to a file for error levels
error
and above - Logging to Chrome Logger when environment
dev
- Errors are displayed in the Chrome console instead of displaying in the webpage
- Logging to FirePHP when environment
dev
- Errors are displayed in the Firebug console instead of displaying in the webpage
- Logging of peak memory usage along with error
--- Except: environment: live --- Injector: Raven: class: Raven_Client constructor: 0: http://someraven.url/1 Monolog: class: Monolog\Logger constructor: 0: App 1: - '%$RavenHandler' - '%$StreamHandler' - '%$ChromePHPHandler' - '%$FirePHPHandler' 2: - '%$MemoryPeakUsageProcessor' --- Only: environment: live --- Injector: Raven: class: Raven_Client constructor: 0: http://someraven.url/1 Monolog: class: Monolog\Logger constructor: 0: App 1: - '%$RavenHandler' - '%$StreamHandler' 2: - '%$MemoryPeakUsageProcessor' --- Name: logging --- Injector: LoggerBridge: class: Camspiers\LoggerBridge\LoggerBridge constructor: 0: '%$Monolog' 1: false RavenHandler: class: Monolog\Handler\RavenHandler constructor: 0: '%$Raven' StreamHandler: class: Monolog\Handler\StreamHandler constructor: 0: '../../error.log' 1: 400 ChromePHPHandler: class: Monolog\Handler\ChromePHPHandler FirePHPHandler: class: Monolog\Handler\FirePHPHandler MemoryPeakUsageProcessor: class: Monolog\Processor\MemoryPeakUsageProcessor
Attaching the logger as early as possible
SilverStripe currently doesn't provide any way to replace the default Debug
error handlers prior to the
database connection etc. But the following patch will use the Logger Bridge as early as possible.
To apply the patch, run the following from the framework
directory of a 3.1.x-dev
install.
patch -p1 < framework.patch
framework.patch
diff --git a/core/Core.php b/core/Core.php index bc3f583..4c9f59e 100644 --- a/core/Core.php +++ b/core/Core.php @@ -131,7 +131,7 @@ if(Director::isLive()) { /** * Load error handlers */ -Debug::loadErrorHandlers(); +Injector::inst()->get('LoggerBridge')->registerGlobalHandlers(); ///////////////////////////////////////////////////////////////////////////////
Unit testing
Logger Bridge has good unit test converage. To run the unit tests:
$ composer install --dev --prefer-dist
$ phpunit
##License
SilverStripe Logger Bridge is released under the MIT license