From 5fd4fb347293b17e265c0e9f065361261a62e6c3 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Wed, 22 May 2024 16:44:30 -0400 Subject: [PATCH] Add 'log4j2' domain to common test code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I84961823eb875c673e525d83d8096291506c1edb Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- .../base-path/load-stream-extra-path.lttng | 5 ++ .../tools/save-load/load-42-complex.lttng | 5 ++ .../tools/save-load/tracker_legacy_all.lttng | 5 ++ .../tools/save-load/tracker_legacy_none.lttng | 5 ++ .../save-load/tracker_legacy_selective.lttng | 5 ++ tests/utils/lttngtest/lttng.py | 24 ++++++++- tests/utils/lttngtest/lttngctl.py | 50 ++++++++++++++++++- 7 files changed, 97 insertions(+), 2 deletions(-) diff --git a/tests/regression/tools/base-path/load-stream-extra-path.lttng b/tests/regression/tools/base-path/load-stream-extra-path.lttng index 973d67a6d..b2ecc5695 100644 --- a/tests/regression/tools/base-path/load-stream-extra-path.lttng +++ b/tests/regression/tools/base-path/load-stream-extra-path.lttng @@ -44,6 +44,11 @@ PER_UID + + LOG4J2 + PER_UID + + PYTHON PER_UID diff --git a/tests/regression/tools/save-load/load-42-complex.lttng b/tests/regression/tools/save-load/load-42-complex.lttng index a80ce5302..4f6041f62 100644 --- a/tests/regression/tools/save-load/load-42-complex.lttng +++ b/tests/regression/tools/save-load/load-42-complex.lttng @@ -120,6 +120,11 @@ PER_UID + + LOG4J2 + PER_UID + + PYTHON PER_UID diff --git a/tests/regression/tools/save-load/tracker_legacy_all.lttng b/tests/regression/tools/save-load/tracker_legacy_all.lttng index 5552345f3..bf4940252 100644 --- a/tests/regression/tools/save-load/tracker_legacy_all.lttng +++ b/tests/regression/tools/save-load/tracker_legacy_all.lttng @@ -44,6 +44,11 @@ PER_UID + + LOG4J2 + PER_UID + + PYTHON PER_UID diff --git a/tests/regression/tools/save-load/tracker_legacy_none.lttng b/tests/regression/tools/save-load/tracker_legacy_none.lttng index 47aeb29fb..5160e1da9 100644 --- a/tests/regression/tools/save-load/tracker_legacy_none.lttng +++ b/tests/regression/tools/save-load/tracker_legacy_none.lttng @@ -48,6 +48,11 @@ PER_UID + + LOG4J2 + PER_UID + + PYTHON PER_UID diff --git a/tests/regression/tools/save-load/tracker_legacy_selective.lttng b/tests/regression/tools/save-load/tracker_legacy_selective.lttng index 11c0169aa..7be334940 100644 --- a/tests/regression/tools/save-load/tracker_legacy_selective.lttng +++ b/tests/regression/tools/save-load/tracker_legacy_selective.lttng @@ -55,6 +55,11 @@ PER_UID + + LOG4J2 + PER_UID + + PYTHON PER_UID diff --git a/tests/utils/lttngtest/lttng.py b/tests/utils/lttngtest/lttng.py index 3598cc940..3d5977657 100644 --- a/tests/utils/lttngtest/lttng.py +++ b/tests/utils/lttngtest/lttng.py @@ -42,6 +42,7 @@ def _get_domain_option_name(domain): lttngctl.TracingDomain.User: "userspace", lttngctl.TracingDomain.Kernel: "kernel", lttngctl.TracingDomain.Log4j: "log4j", + lttngctl.TracingDomain.Log4j2: "log4j2", lttngctl.TracingDomain.Python: "python", lttngctl.TracingDomain.JUL: "jul", }[domain] @@ -53,6 +54,7 @@ def _get_domain_xml_mi_name(domain): lttngctl.TracingDomain.User: "UST", lttngctl.TracingDomain.Kernel: "KERNEL", lttngctl.TracingDomain.Log4j: "LOG4J", + lttngctl.TracingDomain.Log4j2: "LOG4J2", lttngctl.TracingDomain.Python: "PYTHON", lttngctl.TracingDomain.JUL: "JUL", }[domain] @@ -121,6 +123,17 @@ def _get_log_level_argument_name(log_level): lttngctl.Log4jLogLevel.TRACE: "TRACE", lttngctl.Log4jLogLevel.ALL: "ALL", }[log_level] + elif isinstance(log_level, lttngctl.Log4j2LogLevel): + return { + lttngctl.Log4j2LogLevel.OFF: "OFF", + lttngctl.Log4j2LogLevel.FATAL: "FATAL", + lttngctl.Log4j2LogLevel.ERROR: "ERROR", + lttngctl.Log4j2LogLevel.WARN: "WARN", + lttngctl.Log4j2LogLevel.INFO: "INFO", + lttngctl.Log4j2LogLevel.DEBUG: "DEBUG", + lttngctl.Log4j2LogLevel.TRACE: "TRACE", + lttngctl.Log4j2LogLevel.ALL: "ALL", + }[log_level] elif isinstance(log_level, lttngctl.PythonLogLevel): return { lttngctl.PythonLogLevel.CRITICAL: "CRITICAL", @@ -169,6 +182,14 @@ def _get_log_level_from_mi_log_level_name(mi_log_level_name): "LOG4J_DEBUG": lttngctl.Log4jLogLevel.DEBUG, "LOG4J_TRACE": lttngctl.Log4jLogLevel.TRACE, "LOG4J_ALL": lttngctl.Log4jLogLevel.ALL, + "LOG4J2_OFF": lttngctl.Log4j2LogLevel.OFF, + "LOG4J2_FATAL": lttngctl.Log4j2LogLevel.FATAL, + "LOG4J2_ERROR": lttngctl.Log4j2LogLevel.ERROR, + "LOG4J2_WARN": lttngctl.Log4j2LogLevel.WARN, + "LOG4J2_INFO": lttngctl.Log4j2LogLevel.INFO, + "LOG4J2_DEBUG": lttngctl.Log4j2LogLevel.DEBUG, + "LOG4J2_TRACE": lttngctl.Log4j2LogLevel.TRACE, + "LOG4J2_ALL": lttngctl.Log4j2LogLevel.ALL, "PYTHON_CRITICAL": lttngctl.PythonLogLevel.CRITICAL, "PYTHON_ERROR": lttngctl.PythonLogLevel.ERROR, "PYTHON_WARNING": lttngctl.PythonLogLevel.WARNING, @@ -179,11 +200,12 @@ def _get_log_level_from_mi_log_level_name(mi_log_level_name): def _get_tracepoint_event_rule_class_from_domain_type(domain_type): - # type: (lttngctl.TracingDomain) -> Type[lttngctl.UserTracepointEventRule] | Type[lttngctl.Log4jTracepointEventRule] | Type[lttngctl.JULTracepointEventRule] | Type[lttngctl.PythonTracepointEventRule] | Type[lttngctl.KernelTracepointEventRule] + # type: (lttngctl.TracingDomain) -> Type[lttngctl.UserTracepointEventRule] | Type[lttngctl.Log4jTracepointEventRule] | Type[lttngctl.Log4j2TracepointEventRule] | Type[lttngctl.JULTracepointEventRule] | Type[lttngctl.PythonTracepointEventRule] | Type[lttngctl.KernelTracepointEventRule] return { lttngctl.TracingDomain.User: lttngctl.UserTracepointEventRule, lttngctl.TracingDomain.JUL: lttngctl.JULTracepointEventRule, lttngctl.TracingDomain.Log4j: lttngctl.Log4jTracepointEventRule, + lttngctl.TracingDomain.Log4j2: lttngctl.Log4j2TracepointEventRule, lttngctl.TracingDomain.Python: lttngctl.PythonTracepointEventRule, lttngctl.TracingDomain.Kernel: lttngctl.KernelTracepointEventRule, }[domain_type] diff --git a/tests/utils/lttngtest/lttngctl.py b/tests/utils/lttngtest/lttngctl.py index 5b937dc8a..6b8f6a969 100644 --- a/tests/utils/lttngtest/lttngctl.py +++ b/tests/utils/lttngtest/lttngctl.py @@ -81,7 +81,8 @@ class TracingDomain(enum.Enum): User = "User space tracing domain" Kernel = "Linux kernel tracing domain." - Log4j = "Log4j tracing back-end." + Log4j = "Log4j 1.x tracing back-end." + Log4j2 = "Log4j 2.x tracing back-end." JUL = "Java Util Logging tracing back-end." Python = "Python logging module tracing back-end." @@ -164,6 +165,18 @@ class Log4jLogLevel(LogLevel): ALL = -2147483648 +@enum.unique +class Log4j2LogLevel(LogLevel): + OFF = 0 + FATAL = 100 + ERROR = 200 + WARN = 300 + INFO = 400 + DEBUG = 500 + TRACE = 600 + ALL = 2147483647 + + @enum.unique class PythonLogLevel(LogLevel): CRITICAL = 50 @@ -304,6 +317,41 @@ class Log4jTracepointEventRule(TracepointEventRule): return self._name_pattern_exclusions +class Log4j2TracepointEventRule(TracepointEventRule): + def __init__( + self, + name_pattern=None, # type: Optional[str] + filter_expression=None, # type: Optional[str] + log_level_rule=None, # type: Optional[LogLevelRule] + name_pattern_exclusions=None, # type: Optional[List[str]] + ): + TracepointEventRule.__init__(self, name_pattern, filter_expression) + self._log_level_rule = log_level_rule # type: Optional[LogLevelRule] + self._name_pattern_exclusions = ( + name_pattern_exclusions + ) # type: Optional[List[str]] + + if log_level_rule and not isinstance(log_level_rule.level, Log4j2LogLevel): + raise ValueError("Log level rule must use a Log4j2LogLevel as its value") + + def _equals(self, other): + # type (Log4jTracepointEventRule) -> bool + return ( + self.log_level_rule == other.log_level_rule + and self.name_pattern_exclusions == other.name_pattern_exclusions + ) + + @property + def log_level_rule(self): + # type: () -> Optional[LogLevelRule] + return self._log_level_rule + + @property + def name_pattern_exclusions(self): + # type: () -> Optional[List[str]] + return self._name_pattern_exclusions + + class JULTracepointEventRule(TracepointEventRule): def __init__( self, -- 2.39.5