1 /* 2 * Copyright 2012 smartics, Kronseder & Reiner GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package de.smartics.ci.comm; 17 18 import org.slf4j.Logger; 19 20 /** 21 * Helper for logging. 22 */ 23 public final class LogHelper 24 { 25 // ********************************* Fields ********************************* 26 27 // --- constants ------------------------------------------------------------ 28 29 // --- members -------------------------------------------------------------- 30 31 // ****************************** Initializer ******************************* 32 33 // ****************************** Constructors ****************************** 34 35 private LogHelper() 36 { 37 38 } 39 40 // ****************************** Inner Classes ***************************** 41 42 // ********************************* Methods ******************************** 43 44 // --- init ----------------------------------------------------------------- 45 46 // --- get&set -------------------------------------------------------------- 47 48 // --- business ------------------------------------------------------------- 49 50 /** 51 * Log on info level when appropriate. 52 * 53 * @param logger the logger to use for logging. 54 * @param logLevel the level that is activated by the configuration. 55 * @param message the message to log. 56 */ 57 public static void logInfo(final Logger logger, final LogLevel logLevel, 58 final String message) 59 { 60 logInfo(logger, logLevel, message, null); 61 } 62 63 /** 64 * Log on info level when appropriate. 65 * 66 * @param logger the logger to use for logging. 67 * @param logLevel the level that is activated by the configuration. 68 * @param message the message to log. 69 * @param t the throwable that shall be logged with the message. 70 */ 71 public static void logInfo(final Logger logger, final LogLevel logLevel, 72 final String message, final Throwable t) 73 { 74 if (logLevel.isQuiet()) 75 { 76 return; 77 } 78 logger.info(message, t); 79 } 80 81 /** 82 * Log on debug level when appropriate. 83 * 84 * @param logger the logger to use for logging. 85 * @param logLevel the level that is activated by the configuration. 86 * @param message the message to log. 87 */ 88 public static void logDebug(final Logger logger, final LogLevel logLevel, 89 final String message) 90 { 91 logDebug(logger, logLevel, message, null); 92 } 93 94 /** 95 * Log on debug level when appropriate. 96 * 97 * @param logger the logger to use for logging. 98 * @param logLevel the level that is activated by the configuration. 99 * @param message the message to log. 100 * @param t the throwable that shall be logged with the message. 101 */ 102 public static void logDebug(final Logger logger, final LogLevel logLevel, 103 final String message, final Throwable t) 104 { 105 if (logLevel.isQuiet()) 106 { 107 return; 108 } 109 else if (logLevel.isNormal()) 110 { 111 return; 112 } 113 logger.debug(message, t); 114 } 115 116 /** 117 * Log on warn level when appropriate. 118 * 119 * @param logger the logger to use for logging. 120 * @param logLevel the level that is activated by the configuration. 121 * @param message the message to log. 122 */ 123 public static void logWarn(final Logger logger, final LogLevel logLevel, 124 final String message) 125 { 126 logWarn(logger, logLevel, message, null); 127 } 128 129 /** 130 * Log on warn level when appropriate. 131 * 132 * @param logger the logger to use for logging. 133 * @param logLevel the level that is activated by the configuration. 134 * @param message the message to log. 135 * @param t the throwable that shall be logged with the message. 136 */ 137 public static void logWarn(final Logger logger, final LogLevel logLevel, 138 final String message, final Throwable t) 139 { 140 if (logLevel.isQuiet()) 141 { 142 return; 143 } 144 logger.warn(message, t); 145 } 146 147 /** 148 * Log on errror level when appropriate. 149 * 150 * @param logger the logger to use for logging. 151 * @param logLevel the level that is activated by the configuration. 152 * @param message the message to log. 153 */ 154 public static void logError(final Logger logger, final LogLevel logLevel, 155 final String message) 156 { 157 logError(logger, logLevel, message, null); 158 } 159 160 /** 161 * Log on error level when appropriate. 162 * 163 * @param logger the logger to use for logging. 164 * @param logLevel the level that is activated by the configuration. 165 * @param message the message to log. 166 * @param t the throwable that shall be logged with the message. 167 */ 168 public static void logError(final Logger logger, final LogLevel logLevel, 169 final String message, final Throwable t) 170 { 171 logger.error(message, t); 172 } 173 174 // --- object basics -------------------------------------------------------- 175 176 }