Skip to content

Commit

Permalink
feat: add optional environment variable LOGPROXY_CHMOD to change logf… (
Browse files Browse the repository at this point in the history
#32)

…iles mode
  • Loading branch information
thebaptiste authored Feb 21, 2022
1 parent 45e03da commit 718f3a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Optional environment variables to override defaults :
LOGPROXY_ROTATION_TIME
LOGPROXY_ROTATION_SUFFIX
LOGPROXY_ROTATED_FILES
LOGPROXY_CHMOD

Example for rotation-size option :
- If log_proxy is run with the option --rotation-size on command line, rotation-size will take the provided value
Expand Down Expand Up @@ -155,7 +156,7 @@ Application Options:
-S, --rotation-suffix strftime based suffix to append to rotated log files (default: content of environment variable LOGPROXY_ROTATION_SUFFIX or .%%Y%%m%%d%%H%%M%%S)
-d, --log-directory directory to store log files (default: content of environment variable LOGPROXY_LOG_DIRECTORY or current directory), directory is created if missing
-n, --rotated-files maximum number of rotated files to keep including main one (0 => no cleaning, default: content of environment variable LOGPROXY_ROTATED_FILES or 5)
-c, --chmod if set, chmod the logfile to this octal value (0700 for example)
-c, --chmod if set, chmod the logfile to this value, "0700" for example (default : content of environment variable LOGPROXY_CHMOD or NULL)
-o, --chown if set, try (if you don't have sufficient privileges, it will fail silently) to change the owner of the logfile to the given user value
-g, --chgrp if set, try (if you don't have sufficient privileges, it will fail silently) to change the group of the logfile to the given group value
-m, --use-locks use locks to append to main log file (useful if several process writes to the same file)
Expand Down
9 changes: 8 additions & 1 deletion src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ void set_default_values_from_env()
log_directory = g_get_current_dir();
}
}

if ( chmod == NULL ) {
env_val = g_getenv("LOGPROXY_CHMOD");
if ( env_val != NULL ) {
chmod = (gchar *)env_val;
}
}
}

static GOptionEntry entries[] = {
Expand All @@ -87,7 +94,7 @@ static GOptionEntry entries[] = {
{ "rotation-suffix", 'S', 0, G_OPTION_ARG_STRING, &rotation_suffix, "strftime based suffix to append to rotated log files (default: content of environment variable LOGPROXY_ROTATION_SUFFIX or .%%Y%%m%%d%%H%%M%%S)", NULL },
{ "log-directory", 'd', 0, G_OPTION_ARG_STRING, &log_directory, "directory to store log files (default: content of environment variable LOGPROXY_LOG_DIRECTORY or current directory), directory is created if missing", NULL },
{ "rotated-files", 'n', 0, G_OPTION_ARG_INT, &rotated_files, "maximum number of rotated files to keep including main one (0 => no cleaning, default: content of environment variable LOGPROXY_ROTATED_FILES or 5)", NULL },
{ "chmod", 'c', 0, G_OPTION_ARG_STRING, &chmod_str, "if set, chmod the logfile to this octal value (0700 for example)", NULL },
{ "chmod", 'c', 0, G_OPTION_ARG_STRING, &chmod_str, "if set, chmod the logfile to this value, '0700' for example (default: content of environment variable LOGPROXY_CHMOD or NULL)", NULL },
{ "chown", 'o', 0, G_OPTION_ARG_STRING, &chown_str, "if set, try (if you don't have sufficient privileges, it will fail silently) to change the owner of the logfile to the given user value", NULL },
{ "chgrp", 'g', 0, G_OPTION_ARG_STRING, &chgrp_str, "if set, try (if you don't have sufficient privileges, it will fail silently) to change the group of the logfile to the given group value", NULL },
{ "use-locks", 'm', 0, G_OPTION_ARG_NONE, &use_locks, "use locks to append to main log file (useful if several process writes to the same file)", NULL },
Expand Down

0 comments on commit 718f3a0

Please sign in to comment.