74333af
diff --git a/modules/loggers/config.m4 b/modules/loggers/config.m4
74333af
index 762e773..0848d2e 100644
74333af
--- a/modules/loggers/config.m4
74333af
+++ b/modules/loggers/config.m4
74333af
@@ -5,6 +5,8 @@ dnl APACHE_MODULE(name, helptext[, objects[, structname[, default[, config]]]])
74333af
 APACHE_MODPATH_INIT(loggers)
74333af
 	
74333af
 APACHE_MODULE(log_config, logging configuration.  You won't be able to log requests to the server without this module., , , yes)
74333af
+APR_ADDTO(MOD_LOG_CONFIG_LDADD, [$SYSTEMD_LIBS])
74333af
+
74333af
 APACHE_MODULE(log_debug, configurable debug logging, , , most)
74333af
 APACHE_MODULE(log_forensic, forensic logging)
74333af
 
74333af
diff --git a/modules/loggers/mod_log_config.c b/modules/loggers/mod_log_config.c
74333af
index 996c09c..50a056a 100644
74333af
--- a/modules/loggers/mod_log_config.c
74333af
+++ b/modules/loggers/mod_log_config.c
74333af
@@ -172,6 +172,10 @@
74333af
 #include <limits.h>
74333af
 #endif
74333af
 
74333af
+#ifdef HAVE_SYSTEMD
74333af
+#include <systemd/sd-journal.h>
74333af
+#endif
74333af
+
74333af
 #define DEFAULT_LOG_FORMAT "%h %l %u %t \"%r\" %>s %b"
74333af
 
74333af
 module AP_MODULE_DECLARE_DATA log_config_module;
74333af
@@ -1638,6 +1642,25 @@ static apr_status_t ap_default_log_writer( request_rec *r,
74333af
 
74333af
     return rv;
74333af
 }
74333af
+
74333af
+static apr_status_t wrap_journal_stream(apr_pool_t *p, apr_file_t **outfd,
74333af
+                                        int priority)
74333af
+{
74333af
+#ifdef HAVE_SYSTEMD
74333af
+    int fd;
74333af
+
74333af
+    fd = sd_journal_stream_fd("httpd", priority, 0);
74333af
+    if (fd < 0) return fd;
74333af
+
74333af
+    /* This is an AF_UNIX socket fd so is more pipe-like than
74333af
+     * file-like (the fd is neither seekable or readable), and use of
74333af
+     * apr_os_pipe_put_ex() allows cleanup registration. */
74333af
+    return apr_os_pipe_put_ex(outfd, &fd, 1, p);
74333af
+#else
74333af
+    return APR_ENOTIMPL;
74333af
+#endif
74333af
+}
74333af
+
74333af
 static void *ap_default_log_writer_init(apr_pool_t *p, server_rec *s,
74333af
                                         const char* name)
74333af
 {
74333af
@@ -1650,6 +1673,32 @@ static void *ap_default_log_writer_init(apr_pool_t *p, server_rec *s,
74333af
         }
74333af
         return ap_piped_log_write_fd(pl);
74333af
     }
74333af
+    else if (strncasecmp(name, "journald:", 9) == 0) {
74333af
+        int priority;
74333af
+        const char *err = ap_parse_log_level(name + 9, &priority);
74333af
+        apr_status_t rv;
74333af
+        apr_file_t *fd;
74333af
+
74333af
+        if (err == NULL && priority > LOG_DEBUG) {
74333af
+            err = "TRACE level debugging not supported with journald";
74333af
+        }
74333af
+
74333af
+        if (err) {
74333af
+            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EBADPATH, s, 
74333af
+                         "invalid journald log priority name %s: %s",
74333af
+                         name, err);
74333af
+            return NULL;
74333af
+        }
74333af
+
74333af
+        rv = wrap_journal_stream(p, &fd, priority);
74333af
+        if (rv) {
74333af
+            ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, 
74333af
+                         "could not open journald log stream");
74333af
+            return NULL;
74333af
+        }
74333af
+
74333af
+        return fd;
74333af
+    }
74333af
     else {
74333af
         const char *fname = ap_server_root_relative(p, name);
74333af
         apr_file_t *fd;