compositor: Plug-in the file stream

Pass log scopes from the command line to subscribe log scopes
dynamically to the 'logger' subscriber.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
dev
Marius Vlad 5 years ago
parent 8b3ab3cd9b
commit f387f8409a
  1. 50
      compositor/main.c
  2. 6
      man/weston.man

@ -124,7 +124,6 @@ struct wet_compositor {
static FILE *weston_logfile = NULL; static FILE *weston_logfile = NULL;
static struct weston_log_scope *log_scope; static struct weston_log_scope *log_scope;
static struct weston_log_scope *protocol_scope; static struct weston_log_scope *protocol_scope;
static int cached_tm_mday = -1; static int cached_tm_mday = -1;
static int weston_log_timestamp(void) static int weston_log_timestamp(void)
@ -197,11 +196,7 @@ weston_log_file_close(void)
static int static int
vlog(const char *fmt, va_list ap) vlog(const char *fmt, va_list ap)
{ {
int l;
char timestr[128]; char timestr[128];
va_list ap2;
va_copy(ap2, ap);
if (weston_log_scope_is_enabled(log_scope)) { if (weston_log_scope_is_enabled(log_scope)) {
weston_log_scope_printf(log_scope, "%s ", weston_log_scope_printf(log_scope, "%s ",
@ -210,23 +205,14 @@ vlog(const char *fmt, va_list ap)
weston_log_scope_vprintf(log_scope, fmt, ap); weston_log_scope_vprintf(log_scope, fmt, ap);
} }
l = weston_log_timestamp(); return 0;
l += vfprintf(weston_logfile, fmt, ap2);
va_end(ap2);
return l;
} }
static int static int
vlog_continue(const char *fmt, va_list argp) vlog_continue(const char *fmt, va_list argp)
{ {
va_list argp2; weston_log_scope_vprintf(log_scope, fmt, argp);
return 0;
va_copy(argp2, argp);
weston_log_scope_vprintf(log_scope, fmt, argp2);
va_end(argp2);
return vfprintf(weston_logfile, fmt, argp);
} }
static const char * static const char *
@ -656,6 +642,9 @@ usage(int error_code)
" --no-config\t\tDo not read weston.ini\n" " --no-config\t\tDo not read weston.ini\n"
" --wait-for-debugger\tRaise SIGSTOP on start-up\n" " --wait-for-debugger\tRaise SIGSTOP on start-up\n"
" --debug\t\tEnable debug extension\n" " --debug\t\tEnable debug extension\n"
" -l, --logger-scopes=SCOPE\n\t\t\tSpecify log scopes to "
"subscribe to.\n\t\t\tCan specify multiple scopes, "
"each followed by comma\n"
" -h, --help\t\tThis help message\n\n"); " -h, --help\t\tThis help message\n\n");
#if defined(BUILD_DRM_COMPOSITOR) #if defined(BUILD_DRM_COMPOSITOR)
@ -2916,6 +2905,23 @@ wet_load_xwayland(struct weston_compositor *comp)
} }
#endif #endif
static void
weston_log_setup_scopes(struct weston_log_context *log_ctx,
struct weston_log_subscriber *subscriber,
const char *names)
{
assert(log_ctx);
assert(subscriber);
char *tokenize = strdup(names);
char *token = strtok(tokenize, ",");
while (token) {
weston_log_subscribe(log_ctx, subscriber, token);
token = strtok(NULL, ",");
}
free(tokenize);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int ret = EXIT_FAILURE; int ret = EXIT_FAILURE;
@ -2930,6 +2936,7 @@ int main(int argc, char *argv[])
char *modules = NULL; char *modules = NULL;
char *option_modules = NULL; char *option_modules = NULL;
char *log = NULL; char *log = NULL;
char *log_scopes = NULL;
char *server_socket = NULL; char *server_socket = NULL;
int32_t idle_time = -1; int32_t idle_time = -1;
int32_t help = 0; int32_t help = 0;
@ -2946,6 +2953,7 @@ int main(int argc, char *argv[])
struct weston_seat *seat; struct weston_seat *seat;
struct wet_compositor wet = { 0 }; struct wet_compositor wet = { 0 };
struct weston_log_context *log_ctx = NULL; struct weston_log_context *log_ctx = NULL;
struct weston_log_subscriber *logger = NULL;
int require_input; int require_input;
sigset_t mask; sigset_t mask;
@ -2968,6 +2976,7 @@ int main(int argc, char *argv[])
{ WESTON_OPTION_STRING, "config", 'c', &config_file }, { WESTON_OPTION_STRING, "config", 'c', &config_file },
{ WESTON_OPTION_BOOLEAN, "wait-for-debugger", 0, &wait_for_debugger }, { WESTON_OPTION_BOOLEAN, "wait-for-debugger", 0, &wait_for_debugger },
{ WESTON_OPTION_BOOLEAN, "debug", 0, &debug_protocol }, { WESTON_OPTION_BOOLEAN, "debug", 0, &debug_protocol },
{ WESTON_OPTION_STRING, "logger-scopes", 'l', &log_scopes },
}; };
wl_list_init(&wet.layoutput_list); wl_list_init(&wet.layoutput_list);
@ -2995,6 +3004,12 @@ int main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
logger = weston_log_subscriber_create_log(weston_logfile);
if (log_scopes)
weston_log_setup_scopes(log_ctx, logger, log_scopes);
else
weston_log_subscribe(log_ctx, logger, "log");
weston_log_set_handler(vlog, vlog_continue); weston_log_set_handler(vlog, vlog_continue);
weston_log_file_open(log); weston_log_file_open(log);
@ -3203,6 +3218,7 @@ out:
weston_compositor_log_scope_destroy(log_scope); weston_compositor_log_scope_destroy(log_scope);
log_scope = NULL; log_scope = NULL;
weston_compositor_destroy(wet.compositor); weston_compositor_destroy(wet.compositor);
weston_log_subscriber_destroy_log(logger);
out_signals: out_signals:
for (i = ARRAY_LENGTH(signals) - 1; i >= 0; i--) for (i = ARRAY_LENGTH(signals) - 1; i >= 0; i--)

@ -147,6 +147,12 @@ to take screenshots of the outputs using weston-screenshooter application,
which can lead to silently leaking the output contents. This option should which can lead to silently leaking the output contents. This option should
not be used in production. not be used in production.
.TP .TP
\fB\-\^l\fIscope1,scope2\fR, \fB\-\-logger-scopes\fR=\fIscope1,scope2\fR
Specify to which log scopes should subscribe to. When no scopes are supplied,
the log "log" scope will be subscribed by default. Useful to control which
streams to write data into the logger and can be helpful in diagnosing early
start-up code.
.TP
.BR \-\-version .BR \-\-version
Print the program version. Print the program version.
.TP .TP

Loading…
Cancel
Save