Commit | Line | Data |
---|---|---|
5b5ffa03 | 1 | /* |
d60dfbe4 | 2 | * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com> |
5b5ffa03 DG |
3 | * |
4 | * This library is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU Lesser General Public License, version 2.1 only, | |
6 | * as published by the Free Software Foundation. | |
7 | * | |
8 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | |
11 | * for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU Lesser General Public License | |
14 | * along with this library; if not, write to the Free Software Foundation, | |
15 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
16 | */ | |
17 | ||
d60dfbe4 AM |
18 | package org.lttng.ust.agent.jul; |
19 | ||
68a1ef73 AM |
20 | import java.util.ArrayList; |
21 | import java.util.Collection; | |
22 | import java.util.Collections; | |
23 | import java.util.List; | |
24 | import java.util.logging.Handler; | |
25 | import java.util.logging.LogManager; | |
26 | import java.util.logging.Logger; | |
27 | ||
d60dfbe4 AM |
28 | import org.lttng.ust.agent.AbstractLttngAgent; |
29 | ||
30 | /** | |
31 | * Agent implementation for tracing from JUL loggers. | |
32 | * | |
33 | * @author Alexandre Montplaisir | |
34 | */ | |
35 | class LttngJulAgent extends AbstractLttngAgent<LttngLogHandler> { | |
36 | ||
37 | private static LttngJulAgent instance = null; | |
38 | ||
39 | private LttngJulAgent() { | |
40 | super(Domain.JUL); | |
41 | } | |
5b5ffa03 | 42 | |
d60dfbe4 AM |
43 | public static synchronized LttngJulAgent getInstance() { |
44 | if (instance == null) { | |
45 | instance = new LttngJulAgent(); | |
46 | } | |
47 | return instance; | |
48 | } | |
5b5ffa03 | 49 | |
68a1ef73 AM |
50 | @Override |
51 | public Collection<String> listAvailableEvents() { | |
52 | List<String> ret = new ArrayList<String>(); | |
53 | ||
54 | List<String> loggersNames = Collections.list(LogManager.getLogManager().getLoggerNames()); | |
55 | for (String name : loggersNames) { | |
56 | /* | |
57 | * Skip the root logger. An empty string is not a valid event name | |
58 | * in LTTng. | |
59 | */ | |
60 | if (name.equals("")) { | |
61 | continue; | |
62 | } | |
63 | ||
64 | /* | |
65 | * Check if that logger has at least one LTTng JUL handler attached. | |
66 | */ | |
67 | Logger logger = Logger.getLogger(name); | |
68 | if (hasLttngHandlerAttached(logger)) { | |
69 | ret.add(name); | |
70 | } | |
71 | } | |
72 | ||
73 | return ret; | |
74 | } | |
75 | ||
76 | private static boolean hasLttngHandlerAttached(Logger logger) { | |
77 | for (Handler handler : logger.getHandlers()) { | |
78 | if (handler instanceof LttngLogHandler) { | |
79 | return true; | |
80 | } | |
81 | } | |
82 | return false; | |
83 | } | |
84 | ||
5b5ffa03 | 85 | } |