Move to kernel style SPDX license identifiers
[lttng-ust.git] / liblttng-ust-java-agent / java / lttng-ust-agent-jul / org / lttng / ust / agent / jul / LttngJulAgent.java
CommitLineData
5b5ffa03 1/*
c0c0989a 2 * SPDX-License-Identifier: LGPL-2.1-only
5b5ffa03 3 *
c0c0989a
MJ
4 * Copyright (C) 2015 EfficiOS Inc.
5 * Copyright (C) 2015 Alexandre Montplaisir <alexmonthy@efficios.com>
5b5ffa03
DG
6 */
7
d60dfbe4
AM
8package org.lttng.ust.agent.jul;
9
68a1ef73
AM
10import java.util.Collection;
11import java.util.Collections;
12import java.util.List;
46070114
AM
13import java.util.Set;
14import java.util.TreeSet;
68a1ef73
AM
15import java.util.logging.Handler;
16import java.util.logging.LogManager;
17import java.util.logging.Logger;
18
d60dfbe4
AM
19import org.lttng.ust.agent.AbstractLttngAgent;
20
21/**
22 * Agent implementation for tracing from JUL loggers.
23 *
24 * @author Alexandre Montplaisir
25 */
26class LttngJulAgent extends AbstractLttngAgent<LttngLogHandler> {
27
28 private static LttngJulAgent instance = null;
29
30 private LttngJulAgent() {
31 super(Domain.JUL);
32 }
5b5ffa03 33
d60dfbe4
AM
34 public static synchronized LttngJulAgent getInstance() {
35 if (instance == null) {
36 instance = new LttngJulAgent();
37 }
38 return instance;
39 }
5b5ffa03 40
68a1ef73
AM
41 @Override
42 public Collection<String> listAvailableEvents() {
46070114 43 Set<String> ret = new TreeSet<String>();
68a1ef73
AM
44
45 List<String> loggersNames = Collections.list(LogManager.getLogManager().getLoggerNames());
46 for (String name : loggersNames) {
47 /*
48 * Skip the root logger. An empty string is not a valid event name
49 * in LTTng.
50 */
46070114 51 if (name.equals("") || name.equals("global")) {
68a1ef73
AM
52 continue;
53 }
54
55 /*
56 * Check if that logger has at least one LTTng JUL handler attached.
57 */
58 Logger logger = Logger.getLogger(name);
59 if (hasLttngHandlerAttached(logger)) {
60 ret.add(name);
61 }
62 }
63
64 return ret;
65 }
66
67 private static boolean hasLttngHandlerAttached(Logger logger) {
68 for (Handler handler : logger.getHandlers()) {
69 if (handler instanceof LttngLogHandler) {
70 return true;
71 }
72 }
46070114
AM
73
74 /*
75 * A parent logger, if any, may be connected to an LTTng handler. In
76 * this case, we will want to include this child logger in the output,
77 * since it will be accessible by LTTng.
78 */
79 Logger parent = logger.getParent();
80 if (parent != null) {
81 return hasLttngHandlerAttached(parent);
82 }
83
84 /*
85 * We have reached the root logger and have not found any LTTng handler,
86 * this event will not be accessible.
87 */
68a1ef73
AM
88 return false;
89 }
90
5b5ffa03 91}
This page took 0.030361 seconds and 4 git commands to generate.