Add a Log4j 2.x Java agent
[lttng-ust.git] / doc / examples / java-log4j2-basic / HelloLog4j2.java
diff --git a/doc/examples/java-log4j2-basic/HelloLog4j2.java b/doc/examples/java-log4j2-basic/HelloLog4j2.java
new file mode 100644 (file)
index 0000000..2aa1026
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2022 EfficiOS Inc.
+ */
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ * Example application using the LTTng-UST Java log4j agent.
+ *
+ * <p>
+ * To obtain LTTng trace events, you should run the following sequence of
+ * commands:
+ * </p>
+ *
+ * <ul>
+ * <li>$ lttng create</li>
+ * <li>$ lttng enable-event -l -a</li>
+ * <li>$ lttng start</li>
+ * <li>(run this program)</li>
+ * <li>$ lttng stop</li>
+ * <li>$ lttng view</li>
+ * <li>$ lttng destroy</li>
+ * </ul>
+ *
+ */
+public class HelloLog4j2 {
+
+       private static final Logger logger = LogManager.getLogger(HelloLog4j2.class);
+
+       /**
+        * Application start
+        *
+        * @param args Command-line arguments
+        */
+       public static void main(String args[]) {
+
+               /* Trigger some tracing events using the Log4j Logger created before. */
+               logger.info("Basic config: Hello World, the answer is " + 42);
+               logger.info("Basic config: Another info event");
+               logger.error("Basic config: An error event");
+       }
+}
This page took 0.024641 seconds and 4 git commands to generate.