当前位置: 首页>>代码示例>>Java>>正文


Java Logger.error方法代码示例

本文整理汇总了Java中org.apache.log4j.Logger.error方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.error方法的具体用法?Java Logger.error怎么用?Java Logger.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.log4j.Logger的用法示例。


在下文中一共展示了Logger.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.log4j.Logger; //导入方法依赖的package包/类
public static void main(String args[])
{
	Logger logger = Logger.getLogger(com.dytech.common.log4j.DailySizeRollingAppender.class);
	do
	{
		logger.info("This is an info statement");
		logger.warn("This is a warning");
		logger.error("This is an error");
		try
		{
			throw new Exception();
		}
		catch( Exception ex )
		{
			logger.fatal("This is fatal", ex);
		}
	}
	while( true );
}
 
开发者ID:equella,项目名称:Equella,代码行数:20,代码来源:DailySizeRollingAppender.java

示例2: saveEntry

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * Saves an entry to file
 * @param entry
 * @param dbName usually scrapig
 * @return true if success
 */
public static boolean saveEntry(DBEntry entry, String dbName){

    if(entry == null || !entry.isValid())
        return false;

    Logger log = Logger.getLogger(DAO.class);

    MongoDatabase db = MongoDB.INSTANCE.getDatabase(dbName);

    String collectionName = getCollectionName(entry);


    MongoCollection collection = db.getCollection(collectionName,BasicDBObject.class);

    try {
        collection.insertOne(entry);
        return true;
    }
    catch (MongoWriteException ex){
        if (ex.getCode() != 11000) // Ignore errors about duplicates
            log.error(ex.getError().getMessage());
        return false;
    }

}
 
开发者ID:gidim,项目名称:Babler,代码行数:32,代码来源:DAO.java

示例3: execute

import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
	if (isEnabled()) {
		if (super.execute(javascriptContext, scope)) {
			Logger log = engine ? Engine.logEngine : Engine.logContext;
			if(level.equals(Level.WARN.toString()) && log.isEnabledFor(Level.WARN))
				log.warn(getEvalString(javascriptContext, scope));
			else if(level.equals(Level.INFO.toString()) && log.isInfoEnabled())
				log.info(getEvalString(javascriptContext, scope));
			else if(level.equals(Level.DEBUG.toString()) && log.isDebugEnabled())
				log.debug(getEvalString(javascriptContext, scope));
			else if(level.equals(Level.TRACE.toString()) && log.isTraceEnabled())
				log.trace(getEvalString(javascriptContext, scope));
			else if(level.equals(Level.ERROR.toString()) && log.isEnabledFor(Level.ERROR))
				log.error(getEvalString(javascriptContext, scope));
			return true;
		}
	}
	return false;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:21,代码来源:LogStatement.java

示例4: main

import org.apache.log4j.Logger; //导入方法依赖的package包/类
public static void main(String args[])
{
	Logger logger = Logger.getLogger(DailySizeRollingAppender.class);
	do
	{
		logger.info("This is an info statement");
		logger.warn("This is a warning");
		logger.error("This is an error");
		try
		{
			throw new Exception();
		}
		catch( Exception ex )
		{
			logger.fatal("This is fatal", ex);
		}
	}
	while( true );
}
 
开发者ID:equella,项目名称:Equella,代码行数:20,代码来源:DailySizeRollingAppender.java

示例5: logOnServer

import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Override
public String logOnServer(LogRecord record) {
	try {
		if (iDeobfuscator != null && record.getThrown() != null)
			iDeobfuscator.deobfuscateStackTrace(record.getThrown(), getPermutationStrongName());
		Logger logger = Logger.getLogger(record.getLoggerName());
		if (record.getLevel().intValue() >= Level.SEVERE.intValue()) {
			logger.error(record.getMessage(), record.getThrown());
		} else if (record.getLevel().intValue() >= Level.WARNING.intValue()) {
			logger.warn(record.getMessage(), record.getThrown());
		} else if (record.getLevel().intValue() >= Level.INFO.intValue()) {
			logger.info(record.getMessage(), record.getThrown());
		} else if (record.getLevel().intValue() >= Level.FINE.intValue()) {
			logger.debug(record.getMessage(), record.getThrown());
		} else {
			logger.trace(record.getMessage(), record.getThrown());
		}
		return null;
	} catch (Exception e) {
		sLogger.warn("Logging failed, reason: " + e.getMessage(), e);
	}
	return null;
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:24,代码来源:UniTimeRemoteLoggingService.java

示例6: log

import org.apache.log4j.Logger; //导入方法依赖的package包/类
private void log(LogMessage logMessage, LogLevel level, String loggerName) {
	String logMessageString;
	if (config.getLogInPlainString()) {
		StringBuilder sb = new StringBuilder();
		sb.append("[CID: ").append(logMessage.getCorrelationId());
		if (StringUtils.isNotBlank(logMessage.getCorrelationIdLocal())) {
			sb.append(" CID.Local: ").append(logMessage.getCorrelationIdLocal());
		}
		sb.append("] ").append(logMessage.getMessage());
		String varsInString = LogHelper.variablesToString(logMessage.getVariables(), config.getLogVariableType());
		if (varsInString.length() > 0) {
			sb.append(" [").append(varsInString).append("]");
		}
		if (logMessage.getThrowable() != null) {
			Throwable t = logMessage.getThrowable();
			sb.append("\nException: ").append(ExceptionUtils.getMessage(t)).append(" ")
					.append(ExceptionUtils.getStackTrace(logMessage.getThrowable()));
			sb.append("");
		}
		logMessageString = sb.toString();
	} else {
		TimeZone tz = TimeZone.getTimeZone("UTC");
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
		df.setTimeZone(tz);
		logMessage.setTimestamp(df.format(new Date()));
		logMessage.setLevel(level.toString());
		logMessage.setLogger(loggerName);
		logMessage.setThread(Thread.currentThread().toString());
		Gson gson = new GsonBuilder().disableHtmlEscaping().disableHtmlEscaping().create();
		logMessageString = gson.toJson(logMessage);
	}

	Logger logger = LogManager.getLogger(loggerName);
	switch (level) {
	case INFO:
		logger.info(logMessageString);
		break;
	case ERROR:
		logger.error(logMessageString);
		break;
	case FATAL:
		logger.fatal(logMessageString);
		break;
	case DEBUG:
		logger.debug(logMessageString);
		break;
	}
}
 
开发者ID:iac-m,项目名称:mule-json-logger,代码行数:49,代码来源:JsonLogger.java

示例7: flushLogs

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * From http://stackoverflow.com/a/3187802/42171
 */
public static void flushLogs(Logger logger) {
    Logger root = Logger.getRootLogger();
    Set<FileAppender> flushed = new HashSet<FileAppender>();
    try {
        for (Appender appender : CollectionUtil.iterable(logger.getAllAppenders(), Appender.class)) {
            if (appender instanceof FileAppender) {
                FileAppender fileAppender = (FileAppender)appender;
                synchronized (fileAppender) {
                    if (!flushed.contains(fileAppender) && !fileAppender.getImmediateFlush()) {
                        root.info(String.format("Appender %s.%s is not doing an immediateFlush",
                                  logger.getName(), appender.getName()));
                        fileAppender.setImmediateFlush(true);
                        logger.info("FLUSH");
                        fileAppender.setImmediateFlush(false);
                        flushed.add(fileAppender);
                    } else {
                        root.info(String.format("Appender %s.%s is doing an immediateFlush",
                                  logger.getName(), appender.getName()));
                    }
                } // SYNCH
            } else {
                root.debug(String.format("Unable to flush non-file appender %s.%s",
                           logger.getName(), appender.getName()));
            }
        } // FOR (appender)
    } catch (Throwable ex) {
        root.error("Failed flushing logs for " + logger, ex);
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:33,代码来源:LoggerUtil.java

示例8: buildListOfSupportedLanguageCodesFromLanguageNames

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * Generates a list of support languages by this classifier
 * @param langs a list of language names (not codes). For example English, Hebrew, Spanish
 */
protected void buildListOfSupportedLanguageCodesFromLanguageNames(String [] langs){
    this.supportedLanguages = new ArrayList<>();
     Logger log = Logger.getLogger(LanguageClassifier.class);
    for(String lang : langs){
        try {
            supportedLanguages.add(LanguageCode.convertLanguageNameToCode(lang));
        } catch (Exception e) {
            log.error(e);
        }
    }
}
 
开发者ID:gidim,项目名称:Babler,代码行数:16,代码来源:LanguageClassifier.java

示例9: load

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * reads properties and stores them in the Hashtable
 * 
 * @param is InputStream reading properties
 */
public void load(InputStream is) {
	Logger log = Logger.getLogger(MyProperties.class);
	int lineCounter = 0;
	String line;
	String[] prop = new String[2];
	int i;
	InputStreamReader isr = new InputStreamReader(is);
	BufferedReader br = new BufferedReader(isr);
	try {
		while ((line = br.readLine()) != null) {
			lineCounter++;
			i = 0;
			line = line.replaceAll("<","_").replaceAll(">","_");
			String[] tokens = line.split("\\s");
			for(String token : tokens) {
				if(!token.equals("")) {
					prop[i] = token;
					i++;
					if(i == 2) {
						break;
					}
				}
			}
			this.put(prop[0],prop[1]);
		}
		br.close();
		isr.close();
	} catch (IOException ioe) {
		log.error(ioe);
	}
}
 
开发者ID:gidim,项目名称:Babler,代码行数:37,代码来源:MyProperties.java

示例10: loadCategories

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * clears the categories-collection and fills it with the FingerPrints given
 * in the configuration file.
 */
private void loadCategories() {
	this.categories.clear();
	Logger log = Logger.getLogger(TextCategorizer.class);
	try {
		MyProperties properties = new MyProperties();
		if (confFile == null) {
			properties.load(TextCategorizer.class.getClassLoader()
					.getResourceAsStream(jarConfFile));
		} else {
			properties.load(new FileInputStream(confFile.toString()));
		}
		for (Entry<String, String> entry : properties.entrySet()) {
			FingerPrint fp;
			if (confFile == null) {
				fp = new FingerPrint(TextCategorizer.class.getClassLoader()
						.getResourceAsStream(entry.getKey()));
			} else {
				fp = new FingerPrint(BabelConfig.getResourcesPath() + entry.getKey());
			}
			fp.setCategory(entry.getValue());
			this.categories.add(fp);
               this.supportedLanguages.add(new LanguageCode(entry.getValue(), LanguageCode.CodeTypes.ISO_639_2));
		}
	} catch (FileNotFoundException fnfe) {
		log.error(fnfe);
	}
}
 
开发者ID:gidim,项目名称:Babler,代码行数:32,代码来源:TextCategorizer.java

示例11: logError

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * Log an error message.
 *
 * @param message --
 *            error message to log.
 *
 */
public void logError(String message) {
    Logger logger = this.getLogger();
    String newMsg = this.enhanceMessage(message);
    countLines(newMsg);
    logger.error(newMsg);

}
 
开发者ID:YunlongYang,项目名称:LightSIP,代码行数:15,代码来源:LogWriter.java

示例12: stepExecute

import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Override
protected boolean stepExecute(Context javascriptContext, Scriptable scope) throws EngineException {
	if (isEnabled()) {
		if (super.stepExecute(javascriptContext, scope)) {
			Logger log = null;
			if(logger.equals(Engine.logEngine.getName())) 
				log = Engine.logEngine;
			else if(logger.equals(Engine.logContext.getName()))
				log = Engine.logContext;
			else if(logger.equals(Engine.logUser.getName()))
				log = Engine.logUser;
			else if(logger.equals(Engine.logAudit.getName())) 
				log = Engine.logAudit;
			if(level.equals(Level.WARN.toString()) && log.isEnabledFor(Level.WARN))
				log.warn(getEvalString(javascriptContext, scope));
			else if(level.equals(Level.INFO.toString()) && log.isInfoEnabled())
				log.info(getEvalString(javascriptContext, scope));
			else if(level.equals(Level.DEBUG.toString()) && log.isDebugEnabled())
				log.debug(getEvalString(javascriptContext, scope));
			else if(level.equals(Level.TRACE.toString()) && log.isTraceEnabled())
				log.trace(getEvalString(javascriptContext, scope));
			else if(level.equals(Level.ERROR.toString()) && log.isEnabledFor(Level.ERROR))
				log.error(getEvalString(javascriptContext, scope));
			return true;
		}
	}
	return false;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:29,代码来源:LogStep.java

示例13: error

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * Error 输出
 * @param clazz  	目标.Class
 * @param message	输出信息
 * @param e			异常类
 */
public static void error(Class<? extends Object> clazz ,String message,Exception e){
	Logger logger = Logger.getLogger(clazz);
	if(null == e){
		logger.error(message);
		return ;
	}
	logger.error(message, e);
}
 
开发者ID:butter-fly,项目名称:belling-admin,代码行数:15,代码来源:LoggerUtils.java

示例14: error

import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
 * Error 输出
 * @param clazz  	目标.Class
 * @param message	输出信息
 * @param e			异常类
 */
public static void error(Class<? extends Object> clazz ,String message,Exception e){
    Logger logger = Logger.getLogger(clazz);
    if(null == e){
        logger.error(message);
        return ;
    }
    logger.error(message, e);
}
 
开发者ID:Topview-us,项目名称:school-website,代码行数:15,代码来源:LoggerUtils.java

示例15: extractUserParameter

import org.apache.log4j.Logger; //导入方法依赖的package包/类
protected boolean extractUserParameter(
                                        String description,
                                        String valueToMatch,
                                        String text ) throws XmlUtilitiesException {

    Logger log = Logger.getLogger(this.getClass());

    // apply the current user parameters
    valueToMatch = XmlUtilities.applyUserParameters(valueToMatch);

    //FIXME: Limited to one variable only
    int findex = valueToMatch.indexOf("${=") + "${=".length();
    String userParameterName = valueToMatch.substring(findex, valueToMatch.indexOf("}", findex));

    // TODO check the regex accuracy. currently escaped *, ., *, ^, -, ?  and $, {, }
    String patternToMatch = valueToMatch.replace("(", "\\(")
                                        .replace(")", "\\)")
                                        .replace("*", "\\*")
                                        .replace(".", "\\.")
                                        .replace("^", "\\^")
                                        .replace("-", "\\-")
                                        .replace("|", "\\|")
                                        .replace("?", "\\?")
                                        .replaceAll("\\$\\{\\=.*\\}", "(.*)");
    // escape $ { and }, and ${RANDOM} after we have replaced ${=...}
    patternToMatch = patternToMatch.replace("${RANDOM}", ".*")
                                   // match this place as value for the variable
                                   .replace("$", "\\$")
                                   .replace("{", "\\{")
                                   .replace("}", "\\}");

    Matcher matcher = Pattern.compile(patternToMatch).matcher(text);
    if (matcher.find() && matcher.groupCount() == 1) {
        String userParameterValue = matcher.group(1);
        if (log.isDebugEnabled()) {
            log.debug("Extracted new user parameter from " + description + ": '" + userParameterName
                      + "' = '" + userParameterValue + "'");
        }
        ThreadContext.setAttribute(userParameterName, userParameterValue);
        return true;
    } else {
        log.error("Could not extract the expected user parameter '" + userParameterName + "' from "
                  + text + " for " + toString());
        return false;
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:47,代码来源:ResponseMatcher.java


注:本文中的org.apache.log4j.Logger.error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。