summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_main_process.c
diff options
context:
space:
mode:
authorAndrew Clayton <a.clayton@nginx.com>2023-03-30 05:53:13 +0100
committerAndrew Clayton <a.clayton@nginx.com>2023-04-11 19:08:32 +0100
commit45c45eaeb4443ff4af9cc49e716bbd9d65596b02 (patch)
tree1ca6fd50b5a7e3dfce5c90ddd30d5e73316c43f4 /src/nxt_main_process.c
parent8b8952930c8462b5c56cdaf14e4a1c7c8b0c203d (diff)
downloadunit-45c45eaeb4443ff4af9cc49e716bbd9d65596b02.tar.gz
unit-45c45eaeb4443ff4af9cc49e716bbd9d65596b02.tar.bz2
Add per-application logging.
Currently when running in the foreground, unit application processes will send stdout to the current TTY and stderr to the unit log file. That behaviour won't change. When running as a daemon, unit application processes will send stdout to /dev/null and stderr to the unit log file. This commit allows to alter the latter case of unit running as a daemon, by allowing applications to redirect stdout and/or stderr to specific log files. This is done via two new application options, 'stdout' & 'stderr', e.g "applications": { "myapp": { ... "stdout": "/path/to/log/unit/app/stdout.log", "stderr": "/path/to/log/unit/app/stderr.log" } } These log files are created by the application processes themselves and thus the log directories need to be writable by the user (and or group) of the application processes. E.g $ sudo mkdir -p /path/to/log/unit/app $ sudo chown APP_USER /path/to/log/unit/app These need to be setup before starting unit with the above config. Currently these log files do not participate in log-file rotation (SIGUSR1), that may change in a future commit. In the meantime these logs can be rotated using the traditional copy/truncate method. NOTE: You may or may not see stuff printed to stdout as stdout was traditionally used by CGI applications to communicate with the webserver. Closes: <https://github.com/nginx/unit/issues/197> Closes: <https://github.com/nginx/unit/issues/846> Reviewed-by: Alejandro Colomar <alx@nginx.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Diffstat (limited to 'src/nxt_main_process.c')
-rw-r--r--src/nxt_main_process.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c
index db1cfcb9..ae62aff4 100644
--- a/src/nxt_main_process.c
+++ b/src/nxt_main_process.c
@@ -121,6 +121,18 @@ static nxt_conf_map_t nxt_common_app_conf[] = {
},
{
+ nxt_string("stdout"),
+ NXT_CONF_MAP_CSTRZ,
+ offsetof(nxt_common_app_conf_t, stdout_log),
+ },
+
+ {
+ nxt_string("stderr"),
+ NXT_CONF_MAP_CSTRZ,
+ offsetof(nxt_common_app_conf_t, stderr_log),
+ },
+
+ {
nxt_string("working_directory"),
NXT_CONF_MAP_CSTRZ,
offsetof(nxt_common_app_conf_t, working_directory),