forked from mrhanlon/log_stdout
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f1d01ba
Showing
3 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Drupal Watchdog stdout | ||
|
||
Log [Drupal Watchdog][1] messages to `php://stdout` or `php://stderr` for better log handling with Docker. | ||
|
||
[1]: https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/watchdog/7 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name = log_stdout | ||
description = Log watchdog messages to stdout | ||
package = Logging | ||
version = VERSION | ||
core = 7.x |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
function log_stdout_watchdog(array $log_entry) { | ||
if ($log_entry['severity'] < WATCHDOG_WARNING) { | ||
$output = fopen('php://stderr', 'w'); | ||
} else { | ||
$output = fopen('php://stdout', 'w'); | ||
} | ||
$severity = strtoupper(watchdog_severity_levels()[$log_entry['severity']]); | ||
$user = $log_entry['user']->name; | ||
$request_uri = $log_entry['request_uri']; | ||
$referer_uri = $log_entry['referer']; | ||
fwrite($output, t('@severity: @message; user: @user; uri: @request_uri; referer: @referer_uri', array( | ||
'@severity' => $severity, | ||
'@message' => strip_tags(t($log_entry['message'], $log_entry['variables'])), | ||
'@user' => $user, | ||
'@request_uri' => $request_uri, | ||
'@referer_uri' => $referer_uri, | ||
))); | ||
fclose($output); | ||
} |