Make --logpath work again
Also add a new option "log-file" to config file and command line, it doesn the same thing as --logpath. --logpath was never documented, and "log-file" is more consistent with the naming of options. Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
fa98564040
commit
7915ade1be
|
@ -3,6 +3,8 @@ shadow = true;
|
||||||
shadow-radius = 7;
|
shadow-radius = 7;
|
||||||
shadow-offset-x = -7;
|
shadow-offset-x = -7;
|
||||||
shadow-offset-y = -7;
|
shadow-offset-y = -7;
|
||||||
|
log-level = "warn";
|
||||||
|
# log-file = "/path/to/your/log/file";
|
||||||
# shadow-opacity = 0.7;
|
# shadow-opacity = 0.7;
|
||||||
# shadow-red = 0.0;
|
# shadow-red = 0.0;
|
||||||
# shadow-green = 0.0;
|
# shadow-green = 0.0;
|
||||||
|
|
|
@ -73,6 +73,9 @@ OPTIONS
|
||||||
*--log-level*::
|
*--log-level*::
|
||||||
Set the log level. Possible values are "TRACE", "DEBUG", "INFO", "WARN", "ERROR", in increasing level of importance. Case doesn't matter.
|
Set the log level. Possible values are "TRACE", "DEBUG", "INFO", "WARN", "ERROR", in increasing level of importance. Case doesn't matter.
|
||||||
|
|
||||||
|
*--log-file*::
|
||||||
|
Set the log file. If *--log-file* is never specified, logs will be written to stderr. Otherwise, logs will to writeen to the give file, though some of the early logs might still be written to the stderr. When setting this option from the config file, it is recommended to use an absolute path.
|
||||||
|
|
||||||
*--show-all-xerrors*::
|
*--show-all-xerrors*::
|
||||||
Show all X errors (for debugging).
|
Show all X errors (for debugging).
|
||||||
|
|
||||||
|
|
|
@ -2062,26 +2062,6 @@ register_cm(session_t *ps) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reopen streams for logging.
|
|
||||||
*/
|
|
||||||
static bool
|
|
||||||
stdout_reopen(session_t *ps, const char *path) {
|
|
||||||
if (!path)
|
|
||||||
path = ps->o.logpath;
|
|
||||||
if (!path)
|
|
||||||
path = "/dev/null";
|
|
||||||
|
|
||||||
bool success = freopen(path, "a", stdout);
|
|
||||||
success = freopen(path, "a", stderr) && success;
|
|
||||||
if (!success) {
|
|
||||||
log_fatal("(%s): freopen() failed.", path);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fork program to background and disable all I/O streams.
|
* Fork program to background and disable all I/O streams.
|
||||||
*/
|
*/
|
||||||
|
@ -2719,7 +2699,12 @@ session_init(session_t *ps_old, int argc, char **argv) {
|
||||||
};
|
};
|
||||||
|
|
||||||
log_init_tls();
|
log_init_tls();
|
||||||
log_add_target_tls(stderr_logger_new());
|
struct log_target *log_target = stderr_logger_new();
|
||||||
|
if (!log_target) {
|
||||||
|
fprintf(stderr, "Cannot create any logger, giving up.\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
log_add_target_tls(log_target);
|
||||||
|
|
||||||
// Allocate a session and copy default values into it
|
// Allocate a session and copy default values into it
|
||||||
session_t *ps = cmalloc(session_t);
|
session_t *ps = cmalloc(session_t);
|
||||||
|
@ -2845,6 +2830,20 @@ session_init(session_t *ps_old, int argc, char **argv) {
|
||||||
// Parse all of the rest command line options
|
// Parse all of the rest command line options
|
||||||
get_cfg(&ps->o, argc, argv, shadow_enabled, fading_enable, hasneg, winopt_mask);
|
get_cfg(&ps->o, argc, argv, shadow_enabled, fading_enable, hasneg, winopt_mask);
|
||||||
|
|
||||||
|
if (ps->o.logpath) {
|
||||||
|
log_target = file_logger_new(ps->o.logpath);
|
||||||
|
if (log_target) {
|
||||||
|
auto level = log_get_level_tls();
|
||||||
|
log_info("Switching to log file: %s", ps->o.logpath);
|
||||||
|
log_deinit_tls();
|
||||||
|
log_init_tls();
|
||||||
|
log_set_level_tls(level);
|
||||||
|
log_add_target_tls(log_target);
|
||||||
|
} else {
|
||||||
|
log_error("Failed to setup log file %s, I will keep using stderr", ps->o.logpath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get needed atoms for c2 condition lists
|
// Get needed atoms for c2 condition lists
|
||||||
if (!(c2_list_postprocess(ps, ps->o.unredir_if_possible_blacklist) &&
|
if (!(c2_list_postprocess(ps, ps->o.unredir_if_possible_blacklist) &&
|
||||||
c2_list_postprocess(ps, ps->o.paint_blacklist) &&
|
c2_list_postprocess(ps, ps->o.paint_blacklist) &&
|
||||||
|
@ -3051,8 +3050,12 @@ session_init(session_t *ps_old, int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect output stream
|
// Redirect output stream
|
||||||
if (ps->o.fork_after_register || ps->o.logpath)
|
if (ps->o.fork_after_register) {
|
||||||
stdout_reopen(ps, NULL);
|
if (!freopen("/dev/null", "w", stdout) || !freopen("/dev/null", "w", stderr)) {
|
||||||
|
log_fatal("Failed to redirect stdout/stderr to /dev/null");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
write_pid(ps);
|
write_pid(ps);
|
||||||
|
|
||||||
|
|
|
@ -300,6 +300,13 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
|
||||||
log_set_level_tls(level);
|
log_set_level_tls(level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// --log-file
|
||||||
|
if (config_lookup_string(&cfg, "log-file", &sval)) {
|
||||||
|
if (*sval != '/') {
|
||||||
|
log_warn("The log-file in your configuration file is not an absolute path");
|
||||||
|
}
|
||||||
|
opt->logpath = strdup(sval);
|
||||||
|
}
|
||||||
// --sw-opti
|
// --sw-opti
|
||||||
lcfg_lookup_bool(&cfg, "sw-opti", &opt->sw_opti);
|
lcfg_lookup_bool(&cfg, "sw-opti", &opt->sw_opti);
|
||||||
// --use-ewmh-active-win
|
// --use-ewmh-active-win
|
||||||
|
|
|
@ -452,6 +452,7 @@ static const struct option longopts[] = {
|
||||||
{"no-x-selection", no_argument, NULL, 319},
|
{"no-x-selection", no_argument, NULL, 319},
|
||||||
{"no-name-pixmap", no_argument, NULL, 320},
|
{"no-name-pixmap", no_argument, NULL, 320},
|
||||||
{"log-level", required_argument, NULL, 321},
|
{"log-level", required_argument, NULL, 321},
|
||||||
|
{"log-file", required_argument, NULL, 322},
|
||||||
{"reredir-on-root-change", no_argument, NULL, 731},
|
{"reredir-on-root-change", no_argument, NULL, 731},
|
||||||
{"glx-reinit-on-root-change", no_argument, NULL, 732},
|
{"glx-reinit-on-root-change", no_argument, NULL, 732},
|
||||||
{"monitor-repaint", no_argument, NULL, 800},
|
{"monitor-repaint", no_argument, NULL, 800},
|
||||||
|
@ -471,10 +472,11 @@ bool get_early_config(int argc, char *const *argv, char **config_file, bool *all
|
||||||
// Must reset optind to 0 here in case we reread the commandline
|
// Must reset optind to 0 here in case we reread the commandline
|
||||||
// arguments
|
// arguments
|
||||||
optind = 1;
|
optind = 1;
|
||||||
|
*config_file = NULL;
|
||||||
while (-1 != (o = getopt_long(argc, argv, shortopts, longopts, &longopt_idx))) {
|
while (-1 != (o = getopt_long(argc, argv, shortopts, longopts, &longopt_idx))) {
|
||||||
if (o == 256)
|
if (o == 256) {
|
||||||
*config_file = strdup(optarg);
|
*config_file = strdup(optarg);
|
||||||
else if (o == 'd') {
|
} else if (o == 'd') {
|
||||||
log_warn("-d will be ignored, please use the DISPLAY "
|
log_warn("-d will be ignored, please use the DISPLAY "
|
||||||
"environment variable");
|
"environment variable");
|
||||||
} else if (o == 314) {
|
} else if (o == 314) {
|
||||||
|
@ -505,8 +507,7 @@ bool get_early_config(int argc, char *const *argv, char **config_file, bool *all
|
||||||
* Process arguments and configuration files.
|
* Process arguments and configuration files.
|
||||||
*/
|
*/
|
||||||
void get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
|
void get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
|
||||||
bool fading_enable, bool conv_kern_hasneg,
|
bool fading_enable, bool conv_kern_hasneg, win_option_mask_t *winopt_mask) {
|
||||||
win_option_mask_t *winopt_mask) {
|
|
||||||
|
|
||||||
int o = 0, longopt_idx = -1;
|
int o = 0, longopt_idx = -1;
|
||||||
|
|
||||||
|
@ -655,7 +656,10 @@ void get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
|
||||||
P_CASEBOOL(285, blur_background_fixed);
|
P_CASEBOOL(285, blur_background_fixed);
|
||||||
P_CASEBOOL(286, dbus);
|
P_CASEBOOL(286, dbus);
|
||||||
case 287:
|
case 287:
|
||||||
// --logpath
|
log_warn("Please use --log-file instead of --logpath");
|
||||||
|
case 322:
|
||||||
|
// --logpath, --log-file
|
||||||
|
free(opt->logpath);
|
||||||
opt->logpath = strdup(optarg);
|
opt->logpath = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 288:
|
case 288:
|
||||||
|
|
|
@ -29,7 +29,6 @@ bool get_early_config(int argc, char *const *argv, char **config_file, bool *all
|
||||||
* winopt_mask
|
* winopt_mask
|
||||||
*/
|
*/
|
||||||
void get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
|
void get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
|
||||||
bool fading_enable, bool conv_kern_hasneg,
|
bool fading_enable, bool conv_kern_hasneg, win_option_mask_t *winopt_mask);
|
||||||
win_option_mask_t *winopt_mask);
|
|
||||||
|
|
||||||
// vim: set noet sw=8 ts=8:
|
// vim: set noet sw=8 ts=8:
|
||||||
|
|
Loading…
Reference in New Issue