本文整理汇总了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 );
}
示例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;
}
}
示例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;
}
示例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 );
}
示例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;
}
示例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;
}
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
}