Commit | Line | Data |
---|---|---|
2b408e85 AM |
1 | /* |
2 | * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | */ | |
18 | ||
4821eac9 | 19 | package org.lttng.ust.agent.utils; |
8576633f | 20 | |
4821eac9 | 21 | import java.io.IOException; |
8576633f AM |
22 | import java.util.logging.Level; |
23 | import java.util.logging.Logger; | |
24 | ||
4821eac9 AM |
25 | import org.lttng.ust.agent.jul.LttngLogHandler; |
26 | ||
8a0613fa AM |
27 | /** |
28 | * Utility methods for JUL tests | |
29 | */ | |
4821eac9 AM |
30 | public final class JulTestUtils { |
31 | ||
32 | private JulTestUtils() { | |
33 | } | |
8576633f | 34 | |
4821eac9 AM |
35 | /** |
36 | * Check the the JUL native library is available, effectively allowing LTTng | |
37 | * JUL handlers to be used. | |
38 | * | |
39 | * @return True if JUL works fine, false if it does not. | |
40 | */ | |
41 | public static boolean checkForJulLibrary() { | |
42 | try { | |
43 | LttngLogHandler testHandler = new LttngLogHandler(); | |
44 | testHandler.close(); | |
45 | } catch (SecurityException | IOException e) { | |
46 | return false; | |
47 | } | |
48 | return true; | |
8576633f AM |
49 | } |
50 | ||
4821eac9 AM |
51 | /** |
52 | * Send 10 dummy events through the provided logger | |
53 | * | |
54 | * @param logger | |
55 | * The logger to use to send events | |
56 | */ | |
57 | public static void send10EventsTo(Logger logger) { | |
8576633f AM |
58 | String a = new String("a"); |
59 | Object[] params = { a, new String("b"), new Object() }; | |
60 | ||
61 | // Levels are FINE, FINER, FINEST, INFO, SEVERE, WARNING | |
62 | logger.fine("A fine level message"); | |
63 | logger.finer("A finer level message"); | |
64 | logger.finest("A finest level message"); | |
65 | logger.info("A info level message"); | |
66 | logger.severe("A severe level message"); | |
67 | logger.warning("A warning level message"); | |
68 | logger.warning("Another warning level message"); | |
69 | logger.log(Level.WARNING, "A warning message using Logger.log()"); | |
70 | logger.log(Level.INFO, "A message with one parameter", a); | |
71 | logger.log(Level.INFO, "A message with parameters", params); | |
72 | } | |
73 | } |