From: David Goulet Date: Mon, 4 Aug 2014 19:08:38 +0000 (-0400) Subject: Adding log4j agent support X-Git-Tag: v2.6.0-rc1~80 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=5cdb6027a2b78fd93aa7f61174625190b5fc3459;p=lttng-tools.git Adding log4j agent support This adds the log4j domain to the public ABI and "-l, --log4j" option in the lttng command line tool to be able to use it. Note that at this commit, the JUL default channel and event name are used for the log4j domain. That might become specific to the domain in the long run. Signed-off-by: David Goulet --- diff --git a/include/lttng/domain.h b/include/lttng/domain.h index a9c4e6399..becebe2dd 100644 --- a/include/lttng/domain.h +++ b/include/lttng/domain.h @@ -31,6 +31,7 @@ enum lttng_domain_type { LTTNG_DOMAIN_KERNEL = 1, /* Linux Kernel tracer. */ LTTNG_DOMAIN_UST = 2, /* Global Userspace tracer. */ LTTNG_DOMAIN_JUL = 3, /* Java Util Logging. */ + LTTNG_DOMAIN_LOG4J = 4, /* Java Log4j Framework. */ }; /* Buffer type for a specific domain. */ diff --git a/include/lttng/event.h b/include/lttng/event.h index 6848fe34d..40673a4d8 100644 --- a/include/lttng/event.h +++ b/include/lttng/event.h @@ -83,6 +83,21 @@ enum lttng_loglevel_jul { LTTNG_LOGLEVEL_JUL_ALL = INT32_MIN, }; +/* + * Available loglevels for the LOG4j domain. Those are an exact map from the + * class org.apache.log4j.Level. + */ +enum lttng_loglevel_log4j { + LTTNG_LOGLEVEL_LOG4J_OFF = INT32_MAX, + LTTNG_LOGLEVEL_LOG4J_FATAL = 50000, + LTTNG_LOGLEVEL_LOG4J_ERROR = 40000, + LTTNG_LOGLEVEL_LOG4J_WARN = 30000, + LTTNG_LOGLEVEL_LOG4J_INFO = 20000, + LTTNG_LOGLEVEL_LOG4J_DEBUG = 10000, + LTTNG_LOGLEVEL_LOG4J_TRACE = 5000, + LTTNG_LOGLEVEL_LOG4J_ALL = INT32_MIN, +}; + /* * LTTng consumer mode */ diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index d0dcda171..bacaa5caa 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1071,6 +1071,7 @@ int cmd_disable_event(struct ltt_session *session, int domain, channel_name); break; } + case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_JUL: { struct agent *agt; @@ -1078,7 +1079,7 @@ int cmd_disable_event(struct ltt_session *session, int domain, assert(usess); - agt = trace_ust_find_agent(usess, LTTNG_DOMAIN_JUL); + agt = trace_ust_find_agent(usess, domain); if (!agt) { ret = -LTTNG_ERR_UST_EVENT_NOT_FOUND; goto error; @@ -1183,6 +1184,7 @@ int cmd_disable_event_all(struct ltt_session *session, int domain, break; } + case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_JUL: { struct agent *agt; @@ -1190,7 +1192,7 @@ int cmd_disable_event_all(struct ltt_session *session, int domain, assert(usess); - agt = trace_ust_find_agent(usess, LTTNG_DOMAIN_JUL); + agt = trace_ust_find_agent(usess, domain); if (!agt) { ret = -LTTNG_ERR_UST_EVENT_NOT_FOUND; goto error; @@ -1480,6 +1482,7 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, } break; } + case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_JUL: { struct agent *agt; @@ -1489,9 +1492,9 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, assert(usess); - agt = trace_ust_find_agent(usess, LTTNG_DOMAIN_JUL); + agt = trace_ust_find_agent(usess, domain->type); if (!agt) { - agt = agent_create(LTTNG_DOMAIN_JUL); + agt = agent_create(domain->type); if (!agt) { ret = -LTTNG_ERR_NOMEM; goto error; @@ -1712,6 +1715,7 @@ int cmd_enable_event_all(struct ltt_session *session, break; } + case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_JUL: { struct agent *agt; @@ -1721,9 +1725,9 @@ int cmd_enable_event_all(struct ltt_session *session, assert(usess); - agt = trace_ust_find_agent(usess, LTTNG_DOMAIN_JUL); + agt = trace_ust_find_agent(usess, domain->type); if (!agt) { - agt = agent_create(LTTNG_DOMAIN_JUL); + agt = agent_create(domain->type); if (!agt) { ret = -LTTNG_ERR_NOMEM; goto error; @@ -1810,6 +1814,7 @@ ssize_t cmd_list_tracepoints(int domain, struct lttng_event **events) goto error; } break; + case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_JUL: nb_events = agent_list_events(events); if (nb_events < 0) { @@ -2540,6 +2545,7 @@ ssize_t cmd_list_events(int domain, struct ltt_session *session, } break; } + case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_JUL: if (session->ust_session) { struct lttng_ht_iter iter; diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index fac06e0f7..c7fc178cd 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -2593,6 +2593,7 @@ static int copy_session_consumer(int domain, struct ltt_session *session) dir_name = DEFAULT_KERNEL_TRACE_DIR; break; case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_UST: DBG3("Copying tracing session consumer output in UST session"); if (session->ust_session->consumer) { @@ -2637,6 +2638,7 @@ static int create_ust_session(struct ltt_session *session, switch (domain->type) { case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_UST: break; default: @@ -2882,6 +2884,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, } break; case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_UST: if (!cmd_ctx->session->ust_session) { ret = LTTNG_ERR_NO_CHANNEL; @@ -2963,6 +2966,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, break; case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_UST: { if (!ust_app_supported()) { @@ -3056,6 +3060,7 @@ skip_domain: cmd_ctx->lsm->cmd_type == LTTNG_STOP_TRACE) { switch (cmd_ctx->lsm->domain.type) { case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_UST: if (uatomic_read(&ust_consumerd_state) != CONSUMER_STARTED) { ret = LTTNG_ERR_NO_USTCONSUMERD; diff --git a/src/bin/lttng/commands/disable_events.c b/src/bin/lttng/commands/disable_events.c index 63e5f4741..7972d90a0 100644 --- a/src/bin/lttng/commands/disable_events.c +++ b/src/bin/lttng/commands/disable_events.c @@ -36,6 +36,7 @@ static char *opt_session_name; static int opt_userspace; static int opt_disable_all; static int opt_jul; +static int opt_log4j; #if 0 /* Not implemented yet */ static char *opt_cmd_name; @@ -58,6 +59,7 @@ static struct poptOption long_options[] = { {"all-events", 'a', POPT_ARG_VAL, &opt_disable_all, 1, 0, 0}, {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0}, {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0}, + {"log4j", 'l', POPT_ARG_VAL, &opt_log4j, 1, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, #if 0 /* Not implemented yet */ @@ -86,6 +88,7 @@ static void usage(FILE *ofp) fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n"); fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n"); fprintf(ofp, " -j, --jul Apply for Java application using JUL\n"); + fprintf(ofp, " -l, --log4j Apply to Java application using LOG4j\n"); fprintf(ofp, "\n"); } @@ -166,6 +169,8 @@ static int disable_events(char *session_name) dom.type = LTTNG_DOMAIN_UST; } else if (opt_jul) { dom.type = LTTNG_DOMAIN_JUL; + } else if (opt_log4j) { + dom.type = LTTNG_DOMAIN_LOG4J; } else { print_missing_domain(); ret = CMD_ERROR; diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 46a08d88c..f62dadbf0 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -46,6 +46,7 @@ static int opt_kernel; static char *opt_session_name; static int opt_userspace; static int opt_jul; +static int opt_log4j; static int opt_enable_all; static char *opt_probe; static char *opt_function; @@ -86,6 +87,7 @@ static struct poptOption long_options[] = { {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0}, + {"log4j", 'l', POPT_ARG_VAL, &opt_log4j, 1, 0, 0}, {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0}, {"probe", 0, POPT_ARG_STRING, &opt_probe, OPT_PROBE, 0, 0}, {"function", 0, POPT_ARG_STRING, &opt_function, OPT_FUNCTION, 0, 0}, @@ -121,6 +123,7 @@ static void usage(FILE *ofp) fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n"); fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n"); fprintf(ofp, " -j, --jul Apply for Java application using JUL\n"); + fprintf(ofp, " -l, --log4j Apply for Java application using LOG4j\n"); fprintf(ofp, "\n"); fprintf(ofp, "Event options:\n"); fprintf(ofp, " --tracepoint Tracepoint event (default)\n"); @@ -145,7 +148,7 @@ static void usage(FILE *ofp) fprintf(ofp, "\n"); fprintf(ofp, " --loglevel name\n"); fprintf(ofp, " Tracepoint loglevel range from 0 to loglevel.\n"); - fprintf(ofp, " For JUL domain, see the table below for the range values.\n"); + fprintf(ofp, " For JUL/LOG4j domain, see the table below for the range values.\n"); fprintf(ofp, " --loglevel-only name\n"); fprintf(ofp, " Tracepoint loglevel (only this loglevel)\n"); fprintf(ofp, "\n"); @@ -183,6 +186,17 @@ static void usage(FILE *ofp) fprintf(ofp, " JUL_ALL = INT32_MIN\n"); fprintf(ofp, " (shortcuts such as \"severe\" are allowed)\n"); fprintf(ofp, "\n"); + fprintf(ofp, " Available LOG4j domain loglevels:\n"); + fprintf(ofp, " LOG4J_OFF = INT32_MAX\n"); + fprintf(ofp, " LOG4J_FATAL = %d\n", LTTNG_LOGLEVEL_LOG4J_FATAL); + fprintf(ofp, " LOG4J_ERROR = %d\n", LTTNG_LOGLEVEL_LOG4J_ERROR); + fprintf(ofp, " LOG4J_WARN = %d\n", LTTNG_LOGLEVEL_LOG4J_WARN); + fprintf(ofp, " LOG4J_INFO = %d\n", LTTNG_LOGLEVEL_LOG4J_INFO); + fprintf(ofp, " LOG4J_DEBUG = %d\n", LTTNG_LOGLEVEL_LOG4J_DEBUG); + fprintf(ofp, " LOG4J_TRACE = %d\n", LTTNG_LOGLEVEL_LOG4J_TRACE); + fprintf(ofp, " LOG4J_ALL = INT32_MIN\n"); + fprintf(ofp, " (shortcuts such as \"severe\" are allowed)\n"); + fprintf(ofp, "\n"); fprintf(ofp, " -f, --filter \'expression\'\n"); fprintf(ofp, " Filter expression on event fields and context.\n"); fprintf(ofp, " Event recording depends on evaluation.\n"); @@ -298,6 +312,45 @@ end: return ret; } +/* + * Maps LOG4j loglevel from string to value + */ +static int loglevel_log4j_str_to_value(const char *inputstr) +{ + int i = 0; + char str[LTTNG_SYMBOL_NAME_LEN]; + + /* + * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is + * added at the end of the loop so a the upper bound we avoid the overflow. + */ + while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') { + str[i] = toupper(inputstr[i]); + i++; + } + str[i] = '\0'; + + if (!strcmp(str, "LOG4J_OFF") || !strcmp(str, "OFF")) { + return LTTNG_LOGLEVEL_LOG4J_OFF; + } else if (!strcmp(str, "LOG4J_FATAL") || !strcmp(str, "FATAL")) { + return LTTNG_LOGLEVEL_LOG4J_FATAL; + } else if (!strcmp(str, "LOG4J_ERROR") || !strcmp(str, "ERROR")) { + return LTTNG_LOGLEVEL_LOG4J_ERROR; + } else if (!strcmp(str, "LOG4J_WARN") || !strcmp(str, "WARN")) { + return LTTNG_LOGLEVEL_LOG4J_WARN; + } else if (!strcmp(str, "LOG4J_INFO") || !strcmp(str, "INFO")) { + return LTTNG_LOGLEVEL_LOG4J_INFO; + } else if (!strcmp(str, "LOG4J_DEBUG") || !strcmp(str, "DEBUG")) { + return LTTNG_LOGLEVEL_LOG4J_DEBUG; + } else if (!strcmp(str, "LOG4J_TRACE") || !strcmp(str, "TRACE")) { + return LTTNG_LOGLEVEL_LOG4J_TRACE; + } else if (!strcmp(str, "LOG4J_ALL") || !strcmp(str, "ALL")) { + return LTTNG_LOGLEVEL_LOG4J_ALL; + } else { + return -1; + } +} + /* * Maps JUL loglevel from string to value */ @@ -600,6 +653,10 @@ static int enable_events(char *session_name) dom.type = LTTNG_DOMAIN_JUL; /* Default. */ dom.buf_type = LTTNG_BUFFER_PER_UID; + } else if (opt_log4j) { + dom.type = LTTNG_DOMAIN_LOG4J; + /* Default. */ + dom.buf_type = LTTNG_BUFFER_PER_UID; } else { print_missing_domain(); ret = CMD_ERROR; @@ -642,11 +699,13 @@ static int enable_events(char *session_name) strcpy(ev.name, "*"); ev.loglevel_type = opt_loglevel_type; if (opt_loglevel) { - assert(opt_userspace || opt_jul); + assert(opt_userspace || opt_jul || opt_log4j); if (opt_userspace) { ev.loglevel = loglevel_str_to_value(opt_loglevel); } else if (opt_jul) { ev.loglevel = loglevel_jul_str_to_value(opt_loglevel); + } else if (opt_log4j) { + ev.loglevel = loglevel_log4j_str_to_value(opt_loglevel); } if (ev.loglevel == -1) { ERR("Unknown loglevel %s", opt_loglevel); @@ -654,10 +713,10 @@ static int enable_events(char *session_name) goto error; } } else { - assert(opt_userspace || opt_jul); + assert(opt_userspace || opt_jul || opt_log4j); if (opt_userspace) { ev.loglevel = -1; - } else if (opt_jul) { + } else if (opt_jul || opt_log4j) { ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL; } } @@ -941,24 +1000,32 @@ static int enable_events(char *session_name) } else { ev.loglevel = -1; } - } else if (opt_jul) { + } else if (opt_jul || opt_log4j) { if (opt_event_type != LTTNG_EVENT_ALL && opt_event_type != LTTNG_EVENT_TRACEPOINT) { - ERR("Event type not supported for JUL domain."); + ERR("Event type not supported for domain."); ret = CMD_UNSUPPORTED; goto error; } ev.loglevel_type = opt_loglevel_type; if (opt_loglevel) { - ev.loglevel = loglevel_jul_str_to_value(opt_loglevel); + if (opt_jul) { + ev.loglevel = loglevel_jul_str_to_value(opt_loglevel); + } else if (opt_log4j) { + ev.loglevel = loglevel_log4j_str_to_value(opt_loglevel); + } if (ev.loglevel == -1) { ERR("Unknown loglevel %s", opt_loglevel); ret = -LTTNG_ERR_INVALID; goto error; } } else { - ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL; + if (opt_jul) { + ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL; + } else if (opt_log4j) { + ev.loglevel = LTTNG_LOGLEVEL_LOG4J_ALL; + } } ev.type = LTTNG_EVENT_TRACEPOINT; strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN); @@ -999,8 +1066,9 @@ static int enable_events(char *session_name) } error_holder = command_ret; } else { - /* So we don't print the default channel name for JUL. */ - if (dom.type == LTTNG_DOMAIN_JUL) { + /* So we don't print the default channel name for agent domain. */ + if (dom.type == LTTNG_DOMAIN_JUL || + dom.type == LTTNG_DOMAIN_LOG4J) { MSG("%s event %s%s enabled.", get_domain_str(dom.type), event_name, exclusion_string); diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index 580b13f1f..e3ff4f1ba 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -30,6 +30,7 @@ static int opt_userspace; static int opt_kernel; static int opt_jul; +static int opt_log4j; static char *opt_channel; static int opt_domain; static int opt_fields; @@ -57,6 +58,7 @@ static struct poptOption long_options[] = { {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0}, + {"log4j", 'l', POPT_ARG_VAL, &opt_log4j, 1, 0, 0}, #if 0 /* Not implemented yet */ {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0}, @@ -304,7 +306,7 @@ static void print_event_field(struct lttng_event_field *field) * Machine interface * Jul and ust event listing */ -static int mi_list_jul_ust_events(struct lttng_event *events, int count, +static int mi_list_agent_ust_events(struct lttng_event *events, int count, struct lttng_domain *domain) { int ret, i; @@ -388,7 +390,7 @@ error: return ret; } -static int list_jul_events(void) +static int list_agent_events(void) { int i, size, ret = CMD_SUCCESS; struct lttng_domain domain; @@ -396,11 +398,18 @@ static int list_jul_events(void) struct lttng_event *event_list; pid_t cur_pid = 0; char *cmdline = NULL; - - DBG("Getting JUL tracing events"); + const char *agent_domain_str; memset(&domain, 0, sizeof(domain)); - domain.type = LTTNG_DOMAIN_JUL; + if (opt_jul) { + domain.type = LTTNG_DOMAIN_JUL; + } else if (opt_log4j) { + domain.type = LTTNG_DOMAIN_LOG4J; + } + + agent_domain_str = get_domain_str(domain.type); + + DBG("Getting %s tracing events", agent_domain_str); handle = lttng_create_handle(NULL, &domain); if (handle == NULL) { @@ -410,21 +419,23 @@ static int list_jul_events(void) size = lttng_list_tracepoints(handle, &event_list); if (size < 0) { - ERR("Unable to list JUL events: %s", lttng_strerror(size)); + ERR("Unable to list %s events: %s", agent_domain_str, + lttng_strerror(size)); ret = CMD_ERROR; goto end; } if (lttng_opt_mi) { /* Mi print */ - ret = mi_list_jul_ust_events(event_list, size, &domain); + ret = mi_list_agent_ust_events(event_list, size, &domain); if (ret) { ret = CMD_ERROR; goto error; } } else { /* Pretty print */ - MSG("JUL events (Logger name):\n-------------------------"); + MSG("%s events (Logger name):\n-------------------------", + agent_domain_str); if (size == 0) { MSG("None"); @@ -487,7 +498,7 @@ static int list_ust_events(void) if (lttng_opt_mi) { /* Mi print */ - ret = mi_list_jul_ust_events(event_list, size, &domain); + ret = mi_list_agent_ust_events(event_list, size, &domain); } else { /* Pretty print */ MSG("UST events:\n-------------"); @@ -821,9 +832,9 @@ error: /* * Machine Interface - * Print a list of jul events + * Print a list of agent events */ -static int mi_list_session_jul_events(struct lttng_event *events, int count) +static int mi_list_session_agent_events(struct lttng_event *events, int count) { int ret, i; @@ -848,11 +859,11 @@ end: } /* - * List JUL events for a specific session using the handle. + * List agent events for a specific session using the handle. * * Return CMD_SUCCESS on success else a negative value. */ -static int list_session_jul_events(void) +static int list_session_agent_events(void) { int ret = CMD_SUCCESS, count, i; struct lttng_event *events = NULL; @@ -866,7 +877,7 @@ static int list_session_jul_events(void) if (lttng_opt_mi) { /* Mi print */ - ret = mi_list_session_jul_events(events, count); + ret = mi_list_session_agent_events(events, count); if (ret) { ret = CMD_ERROR; goto end; @@ -1360,6 +1371,9 @@ static int list_domains(const char *session_name) case LTTNG_DOMAIN_JUL: MSG(" - JUL (Java Util Logging)"); break; + case LTTNG_DOMAIN_LOG4J: + MSG(" - LOG4j (Logging for Java)"); + break; default: break; } @@ -1450,9 +1464,11 @@ int cmd_list(int argc, const char **argv) } else if (opt_jul) { DBG2("Listing JUL domain"); domain.type = LTTNG_DOMAIN_JUL; + } else if (opt_jul) { + domain.type = LTTNG_DOMAIN_LOG4J; } - if (opt_kernel || opt_userspace || opt_jul) { + if (opt_kernel || opt_userspace || opt_jul || opt_log4j) { handle = lttng_create_handle(session_name, &domain); if (handle == NULL) { ret = CMD_FATAL; @@ -1461,7 +1477,7 @@ int cmd_list(int argc, const char **argv) } if (session_name == NULL) { - if (!opt_kernel && !opt_userspace && !opt_jul) { + if (!opt_kernel && !opt_userspace && !opt_jul && !opt_log4j) { ret = list_sessions(NULL); if (ret) { goto end; @@ -1483,8 +1499,8 @@ int cmd_list(int argc, const char **argv) goto end; } } - if (opt_jul) { - ret = list_jul_events(); + if (opt_jul || opt_log4j) { + ret = list_agent_events(); if (ret) { goto end; } @@ -1578,6 +1594,9 @@ int cmd_list(int argc, const char **argv) case LTTNG_DOMAIN_JUL: MSG("=== Domain: JUL (Java Util Logging) ===\n"); break; + case LTTNG_DOMAIN_LOG4J: + MSG("=== Domain: LOG4j (Logging for Java) ===\n"); + break; default: MSG("=== Domain: Unimplemented ===\n"); break; @@ -1602,8 +1621,9 @@ int cmd_list(int argc, const char **argv) goto end; } - if (domains[i].type == LTTNG_DOMAIN_JUL) { - ret = list_session_jul_events(); + if (domains[i].type == LTTNG_DOMAIN_JUL || + domains[i].type == LTTNG_DOMAIN_LOG4J) { + ret = list_session_agent_events(); if (ret) { goto end; } diff --git a/src/bin/lttng/utils.c b/src/bin/lttng/utils.c index 257dfc89a..fc592ebde 100644 --- a/src/bin/lttng/utils.c +++ b/src/bin/lttng/utils.c @@ -36,6 +36,7 @@ static const char *str_kernel = "Kernel"; static const char *str_ust = "UST"; static const char *str_jul = "JUL"; +static const char *str_log4j = "LOG4J"; /* * get_session_name @@ -274,6 +275,9 @@ const char *get_domain_str(enum lttng_domain_type domain) case LTTNG_DOMAIN_JUL: str_dom = str_jul; break; + case LTTNG_DOMAIN_LOG4J: + str_dom = str_log4j; + break; default: /* Should not have an unknown domain or else define it. */ assert(0); diff --git a/src/common/config/config-session-abi.h b/src/common/config/config-session-abi.h index 0efd391d5..1a1feec06 100644 --- a/src/common/config/config-session-abi.h +++ b/src/common/config/config-session-abi.h @@ -69,6 +69,7 @@ const char * const config_element_max_size; const char * const config_domain_type_kernel; const char * const config_domain_type_ust; const char * const config_domain_type_jul; +const char * const config_domain_type_log4j; const char * const config_buffer_type_per_pid; const char * const config_buffer_type_per_uid; diff --git a/src/common/config/config.c b/src/common/config/config.c index bfb2576f4..a1ad95e46 100644 --- a/src/common/config/config.c +++ b/src/common/config/config.c @@ -117,6 +117,7 @@ const char * const config_element_max_size = "max_size"; const char * const config_domain_type_kernel = "KERNEL"; const char * const config_domain_type_ust = "UST"; const char * const config_domain_type_jul = "JUL"; +const char * const config_domain_type_log4j = "LOG4J"; const char * const config_buffer_type_per_pid = "PER_PID"; const char * const config_buffer_type_per_uid = "PER_UID"; @@ -749,6 +750,8 @@ int get_domain_type(xmlChar *domain) ret = LTTNG_DOMAIN_UST; } else if (!strcmp((char *) domain, config_domain_type_jul)) { ret = LTTNG_DOMAIN_JUL; + } else if (!strcmp((char *) domain, config_domain_type_log4j)) { + ret = LTTNG_DOMAIN_LOG4J; } else { goto error; } @@ -1236,6 +1239,7 @@ int create_session(const char *name, struct lttng_domain *kernel_domain, struct lttng_domain *ust_domain, struct lttng_domain *jul_domain, + struct lttng_domain *log4j_domain, xmlNodePtr output_node, uint64_t live_timer_interval) { @@ -1276,7 +1280,7 @@ int create_session(const char *name, int i; struct lttng_domain *domain; struct lttng_domain *domains[] = - { kernel_domain, ust_domain, jul_domain }; + { kernel_domain, ust_domain, jul_domain, log4j_domain}; /* network destination */ if (live_timer_interval && live_timer_interval != UINT64_MAX) { @@ -2147,6 +2151,7 @@ int process_session_node(xmlNodePtr session_node, const char *session_name, struct lttng_domain *kernel_domain = NULL; struct lttng_domain *ust_domain = NULL; struct lttng_domain *jul_domain = NULL; + struct lttng_domain *log4j_domain = NULL; for (node = xmlFirstElementChild(session_node); node; node = xmlNextElementSibling(node)) { @@ -2273,6 +2278,13 @@ int process_session_node(xmlNodePtr session_node, const char *session_name, } jul_domain = domain; break; + case LTTNG_DOMAIN_LOG4J: + if (log4j_domain) { + /* Same domain seen twice, invalid! */ + goto domain_init_error; + } + log4j_domain = domain; + break; default: WARN("Invalid domain type"); goto domain_init_error; @@ -2299,11 +2311,11 @@ domain_init_error: } else if (live_timer_interval && live_timer_interval != UINT64_MAX) { ret = create_session(name, kernel_domain, ust_domain, jul_domain, - output_node, live_timer_interval); + log4j_domain, output_node, live_timer_interval); } else { /* regular session */ ret = create_session(name, kernel_domain, ust_domain, jul_domain, - output_node, UINT64_MAX); + log4j_domain, output_node, UINT64_MAX); } if (ret) { goto error; @@ -2334,6 +2346,7 @@ error: free(kernel_domain); free(ust_domain); free(jul_domain); + free(log4j_domain); free(name); return ret; } diff --git a/src/common/mi-lttng.c b/src/common/mi-lttng.c index a636c71b2..fc7207cb4 100644 --- a/src/common/mi-lttng.c +++ b/src/common/mi-lttng.c @@ -305,6 +305,8 @@ const char *mi_lttng_domaintype_string(enum lttng_domain_type value) return config_domain_type_ust; case LTTNG_DOMAIN_JUL: return config_domain_type_jul; + case LTTNG_DOMAIN_LOG4J: + return config_domain_type_log4j; default: /* Should not have an unknown domain */ assert(0); diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index b9dc1efb0..9686b7d0f 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -105,6 +105,7 @@ void lttng_ctl_copy_lttng_domain(struct lttng_domain *dst, case LTTNG_DOMAIN_KERNEL: case LTTNG_DOMAIN_UST: case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: memcpy(dst, src, sizeof(struct lttng_domain)); break; default: @@ -938,7 +939,8 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, * filtering by logger name. */ if (exclusion_count == 0 && filter_expression == NULL && - handle->domain.type != LTTNG_DOMAIN_JUL) { + (handle->domain.type != LTTNG_DOMAIN_JUL && + handle->domain.type != LTTNG_DOMAIN_LOG4J)) { goto ask_sessiond; } @@ -948,8 +950,10 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, */ /* Parse filter expression */ - if (filter_expression != NULL || handle->domain.type == LTTNG_DOMAIN_JUL) { - if (handle->domain.type == LTTNG_DOMAIN_JUL) { + if (filter_expression != NULL || handle->domain.type == LTTNG_DOMAIN_JUL + || handle->domain.type == LTTNG_DOMAIN_LOG4J) { + if (handle->domain.type == LTTNG_DOMAIN_JUL || + handle->domain.type == LTTNG_DOMAIN_LOG4J) { char *jul_filter; /* Setup JUL filter if needed. */