mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-08 06:06:40 +02:00
Merge pull request #585 from daniel-adlantic/master
Add support for Javascript output in BrowserConsoleHandler
This commit is contained in:
@@ -55,15 +55,19 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert records to javascript console commands and send it to the browser.
|
* Convert records to javascript console commands and send it to the browser.
|
||||||
* This method is automatically called on PHP shutdown if output is HTML.
|
* This method is automatically called on PHP shutdown if output is HTML or Javascript.
|
||||||
*/
|
*/
|
||||||
public static function send()
|
public static function send()
|
||||||
{
|
{
|
||||||
|
$htmlTags = true;
|
||||||
// Check content type
|
// Check content type
|
||||||
foreach (headers_list() as $header) {
|
foreach (headers_list() as $header) {
|
||||||
if (stripos($header, 'content-type:') === 0) {
|
if (stripos($header, 'content-type:') === 0) {
|
||||||
if (stripos($header, 'text/html') === false) {
|
// This handler only works with HTML and javascript outputs
|
||||||
// This handler only works with HTML outputs
|
// text/javascript is obsolete in favour of application/javascript, but still used
|
||||||
|
if (stripos($header, 'application/javascript') !== false || stripos($header, 'text/javascript') !== false) {
|
||||||
|
$htmlTags = false;
|
||||||
|
} elseif (stripos($header, 'text/html') === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -71,7 +75,11 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count(self::$records)) {
|
if (count(self::$records)) {
|
||||||
echo '<script>' , self::generateScript() , '</script>';
|
if ($htmlTags) {
|
||||||
|
echo '<script>' , self::generateScript() , '</script>';
|
||||||
|
} else {
|
||||||
|
echo self::generateScript();
|
||||||
|
}
|
||||||
self::reset();
|
self::reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user