| 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 | |
| 19 | package org.lttng.ust.agent.utils; |
| 20 | |
| 21 | import java.io.IOException; |
| 22 | |
| 23 | import org.apache.log4j.Level; |
| 24 | import org.apache.log4j.Logger; |
| 25 | import org.lttng.ust.agent.log4j.LttngLogAppender; |
| 26 | |
| 27 | /** |
| 28 | * Utility methods for log4j tests |
| 29 | */ |
| 30 | public final class Log4jTestUtils { |
| 31 | |
| 32 | private Log4jTestUtils() { |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Check the the Log4j native library is available, effectively allowing |
| 37 | * LTTng Log4j appenders to be used. |
| 38 | * |
| 39 | * @return True if Log4j works fine, false if it does not. |
| 40 | */ |
| 41 | public static boolean checkForLog4jLibrary() { |
| 42 | try { |
| 43 | LttngLogAppender testAppender = new LttngLogAppender(); |
| 44 | testAppender.close(); |
| 45 | } catch (SecurityException | IOException e) { |
| 46 | e.printStackTrace(); |
| 47 | return false; |
| 48 | } |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Send 10 dummy events through the provided logger |
| 54 | * |
| 55 | * @param logger |
| 56 | * The logger to use to send events |
| 57 | */ |
| 58 | public static void send10Events(Logger logger) { |
| 59 | // Levels/priorities are DEBUG, ERROR, FATAL, INFO, TRACE, WARN |
| 60 | logger.debug("Debug message. Lost among so many."); |
| 61 | logger.debug("Debug message with a throwable", new IOException()); |
| 62 | logger.error("Error messsage. This might be bad."); |
| 63 | logger.error("Error message with a throwable", new IOException()); |
| 64 | logger.fatal("A fatal message. You are already dead."); |
| 65 | logger.info("A info message. Lol, who cares."); |
| 66 | logger.trace("A trace message. No, no *that* trace"); |
| 67 | logger.warn("A warn message. Yellow underline."); |
| 68 | logger.log(Level.DEBUG, "A debug message using .log()"); |
| 69 | logger.log(Level.ERROR, "A error message using .log()"); |
| 70 | } |
| 71 | } |