2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2015 EfficiOS Inc.
5 * Copyright (C) 2015 Alexandre Montplaisir <alexmonthy@efficios.com>
8 import java
.io
.IOException
;
9 import java
.util
.logging
.Level
;
11 import org
.lttng
.ust
.agent
.ILttngHandler
;
12 import org
.lttng
.ust
.agent
.filter
.FilterChangeNotifier
;
13 import org
.lttng
.ust
.agent
.filter
.IFilterChangeListener
;
14 import org
.lttng
.ust
.agent
.jul
.LttngLogHandler
;
15 import org
.lttng
.ust
.agent
.session
.EventRule
;
16 import org
.lttng
.ust
.agent
.session
.LogLevelSelector
;
19 * Example usage of a {@link IFilterChangeListener}.
21 * This listener will simply print to stdout the notifications it receives. To
22 * try it, run the program, then issue "lttng enable-event" and
23 * "lttng disable-event" commands for the JUL domain.
25 * @author Alexandre Montplaisir
27 public class FilterChangeListenerExample
{
29 private static class ExampleFilterChangeListener
implements IFilterChangeListener
{
32 public void eventRuleAdded(EventRule rule
) {
34 System
.out
.println("New event rule enabled:");
35 System
.out
.println("Event name: " + rule
.getEventName());
36 System
.out
.println(printLogLevel(rule
.getLogLevelSelector()));
37 System
.out
.println("Filter string: " + rule
.getFilterString());
41 public void eventRuleRemoved(EventRule rule
) {
43 System
.out
.println("Event rule disabled:");
44 System
.out
.println("Event name: " + rule
.getEventName());
45 System
.out
.println(printLogLevel(rule
.getLogLevelSelector()));
46 System
.out
.println("Filter string: " + rule
.getFilterString());
50 * Convenience method to print integer log level values into their JUL
53 private static String
printLogLevel(LogLevelSelector lls
) {
54 String llname
= Level
.parse(String
.valueOf(lls
.getLogLevel())).getName();
55 return "Log level: " + llname
+ ", filter type: " + lls
.getLogLevelType().toString();
63 * Command-line arguments (not used)
66 public static void main(String args
[]) throws IOException
{
67 /* We need at least one log handler to activate the LTTng agent */
68 ILttngHandler handler
= new LttngLogHandler();
70 /* Create a listener and register it to the manager */
71 IFilterChangeListener listener
= new ExampleFilterChangeListener();
72 FilterChangeNotifier
.getInstance().registerListener(listener
);
74 System
.out
.println("Press Enter to finish.");
77 /* Unregister the listener */
78 FilterChangeNotifier
.getInstance().unregisterListener(listener
);
80 /* Cleanup the log handler we created */