From c03dcf4617dff1cfcdc2f96866b967349748dde5 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sun, 28 Oct 2012 19:27:42 +0100 Subject: [PATCH] added logfile commodity plugin --- buildconf/base.ini | 2 +- plugins/logfile/logfile.c | 31 +++++++++++++++++++++++++ plugins/logfile/uwsgiplugin.py | 6 +++++ plugins/systemd_logger/systemd_logger.c | 3 ++- 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 plugins/logfile/logfile.c create mode 100644 plugins/logfile/uwsgiplugin.py diff --git a/buildconf/base.ini b/buildconf/base.ini index 5e1c5d6c..a34ed0a8 100644 --- a/buildconf/base.ini +++ b/buildconf/base.ini @@ -29,7 +29,7 @@ plugins = bin_name = uwsgi append_version = plugin_dir = . -embedded_plugins = %(main_plugin)s, ping, cache, nagios, rrdtool, carbon, rpc, corerouter, fastrouter, http, ugreen, signal, syslog, rsyslog, logsocket, router_uwsgi, router_redirect, router_basicauth, zergpool, redislog, mongodblog, router_rewrite, router_http +embedded_plugins = %(main_plugin)s, ping, cache, nagios, rrdtool, carbon, rpc, corerouter, fastrouter, http, ugreen, signal, syslog, rsyslog, logsocket, router_uwsgi, router_redirect, router_basicauth, zergpool, redislog, mongodblog, router_rewrite, router_http, logfile as_shared_library = false locking = auto diff --git a/plugins/logfile/logfile.c b/plugins/logfile/logfile.c new file mode 100644 index 00000000..0e222e24 --- /dev/null +++ b/plugins/logfile/logfile.c @@ -0,0 +1,31 @@ +#include "../../uwsgi.h" + +ssize_t uwsgi_file_logger(struct uwsgi_logger *ul, char *message, size_t len) { + + if (!ul->configured) { + if (ul->arg) { + ul->fd = open(ul->arg, O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP); + if (ul->fd >= 0) { + ul->configured = 1; + } + } + } + + if (ul->fd >= 0) { + return write(ul->fd, message, len); + } + return 0; + +} + +void uwsgi_file_logger_register() { + uwsgi_register_logger("file", uwsgi_file_logger); +} + +struct uwsgi_plugin logfile_plugin = { + + .name = "logfile", + .on_load = uwsgi_file_logger_register, + +}; + diff --git a/plugins/logfile/uwsgiplugin.py b/plugins/logfile/uwsgiplugin.py new file mode 100644 index 00000000..dd504017 --- /dev/null +++ b/plugins/logfile/uwsgiplugin.py @@ -0,0 +1,6 @@ +NAME='logfile' + +CFLAGS = [] +LDFLAGS = [] +LIBS = [] +GCC_LIST = ['logfile'] diff --git a/plugins/systemd_logger/systemd_logger.c b/plugins/systemd_logger/systemd_logger.c index c22ad7b7..45a89ce7 100644 --- a/plugins/systemd_logger/systemd_logger.c +++ b/plugins/systemd_logger/systemd_logger.c @@ -15,8 +15,9 @@ ssize_t uwsgi_systemd_logger(struct uwsgi_logger *ul, char *message, size_t len) } } + // last \n is missing... if (base < message+len) { - sd_journal_print(LOG_INFO, base); + sd_journal_print(LOG_INFO, "%.*s", (message+len) - base, base); } return 0;