Java Code Examples for org.apache.log4j.Logger#isInfoEnabled()

The following examples show how to use org.apache.log4j.Logger#isInfoEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelValidator.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Log issue.
 *
 * @param resource
 *          the resource
 * @param issue
 *          the issue
 * @param logger
 *          the logger
 */
private void logIssue(final Resource resource, final Issue issue, final Logger logger) {
  final String message = NLS.bind(MESSAGE_TEMPLATE, new Object[] {resource.getURI().lastSegment(), issue.getLineNumber(), issue.getMessage()});
  final Severity severity = issue.getSeverity();
  switch (severity) {
  case ERROR:
    logger.error(message);
    break;
  case WARNING:
    logger.warn(message);
    break;
  case INFO:
    if (logger.isInfoEnabled()) {
      logger.info(message);
    }
    break;

  default:
    break;
  }
}
 
Example 2
Source File: JobSetupUtil.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Changes the priority of a MapReduce job to VERY_HIGH. There doesn't seem to be a good way using the Hadoop API to do this, so we wait until there is map
 * progress reported (indicating the job is actually running) and then update its priority by executing a system command.
 *
 * @param job
 *            The {@link Job} whose priority is to be increased
 */
public static void changeJobPriority(Job job, Logger log) throws IOException {
    // Spin until we get some map progress, so that we can be sure the job is
    // registered with hadoop when we go to change its priority through the
    // command-line below.
    while (job.mapProgress() == 0) {
        // block
    }
    
    try {
        StringBuilder cmd = new StringBuilder();
        String hadoopHome = System.getProperty("HADOOP_HOME");
        if (hadoopHome == null) {
            log.debug("$HADOOP_HOME is not set; hopefully `hadoop` is on the classpath.");
        } else {
            cmd.append(hadoopHome).append('/');
        }
        cmd.append("hadoop job -set-priority ").append(job.getJobID()).append(" VERY_HIGH");
        
        log.info("Executing: " + cmd);
        Process pr = Runtime.getRuntime().exec(cmd.toString());
        
        if (log.isInfoEnabled()) {
            BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
            while (in.ready()) {
                log.info(in.readLine());
            }
        }
        
        int retCode = pr.waitFor();
        if (retCode == 0) {
            log.info("Successfully upgraded job priority.");
        } else {
            log.error("Hadoop process exited abnormally-- job may take a long time if system is saturated.");
        }
    } catch (Exception e) {
        log.error("This job may take a while on a system running at full ingest load.", e);
    }
}
 
Example 3
Source File: LoggerHelper.java    From niubi-job with Apache License 2.0 5 votes vote down vote up
public static void info(Class<?> clazz, String message, Throwable throwable) {
    AssertHelper.notNull(message, "message can't be null!");
    if (clazz == null) {
        clazz = LoggerHelper.class;
    }
    Logger logger = Logger.getLogger(clazz);
    if (logger.isInfoEnabled() && throwable == null) {
        logger.info(message);
    }
    if (logger.isInfoEnabled() && throwable != null) {
        logger.info(message, throwable);
    }
}
 
Example 4
Source File: Tools.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Log available script engines at INFO level.
 *
 * @param logger the logger instance used to log available script engines.
 */
public static void logAvailableScriptEngines(Logger logger) {
    if (!logger.isInfoEnabled()) {
        return;
    }

    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    List<ScriptEngineFactory> engineFactories = scriptEngineManager.getEngineFactories();

    StringBuilder buffer = new StringBuilder();
    buffer.append("Available script engines: ");

    int engineFactoriesCount = engineFactories.size();

    for (int i = 0; i < engineFactoriesCount; i++) {
        ScriptEngineFactory scriptEngineFactory = engineFactories.get(i);
        buffer.append(scriptEngineFactory.getEngineName());
        buffer.append(" (");
        buffer.append(scriptEngineFactory.getEngineVersion());
        buffer.append(")");

        if (i < engineFactoriesCount - 1) {
            buffer.append(", ");
        }
    }

    logger.info(buffer.toString());
}
 
Example 5
Source File: RequestAppender.java    From webdsl with Apache License 2.0 5 votes vote down vote up
private synchronized void forceLogLevels() {
	Logger bindLog = LogManager.getLogger(org.hibernate.type.descriptor.sql.BasicBinder.class);
	if(bindLog != null && !bindLog.isTraceEnabled()) {
		restoreBindLevel = bindLog.getLevel();
		restoreBind = true;
		bindLog.setLevel(Level.TRACE);
	}
	Logger sqlLog = LogManager.getLogger("org.hibernate.SQL");
	if(sqlLog != null && !sqlLog.isDebugEnabled()) {
		restoreSQLLevel = sqlLog.getLevel();
		restoreSQL = true;
		sqlLog.setLevel(Level.DEBUG);
	}
	Logger statLog = LogManager.getLogger(org.hibernate.stat.StatisticsImpl.class);
	if(statLog != null && !statLog.isInfoEnabled()) {
		restoreStatLevel = statLog.getLevel();
		restoreStat = true;
		statLog.setLevel(Level.INFO);
	}
	Logger loaderLog = LogManager.getLogger(org.hibernate.loader.Loader.class);
	if(loaderLog != null && !loaderLog.isTraceEnabled()) { // Trace for hydrated objects, Debug for result row
		restoreLoaderLevel = loaderLog.getLevel();
		restoreLoader = true;
		loaderLog.setLevel(Level.TRACE);
	}
	Logger jdbcLog = LogManager.getLogger(org.hibernate.jdbc.AbstractBatcher.class);
	if(jdbcLog != null && !jdbcLog.isDebugEnabled()) {
		restoreJdbcLevel = jdbcLog.getLevel();
		restoreJdbc = true;
		jdbcLog.setLevel(Level.DEBUG);
	}
}
 
Example 6
Source File: LogUtil.java    From zxl with Apache License 2.0 5 votes vote down vote up
public static void info(Logger logger, String message, Exception exception) {
	if (logger.isInfoEnabled()) {
		if (exception != null) {
			logger.info(message, exception);
		} else {
			logger.info(message);
		}
	}
}
 
Example 7
Source File: Dictionary.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Prints out the dictionary content into log at INFO level AND/OR into specified StringBuilder.
 * 
 * @param stringBuilder - if it's null, it's ignored; if it's not null, it's filled with dictionary content
 * @param logger - if it's null, it's ignored; if it's not null, it's used for logging dictionary content
 * @param message - first message introducing the content
 */
private void printContent(StringBuilder sb, Logger logger, String message) {
	if (!dictionary.isEmpty() && (sb != null || (logger != null && logger.isInfoEnabled())) ) { 
		if (logger != null)
			logger.info(message);
		if (sb != null) {
			sb.append(message).append("\n");
		}
		
		Set<String> keys = this.getKeys();
		for (String key : keys) {
			DictionaryEntry entry = this.getEntry(key);
			String entryValue = null;
			if (entry.getType().isFormatPropertiesSupported()) {
				Properties properties = entry.getType().formatProperties(entry.getValue());
				if (properties != null) {
					Level level = getGraph() != null && getGraph().getRuntimeContext() != null ? 
							getGraph().getRuntimeContext().getLogLevel() : null;
					entryValue = SafeLogUtils.getTruncatedMessage(level, Level.INFO, properties.toString());
				}
			} else {
				entryValue = "<unprintable_value>";
			}
			String s = "DictEntry:" + key + ":" + entry.getType().getTypeId() + ":" + entryValue;
			if (logger != null) {
				logger.info(s);
			}
			if (sb != null) {
				sb.append(s).append("\n");
			}
		}
	}
}
 
Example 8
Source File: BufferedLogger.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Wraps {@link Logger#info(String)}
 * 
 * @param pattern to format against
 * @param objs an array of objects used as parameters to the <code>pattern</code>
 */
public static final void info(Object ... objs) {
    Logger log = getLogger();
    if (log.isInfoEnabled()) {
        log.info(getMessage(objs));
    }
}
 
Example 9
Source File: SpliceLogUtils.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void info(Logger logger, String messageFormat,Object...args){
	if(logger.isInfoEnabled())logger.info(String.format(messageFormat,args));
}
 
Example 10
Source File: SpliceLogUtils.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void info(Logger logger, String message){
	if(logger.isInfoEnabled())logger.info(message);
}
 
Example 11
Source File: LoggerUtil.java    From heisenberg with Apache License 2.0 2 votes vote down vote up
/**
 * 生成<font color="blue">通知</font>级别日志<br>
 * 可处理任意多个输入参数,并避免在日志级别不够时字符串拼接带来的资源浪费
 * 
 * @param logger
 * @param obj
 */
public static void info(Logger logger, Object... obj) {
    if (logger.isInfoEnabled()) {
        logger.info(getLogString(obj));
    }
}