Last active
April 18, 2017 05:49
-
-
Save sminnee/a99ff6888fc0e5a60095fe701a884a4f to your computer and use it in GitHub Desktop.
logging queries to php-console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/composer.json b/composer.json | |
| index 05214e4..6cb25d8 100644 | |
| --- a/composer.json | |
| +++ b/composer.json | |
| @@ -14,7 +14,13 @@ | |
| "silverstripe/reports": "4.0.x-dev", | |
| "silverstripe/siteconfig": "4.0.x-dev", | |
| "silverstripe/versioned": "1.0.x-dev", | |
| - "silverstripe-themes/simple": "~3.2.0" | |
| + "silverstripe-themes/simple": "~3.2.0", | |
| + "php-console/php-console": "^3.1" | |
| }, | |
| "require-dev": { | |
| "phpunit/PHPUnit": "^5.7" | |
| diff --git a/mysite/_config/config.yml b/mysite/_config/config.yml | |
| index 313e68b..67d9375 100644 | |
| --- a/mysite/_config/config.yml | |
| +++ b/mysite/_config/config.yml | |
| @@ -8,3 +8,53 @@ SilverStripe\View\SSViewer: | |
| themes: | |
| - 'simple' | |
| - '$default' | |
| +--- | |
| +Name: logging-php-console | |
| +Only: | |
| + environment: dev | |
| +--- | |
| +SilverStripe\Core\Injector\Injector: | |
| + Psr\Log\LoggerInterface: | |
| + calls: | |
| + PHPConsoleHandler: [ pushHandler, [ %$Monolog\Handler\PHPConsoleHandler ] ] | |
| + | |
| + DisplayErrorHandler: | |
| + class: SilverStripe\Logging\HTTPOutputHandler | |
| + constructor: | |
| + - "error" | |
| + properties: | |
| + Formatter: %$FriendlyErrorFormatter | |
| + FriendlyErrorFormatter: | |
| + class: SilverStripe\Logging\DebugViewFriendlyErrorFormatter | |
| + properties: | |
| + Title: "There has been an error" | |
| + Body: "Please see Chromes' PHP-Console for more details" | |
| diff --git a/mysite/code/Page.php b/mysite/code/Page.php | |
| diff --git a/src/Dev/Debug.php b/src/Dev/Debug.php | |
| index 06d7ec9..38f1947 100644 | |
| --- a/src/Dev/Debug.php | |
| +++ b/src/Dev/Debug.php | |
| @@ -8,6 +8,8 @@ use SilverStripe\Core\Injector\Injector; | |
| use SilverStripe\ORM\DB; | |
| use SilverStripe\Security\Permission; | |
| use SilverStripe\Security\Security; | |
| +use Psr\Log\LoggerInterface; | |
| + | |
| /** | |
| * Supports debugging and core error handling. | |
| @@ -161,20 +163,7 @@ class Debug | |
| public static function message($message, $showHeader = true) | |
| { | |
| if (!Director::isLive()) { | |
| - $caller = Debug::caller(); | |
| - $file = basename($caller['file']); | |
| - if (Director::is_cli()) { | |
| - if ($showHeader) { | |
| - echo "Debug (line $caller[line] of $file):\n "; | |
| - } | |
| - echo $message . "\n"; | |
| - } else { | |
| - echo "<p class=\"message warning\">\n"; | |
| - if ($showHeader) { | |
| - echo "<b>Debug (line $caller[line] of $file):</b>\n "; | |
| - } | |
| - echo Convert::raw2xml($message) . "</p>\n"; | |
| - } | |
| + Injector::inst()->get(LoggerInterface::class)->debug($message); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment