本文整理汇总了Java中org.apache.logging.log4j.Logger.error方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.error方法的具体用法?Java Logger.error怎么用?Java Logger.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.Logger
的用法示例。
在下文中一共展示了Logger.error方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
@Test
public void test() {
{
Logger logger = LogManager.getLogger("test.logger");
logger.error("This is an error!");
logger.error("This is another error!");
logger.error("This is a third error!");
}
assertThat(collector.getLogs()).hasSize(3)
.contains("This is an error!", "This is another error!", "This is a third error!");
List<LogEvent> rawLogs = (List<LogEvent>) collector.getRawLogs();
assertThat(rawLogs).hasSize(3);
assertTrue(rawLogs.stream().allMatch(l -> l.getLevel() == Level.ERROR));
}
示例2: handleDiscord4JException
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
public static void handleDiscord4JException(@NotNull Logger logger, @NotNull Exception e, @NotNull ICommand commandHandler, @NotNull IMessage message) {
try {
logger.error("{} failed to handle command, a {} was captured",
() -> commandHandler.getClass().getSimpleName(),
() -> e.getClass().getSimpleName());
logger.error(e);
if (e instanceof MissingPermissionsException) {
messageDeletionService().schedule(getMessageBuilder(message)
.appendContent(message.getAuthor().mention())
.appendContent(" I dont have the necessary permissions to execute that action,")
.appendContent(" please give me the following permissions and try again")
.appendContent(System.lineSeparator())
.appendContent(((MissingPermissionsException) e).getMissingPermissions().toString())
.send());
}
} catch (@NotNull RateLimitException | DiscordException | MissingPermissionsException e1) {
logger.error(e1);
}
}
示例3: publish
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
@Override
public void publish(LogRecord record) {
Logger logger = getLogger(record.getLoggerName());
Throwable exception = record.getThrown();
Level level = record.getLevel();
String message = getFormatter().formatMessage(record);
if (level == Level.SEVERE) {
logger.error(message, exception);
} else if (level == Level.WARNING) {
logger.warn(message, exception);
} else if (level == Level.INFO) {
logger.info(message, exception);
} else if (level == Level.CONFIG) {
logger.debug(message, exception);
} else {
logger.trace(message, exception);
}
}
示例4: testLocationInfoTest
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
public void testLocationInfoTest() throws IOException, UserException {
setupLogging("location_info");
final Logger testLogger = ESLoggerFactory.getLogger("test");
testLogger.error("This is an error message");
testLogger.warn("This is a warning message");
testLogger.info("This is an info message");
testLogger.debug("This is a debug message");
testLogger.trace("This is a trace message");
final String path =
System.getProperty("es.logs.base_path") +
System.getProperty("file.separator") +
System.getProperty("es.logs.cluster_name") +
".log";
final List<String> events = Files.readAllLines(PathUtils.get(path));
assertThat(events.size(), equalTo(5));
final String location = "org.elasticsearch.common.logging.EvilLoggerTests.testLocationInfoTest";
// the first message is a warning for unsupported configuration files
assertLogLine(events.get(0), Level.ERROR, location, "This is an error message");
assertLogLine(events.get(1), Level.WARN, location, "This is a warning message");
assertLogLine(events.get(2), Level.INFO, location, "This is an info message");
assertLogLine(events.get(3), Level.DEBUG, location, "This is a debug message");
assertLogLine(events.get(4), Level.TRACE, location, "This is a trace message");
}
示例5: createFrame
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
public static void createFrame(DefaultResourcePack mcDefaultResourcePack,
Logger logger) throws LWJGLException
{
// check if frame should be created
if(!isAutoMaximize() && !WurstBot.isEnabled())
return;
// create frame
frame = new JFrame("Minecraft " + WMinecraft.DISPLAY_VERSION);
// add LWJGL
Canvas canvas = new Canvas();
canvas.setBackground(new Color(16, 16, 16));
Display.setParent(canvas);
Minecraft mc = Minecraft.getMinecraft();
canvas.setSize(mc.displayWidth, mc.displayHeight);
frame.add(canvas);
// configure frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
// add icons
InputStream icon16 = null;
InputStream icon32 = null;
try
{
icon16 = mcDefaultResourcePack.getInputStreamAssets(
new ResourceLocation("icons/icon_16x16.png"));
icon32 = mcDefaultResourcePack.getInputStreamAssets(
new ResourceLocation("icons/icon_32x32.png"));
ArrayList<BufferedImage> icons = new ArrayList<>();
icons.add(ImageIO.read(icon16));
icons.add(ImageIO.read(icon32));
frame.setIconImages(icons);
}catch(Exception e)
{
logger.error("Couldn't set icon", e);
}finally
{
IOUtils.closeQuietly(icon16);
IOUtils.closeQuietly(icon32);
}
// show frame
if(!WurstBot.isEnabled())
frame.setVisible(true);
}
示例6: test03
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
@Test
public void test03() {
// Logger logger = LogManager.getFormatterLogger();
Logger logger = LogManager.getLogger();
String name = "李志伟";
Date birthday = new Date();
logger.debug("用户名称:[{}], 日期:[{}]", name, birthday);
logger.info("用户名称:[{}], 日期:[{}]", name, birthday);
logger.warn("用户名称:[{}], 日期:[{}]", name, birthday);
logger.error("用户名称:[{}], 日期:[{}]", name, birthday);
logger.fatal("用户名称:[{}], 日期:[{}]", name, birthday);
logger.error("异常信息提示", new RuntimeException("异常信息"));
LogManager.shutdown();
}
示例7: test04
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
@Test
public void test04() {
Logger logger = LogManager.getLogger();
String name = "李志伟";
Date birthday = new Date();
for (int i = 0; i < 10000; i++) {
logger.debug("次数[{}] 用户名称:[{}], 日期:[{}]", i, name, birthday);
logger.info("次数[{}] 用户名称:[{}], 日期:[{}]", i, name, birthday);
logger.warn("次数[{}] 用户名称:[{}], 日期:[{}]", i, name, birthday);
logger.error("次数[{}] 用户名称:[{}], 日期:[{}]", i, name, birthday);
logger.fatal("次数[{}] 用户名称:[{}], 日期:[{}]", i, name, birthday);
}
LogManager.shutdown();
}
示例8: test
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
@Test
public void test() {
{
Logger logger = LogManager.getLogger("test.logger");
logger.error("This is an error!");
logger.error("This is another error!");
}
assertThat(collector.getLogs())
.hasSize(2)
.contains("This is an error!", "This is another error!");
}
示例9: testLogs
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
/**
* @author wasiq.bhamla
* @since 17-Jun-2017 6:18:03 PM
*/
@Test
public void testLogs () {
final Logger log = LogManager.getLogger (TestLogging.class);
log.info ("Testing info...");
log.warn ("Testing warn...");
log.error ("Testing error...");
log.debug ("Testing debug...");
log.trace ("Testing trace...");
log.fatal ("Testing fatal...");
}
示例10: logError
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
public static int logError(final String errorMsg,
final Logger logger) {
logger.error(errorMsg);
return logError(errorMsg);
}
示例11: onFatalUncaught
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
void onFatalUncaught(final String threadName, final Throwable t) {
final Logger logger = Loggers.getLogger(ElasticsearchUncaughtExceptionHandler.class, loggingPrefixSupplier.get());
logger.error(
(org.apache.logging.log4j.util.Supplier<?>)
() -> new ParameterizedMessage("fatal error in thread [{}], exiting", threadName), t);
}
示例12: error
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
public static void error(Class<?> clazz, Throwable t) {
final Logger logger = LogManager.getLogger(clazz);
logger.error("Unexpected error has occurred: {}", t.getMessage(), t);
}
示例13: testLogOutput
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
/**
* Verifies that writing to a Log4j logger will end up in the LogWriter's output.
*/
@Test
public final void testLogOutput() throws IOException {
// Create the appender
final StringWriter stringWriter = new StringWriter();
final PureLogWriter logWriter =
new PureLogWriter(InternalLogWriter.FINEST_LEVEL, new PrintWriter(stringWriter), "");
final AppenderContext[] contexts = new AppenderContext[2];
contexts[0] = LogService.getAppenderContext(); // root context
contexts[1] = LogService.getAppenderContext(LogService.BASE_LOGGER_NAME); // "org.apache"
// context
this.appender =
LogWriterAppender.create(contexts, LogService.MAIN_LOGGER_NAME, logWriter, null);
final Logger logger = LogService.getLogger();
// set the level to TRACE
Configurator.setLevel(LogService.BASE_LOGGER_NAME, Level.TRACE);
Configurator.setLevel(LogService.MAIN_LOGGER_NAME, Level.TRACE);
assertEquals(Level.TRACE, logger.getLevel());
logger.trace("TRACE MESSAGE");
assertTrue(Pattern.compile(".*\\[finest .*TRACE MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.debug("DEBUG MESSAGE");
assertTrue(Pattern.compile(".*\\[fine .*DEBUG MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.info("INFO MESSAGE");
assertTrue(Pattern.compile(".*\\[info .*INFO MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.warn("ExpectedStrings: WARNING MESSAGE");
assertTrue(Pattern.compile(".*\\[warning .*WARNING MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.error("ExpectedStrings: ERROR MESSAGE");
assertTrue(Pattern.compile(".*\\[error .*ERROR MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.fatal("ExpectedStrings: FATAL MESSAGE");
assertTrue(Pattern.compile(".*\\[severe .*FATAL MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
final Logger lowerLevelLogger =
LogService.getLogger(LogService.BASE_LOGGER_NAME + ".subpackage");
lowerLevelLogger.fatal("ExpectedStrings: FATAL MESSAGE");
assertTrue(Pattern.compile(".*\\[severe .*FATAL MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
this.appender.destroy();
assertFalse(Configurator.getLoggerConfig(LogService.BASE_LOGGER_NAME).getAppenders()
.containsKey(this.appender.getName()));
}