Currently the Syslog module only logs to a local syslog server, while its possible to tell the local syslog server to forward the logs to a remote server this is double handling. It'd be great if Drupal could connect directly to the remote server to send logs.

Issue fork drupal-1252820

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mdupont’s picture

Status: Active » Closed (won't fix)

Nope. This is the exact contrary to double handling: the local syslog daemon is responsible for handling the log, either keeping it local or sending it to a remote server.

The sysadmin has then only the syslog daemon to configure and doesn't have to go through application x or y (Drupal or whatever else) he might not know.

Moreover, the syslog server has built-in support to send logs to a remote server (UDP port 514), so why duplicate the code and bloat Drupal to implement the same feature instead of using what's already there?

kim.pepper’s picture

Issue summary: View changes
Status: Closed (won't fix) » Active

We are interested in adding this functionality.

I think this issue was created before the introduction of Docker containers. It's best practice to have a container only run one process. Therefore having a syslog daemon in your PHP container is not recommended.

If Drupal syslog module could send directly to udp then we could have a nice decoupling of syslog and php processes.

kim.pepper’s picture

Version: 8.0.x-dev » 9.0.x-dev
Status: Active » Needs review
StatusFileSize
new3.26 KB

Something like this might be enough.

andypost’s picture

I think it's wrong to bet on UDP only, there's set of rfc which defines - tls, snmp and tcp for syslog

Also UDP allows data loss and limits on message size... So not sure it usable in long run

For docker/k8s I used rsyslog (and surely monolog) but IMO better move to binary logs (less data loss)

bgilhome’s picture

StatusFileSize
new3.69 KB
new1.85 KB

The patch in #3 just needs a fix for an overwritten form key, and to set the config values on submit. Patch attached, seems to be working fine logging to a rsyslog Docker container. NB for some reason if the format doesn't start with '!base_url' then I don't see any other variables populated except for message, perhaps a separate issue.

xjm’s picture

Version: 9.0.x-dev » 9.1.x-dev
dagmar’s picture

Status: Needs review » Needs work

There is only a few `if`s in the syslog module. I think we should keep this number as low as possible. If this new approach to send information to syslog is going to be checked every time a log entry is created we will see a minor but considerable performance penalization in busy sites.

In my opinion we should try to find a way to swap the service if the host is present, and do not ask this value every time the logger is invoked.

andypost’s picture

Additionally to #7 - creating socket requires context switch and probably syscall
Also it needs "try/catch/finally" because sockets could leak and it could lead to ddos

+++ b/core/modules/syslog/src/Logger/SysLog.php
@@ -95,7 +95,27 @@ public function log($level, $message, array $context = []) {
+  protected function sendUdp($level, $entry) {
+    $hostname = $this->config->get("hostname");
+    $port = $this->config->get("port") ?? 514;
+    $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

Better to create socket only once on first need, then close it in destructor

The presence of host/port in config could be checked in contructor (also once)

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

O'Briat made their first commit to this issue’s fork.

o'briat’s picture

I fixed the missing facility & identity. I also move all "config-get" to constructor (I just need this patch for my local docker stack).
Try catch is still missing.

#7 / @dagmar: if you could provide an example, I'll try to improve the MR

ravi.shankar made their first commit to this issue’s fork.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.