| 1 | /* |
| 2 | * Copyright (C) 2015 - Michael Jeanson <mjeanson@efficios.com> |
| 3 | * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License, version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., 51 |
| 16 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | */ |
| 18 | |
| 19 | import java.io.IOException; |
| 20 | import java.lang.Integer; |
| 21 | import java.util.logging.Handler; |
| 22 | import java.util.logging.Logger; |
| 23 | import java.util.logging.Level; |
| 24 | |
| 25 | import org.lttng.ust.agent.jul.LttngLogHandler; |
| 26 | |
| 27 | public class JTestLTTng { |
| 28 | |
| 29 | /** |
| 30 | * Application start |
| 31 | * |
| 32 | * @param args |
| 33 | * Command-line arguments |
| 34 | * @throws IOException |
| 35 | * @throws InterruptedException |
| 36 | */ |
| 37 | public static void main(String args[]) throws IOException, InterruptedException { |
| 38 | |
| 39 | Logger lttng = Logger.getLogger("JTestLTTng"); |
| 40 | Logger lttng2 = Logger.getLogger("JTestLTTng2"); |
| 41 | |
| 42 | int nrIter = Integer.parseInt(args[0]); |
| 43 | int waitTime = Integer.parseInt(args[1]); |
| 44 | int fire_finest_tp = 0; |
| 45 | int fire_second_tp = 0; |
| 46 | |
| 47 | if (args.length > 2) { |
| 48 | fire_finest_tp = Integer.parseInt(args[2]); |
| 49 | } |
| 50 | if (args.length > 3) { |
| 51 | fire_second_tp = Integer.parseInt(args[3]); |
| 52 | } |
| 53 | |
| 54 | /* Instantiate a LTTngLogHandler object, and attach it to our loggers */ |
| 55 | Handler lttngHandler = new LttngLogHandler(); |
| 56 | lttng.addHandler(lttngHandler); |
| 57 | lttng2.addHandler(lttngHandler); |
| 58 | |
| 59 | lttng.setLevel(Level.FINEST); |
| 60 | |
| 61 | for (int iter = 0; iter < nrIter; iter++) { |
| 62 | lttng.info("JUL tp fired!"); |
| 63 | if (fire_finest_tp == 1) { |
| 64 | /* Third arg, trigger finest TP. */ |
| 65 | lttng.finest("JUL FINEST tp fired"); |
| 66 | } |
| 67 | Thread.sleep(waitTime); |
| 68 | } |
| 69 | |
| 70 | if (fire_second_tp == 1) { |
| 71 | lttng2.info("JUL second logger fired"); |
| 72 | } |
| 73 | |
| 74 | /* |
| 75 | * Do not forget to close() all handlers so that the agent can shutdown |
| 76 | * and the session daemon socket gets cleaned up explicitly. |
| 77 | */ |
| 78 | lttngHandler.close(); |
| 79 | } |
| 80 | } |