本文整理汇总了Java中org.apache.log4j.Logger.fatal方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.fatal方法的具体用法?Java Logger.fatal怎么用?Java Logger.fatal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.Logger
的用法示例。
在下文中一共展示了Logger.fatal方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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 );
}
示例3: 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;
}
}
示例4: logFatalError
import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
* Log an error message.
*
* @param message --
* error message to log.
*/
public void logFatalError(String message) {
Logger logger = this.getLogger();
String newMsg = this.enhanceMessage(message);
countLines(newMsg);
logger.fatal(newMsg);
}
示例5: publish
import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Override
public void publish(LogRecord record)
{
Logger logger = Logger.getLogger(record.getLoggerName());
Level level = record.getLevel();
String message = record.getMessage();
try
{
message = MessageFormat.format(record.getMessage(), record.getParameters());
}
catch( IllegalArgumentException ignore )
{
// message will possibly have placeholder format for its
// parameters, such as
// "frog went {0} on a {1} day", "walking", "summer's",
// If format fails, send message in the raw.
}
if( record.getThrown() != null && !Check.isEmpty(record.getThrown().getLocalizedMessage()) )
{
message += '\n' + record.getThrown().getLocalizedMessage();
}
if( Level.SEVERE.equals(level) )
{
logger.fatal(message);
}
else if( Level.INFO.equals(level) )
{
logger.info(message);
}
else if( Level.WARNING.equals(level) )
{
logger.warn(message);
}
else if( Level.FINE.equals(level) || Level.FINER.equals(level) || Level.FINEST.equals(level) )
{
logger.trace(record);
}
}