本文整理了Java中jodd.log.Logger.error()
方法的一些代码示例,展示了Logger.error()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Logger.error()
方法的具体详情如下:
包路径:jodd.log.Logger
类名称:Logger
方法名:error
[英]Logs a message at ERROR level.
[中]在错误级别记录消息。
代码示例来源:origin: oblac/jodd
/**
* Logs a message at ERROR level.
*/
default void error(final Supplier<String> messageSupplier) {
if (isErrorEnabled()) {
error(messageSupplier.get());
}
}
代码示例来源:origin: oblac/jodd
/**
* Logs a message at ERROR level.
*/
default void error(final Supplier<String> messageSupplier, final Throwable throwable) {
if (isErrorEnabled()) {
error(messageSupplier.get(), throwable);
}
}
代码示例来源:origin: oblac/jodd
/**
* Checks if connection provider can return a connection.
*/
protected void checkConnectionProvider() {
final Connection connection = connectionProvider.getConnection();
try {
final DatabaseMetaData databaseMetaData = connection.getMetaData();
String name = databaseMetaData.getDatabaseProductName();
String version = databaseMetaData.getDatabaseProductVersion();
if (log.isInfoEnabled()) {
log.info("Connected to database: " + name + " v" + version);
}
} catch (SQLException sex) {
log.error("DB connection failed: ", sex);
} finally {
connectionProvider.closeConnection(connection);
}
}
代码示例来源:origin: oblac/jodd
@Test
void testErrorWithThrowable() {
//given
throwable = mock(Throwable.class);
//when
logger.error(LoggerConstants.ERROR_MESSAGE, throwable);
//then
verify(log).error(LoggerConstants.ERROR_MESSAGE, throwable);
}
代码示例来源:origin: oblac/jodd
@Test
void testErrorWithThrowable() {
//given
throwable = mock(Throwable.class);
//when
logger.error(LoggerConstants.ERROR_MESSAGE, throwable);
//then
verify(log).error(LoggerConstants.ERROR_MESSAGE, throwable);
}
代码示例来源:origin: oblac/jodd
@Test
void testErrorWithThrowable() {
//given
throwable = mock(Throwable.class);
//when
logger.error(LoggerConstants.ERROR_MESSAGE, throwable);
//then
verify(log).error(LoggerConstants.ERROR_MESSAGE, throwable);
}
代码示例来源:origin: oblac/jodd
@Test
void testErrorWithThrowable() {
//given
throwable = mock(Throwable.class);
//when
logger.error(LoggerConstants.ERROR_MESSAGE, throwable);
//then
verify(log).log(java.util.logging.Level.SEVERE, LoggerConstants.ERROR_MESSAGE, throwable);
}
代码示例来源:origin: oblac/jodd
/**
* Initializes Decora filter. Loads manager and parser from init parameters.
*/
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
String decoraManagerClass = filterConfig.getInitParameter(PARAM_DECORA_MANAGER);
if (decoraManagerClass != null) {
try {
Class decoraManagerType = ClassLoaderUtil.loadClass(decoraManagerClass);
decoraManager = (DecoraManager) ClassUtil.newInstance(decoraManagerType);
} catch (Exception ex) {
log.error("Unable to load Decora manager class: " + decoraManagerClass, ex);
throw new ServletException(ex);
}
} else {
decoraManager = createDecoraManager();
}
String decoraParserClass = filterConfig.getInitParameter(PARAM_DECORA_PARSER);
if (decoraParserClass != null) {
try {
Class decoraParserType = ClassLoaderUtil.loadClass(decoraParserClass);
decoraParser = (DecoraParser) ClassUtil.newInstance(decoraParserType);
} catch (Exception ex) {
log.error("Unable to load Decora parser class: " + decoraParserClass, ex);
throw new ServletException(ex);
}
} else {
decoraParser = createDecoraParser();
}
}
代码示例来源:origin: oblac/jodd
/**
* Creates and starts new <code>Madvoc</code> web application.
* <code>Madvoc</code> instance is stored in servlet context.
* Important: <code>servletContext</code> may be <code>null</code>,
* when web application is run out from container.
*/
@SuppressWarnings("InstanceofCatchParameter")
public WebApp startWebApplication(final ServletContext servletContext) {
try {
WebApp webApp = _start(servletContext);
log.info("Madvoc is up and running.");
return webApp;
}
catch (Exception ex) {
if (log != null) {
log.error("Madvoc startup failure.", ex);
} else {
ex.printStackTrace();
}
if (ex instanceof MadvocException) {
throw (MadvocException) ex;
}
throw new MadvocException(ex);
}
}
代码示例来源:origin: oblac/jodd
/**
* Builds {@link ActionRequest} and invokes it. If action result is a chain, it repeats the process.
*/
@Override
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
String actionPath = DispatcherUtil.getServletPath(request);
try {
MadvocResponseWrapper madvocResponse = new MadvocResponseWrapper(response);
actionPath = madvocController.invoke(actionPath, request, madvocResponse);
} catch (Exception ex) {
log.error("Invoking action path failed: " + actionPath, ex);
throw new ServletException(ex);
}
if (actionPath != null) { // action path is not consumed
boolean pathProcessed = processUnhandledPath(actionPath, req, res);
if (!pathProcessed) {
chain.doFilter(request, response);
}
}
}
代码示例来源:origin: oblac/jodd
@Test
void testThrowable() {
//given
throwable = mock(Throwable.class);
setUpOutputStream();
//when
logger.warn(LoggerConstants.WARN_MESSAGE, throwable);
//then
output = outputStream.toString();
assertTrue(output.contains(LoggerConstants.WARN_MESSAGE));
verify(throwable).printStackTrace(System.out);
//setup
throwable = mock(Throwable.class);
//when
logger.error(LoggerConstants.ERROR_MESSAGE, throwable);
//then
output = outputStream.toString();
assertTrue(output.contains(LoggerConstants.ERROR));
verify(throwable).printStackTrace(System.out);
}
代码示例来源:origin: oblac/jodd
@Test
void testLevel() {
//when
logger.trace(LoggerConstants.TRACE_MESSAGE);
//then
verify(log).trace(LoggerConstants.TRACE_MESSAGE);
//when
logger.debug(LoggerConstants.DEBUG_MESSAGE);
//then
verify(log).debug(LoggerConstants.DEBUG_MESSAGE);
//when
logger.info(LoggerConstants.INFO_MESSAGE);
//then
verify(log).info(LoggerConstants.INFO_MESSAGE);
//when
logger.warn(LoggerConstants.WARN_MESSAGE);
//then
verify(log).warn(LoggerConstants.WARN_MESSAGE);
//when
logger.error(LoggerConstants.ERROR_MESSAGE);
//then
verify(log).error(LoggerConstants.ERROR_MESSAGE);
}
代码示例来源:origin: oblac/jodd
@Test
void testLevel() {
//when
logger.trace(LoggerConstants.TRACE_MESSAGE);
//then
verify(log).log(java.util.logging.Level.FINER, LoggerConstants.TRACE_MESSAGE);
//when
logger.debug(LoggerConstants.DEBUG_MESSAGE);
//then
verify(log).log(java.util.logging.Level.FINE, LoggerConstants.DEBUG_MESSAGE);
//when
logger.info(LoggerConstants.INFO_MESSAGE);
//then
verify(log).log(java.util.logging.Level.INFO, LoggerConstants.INFO_MESSAGE);
//when
logger.warn(LoggerConstants.WARN_MESSAGE);
//then
verify(log).log(java.util.logging.Level.WARNING, LoggerConstants.WARN_MESSAGE);
//when
logger.error(LoggerConstants.ERROR_MESSAGE);
//then
verify(log).log(java.util.logging.Level.SEVERE, LoggerConstants.ERROR_MESSAGE);
}
代码示例来源:origin: oblac/jodd
@Test
void testLevel() {
//when
logger.trace(LoggerConstants.TRACE_MESSAGE);
//then
verify(log).trace(LoggerConstants.TRACE_MESSAGE);
//when
logger.debug(LoggerConstants.DEBUG_MESSAGE);
//then
verify(log).debug(LoggerConstants.DEBUG_MESSAGE);
//when
logger.info(LoggerConstants.INFO_MESSAGE);
//then
verify(log).info(LoggerConstants.INFO_MESSAGE);
//when
logger.warn(LoggerConstants.WARN_MESSAGE);
//then
verify(log).warn(LoggerConstants.WARN_MESSAGE);
//when
logger.error(LoggerConstants.ERROR_MESSAGE);
//then
verify(log).error(LoggerConstants.ERROR_MESSAGE);
}
代码示例来源:origin: oblac/jodd
@Test
void testLevel() {
//when
logger.trace(LoggerConstants.TRACE_MESSAGE);
//then
verify(log).trace(LoggerConstants.TRACE_MESSAGE);
//when
logger.debug(LoggerConstants.DEBUG_MESSAGE);
//then
verify(log).debug(LoggerConstants.DEBUG_MESSAGE);
//when
logger.info(LoggerConstants.INFO_MESSAGE);
//then
verify(log).info(LoggerConstants.INFO_MESSAGE);
//when
logger.warn(LoggerConstants.WARN_MESSAGE);
//then
verify(log).warn(LoggerConstants.WARN_MESSAGE);
//when
logger.error(LoggerConstants.ERROR_MESSAGE);
//then
verify(log).error(LoggerConstants.ERROR_MESSAGE);
}
代码示例来源:origin: oblac/jodd
@Test
void testNopLogger() {
LoggerFactory.setLoggerProvider(NOPLogger.PROVIDER);
Logger log = LoggerFactory.getLogger("foo");
assertEquals("*", log.getName());
PrintStream out = System.out;
ByteArrayOutputStream sos = new ByteArrayOutputStream();
System.setOut(new PrintStream(sos));
log.debug("nothing");
log.error("nothing");
assertEquals("", sos.toString());
System.setOut(out);
}
代码示例来源:origin: oblac/jodd
@Override
public Object intercept(final ActionRequest actionRequest) {
try {
return actionRequest.invoke();
}
catch (ResponseException rex) {
return JsonResult.of(HttpStatus.of(rex.getStatus(), rex.getMessage()));
}
catch (Exception ex) {
log.error("Action execution failed:", ex);
return JsonResult.of(ex);
}
}
}
代码示例来源:origin: oblac/jodd
/**
* Invokes an action asynchronously by submitting it to the thread pool.
*/
public void invoke(final ActionRequest actionRequest) {
if (executorService == null) {
throw new MadvocException("No action is marked as async!");
}
final HttpServletRequest servletRequest = actionRequest.getHttpServletRequest();
log.debug(() -> "Async call to: " + actionRequest);
final AsyncContext asyncContext = servletRequest.startAsync();
executorService.submit(() -> {
try {
actionRequest.invoke();
} catch (Exception ex) {
log.error("Invoking async action path failed: " , ExceptionUtil.unwrapThrowable(ex));
} finally {
asyncContext.complete();
}
});
}
}
代码示例来源:origin: oblac/jodd
@Test
void testSimpleFactory() {
LoggerFactory.setLoggerProvider(SimpleLogger.PROVIDER);
Logger log = LoggerFactory.getLogger("foo");
log.setLevel(Logger.Level.TRACE);
assertEquals("foo", log.getName());
PrintStream out = System.out;
ByteArrayOutputStream sos = new ByteArrayOutputStream();
System.setOut(new PrintStream(sos));
log.debug("debug");
log.error("error");
System.setOut(out);
String str = sos.toString();
assertTrue(str.contains("[DEBUG]"));
assertTrue(str.contains("[ERROR]"));
assertFalse(str.contains("[TRACE]"));
}
代码示例来源:origin: oblac/jodd
@Test
void testLog() {
//given
throwable = mock(Throwable.class);
//when
//The below methods are no op methods in actual implementations.
//so we will not be able to verify anything
logger.log(Level.DEBUG, name);
logger.trace(name);
logger.debug(name);
logger.info(name);
logger.warn(name);
logger.warn(name, throwable);
logger.error(name);
logger.error(name, throwable);
}
内容来源于网络,如有侵权,请联系作者删除!