jodd.log.Logger类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(263)

本文整理了Java中jodd.log.Logger类的一些代码示例,展示了Logger类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Logger类的具体详情如下:
包路径:jodd.log.Logger
类名称:Logger

Logger介绍

[英]Simple Logger interface. It defines only logger methods with string argument as our coding style and approach insist in always using if block around the logging.
[中]简单的记录器接口。它只定义了带有字符串参数的记录器方法,作为我们的编码风格和方法,我们坚持在日志中始终使用if块。

代码示例

代码示例来源:origin: oblac/jodd

/**
 * Sets bundle name for provided servlet request.
 */
public static void setRequestBundleName(final ServletRequest request, final String bundleName) {
  if (log.isDebugEnabled()) {
    log.debug("Bundle name for this request: " + bundleName);
  }
  request.setAttribute(REQUEST_BUNDLE_NAME_ATTR, bundleName);
}

代码示例来源: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);
}

代码示例来源:origin: oblac/jodd

/**
 * Logs a message at INFO level.
 */
default void info(final Supplier<String> messageSupplier) {
  if (isInfoEnabled()) {
    info(messageSupplier.get());
  }
}

代码示例来源:origin: oblac/jodd

/**
 * Logs a message at WARN level.
 */
default void warn(final Supplier<String> messageSupplier, final Throwable throwable) {
  if (isWarnEnabled()) {
    warn(messageSupplier.get(), throwable);
  }
}

代码示例来源:origin: oblac/jodd

/**
 * Logs a message at ERROR level.
 */
default void error(final Supplier<String> messageSupplier) {
  if (isErrorEnabled()) {
    error(messageSupplier.get());
  }
}

代码示例来源:origin: oblac/jodd

if (log.isWarnEnabled()) {
  log.warn(createMixingMessage(targetBeanDefinition, refBeanDefinition));
if (log.isDebugEnabled()) {
  log.debug(createMixingMessage(targetBeanDefinition, refBeanDefinition));

代码示例来源:origin: oblac/jodd

@Override
  protected void out(final String message) {
    log.debug(message);
  }
}

代码示例来源:origin: oblac/jodd

throw ioex;
      if (log.isWarnEnabled()) {
        log.warn("Download failed: " + src + "; " + ioex.getMessage());
          throw ioex;
        if (log.isWarnEnabled()) {
          log.warn(ioex.getMessage());
          throw ioex;
        if (log.isWarnEnabled()) {
          log.warn("Download failed: " + localUrl + "; " + ioex.getMessage());
if (log.isInfoEnabled()) {
  log.info("Bundle created: " + bundleId);

代码示例来源:origin: oblac/jodd

@Test
void testIsLevelEnabled() {
  // Loggers does not provide any API to enable levels.
  // Instead we need to use log/level(trace/debug etc) API to log information into corresponding level
  assertFalse(logger.isTraceEnabled());
  assertFalse(logger.isDebugEnabled());
  assertFalse(logger.isInfoEnabled());
  assertFalse(logger.isWarnEnabled());
  assertFalse(logger.isErrorEnabled());
}

代码示例来源: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

/**
   * Creates Proxetta with all aspects. The following aspects are created:
   * <ul>
   * <li>Transaction proxy - applied on all classes that contains public top-level methods
   * annotated with <code>@Transaction</code> annotation. This is just one way how proxies
   * can be applied - since base configuration is in Java, everything is possible.</li>
   * </ul>
   */
  @Override
  public void start() {
    initLogger();

    log.info("PROXETTA start ----------");

    final ProxyAspect[] proxyAspectsArray = this.proxyAspects.toArray(new ProxyAspect[0]);

    log.debug("Total proxy aspects: " + proxyAspectsArray.length);

//        proxetta = Proxetta.wrapperProxetta().setCreateTargetInDefaultCtor(true).withAspects(proxyAspectsArray);

    proxetta = Proxetta.proxyProxetta().withAspects(proxyAspectsArray);

    log.info("PROXETTA OK!");
  }

代码示例来源:origin: oblac/jodd

/**
 * Stops <em>Madvoc</em> web application.
 */
public void stopWebApplication() {
  log.info("Madvoc shutting down...");
  if (servletContext != null) {
    servletContext.removeAttribute(MADVOC_ATTR);
  }
  webapp.shutdown();
  webapp = null;
}

代码示例来源: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 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

/**
 * Clears resource bundle caches.
 */
protected static void clearResourceBundleCache() {
  try {
    clearMap(ResourceBundle.class, null, "cacheList");
  } catch (Exception ex) {
    log.warn("Unable to clear resource bundle cache", 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

/**
 * Creates new DbOom.
 */
public DbOom(
    final ConnectionProvider connectionProvider,
    final DbSessionProvider dbSessionProvider,
    final QueryMap queryMap) {
  this.connectionProvider = connectionProvider;
  this.dbSessionProvider = dbSessionProvider;
  this.queryMap = queryMap;
  this.dbOomConfig = new DbOomConfig();
  this.dbQueryConfig = new DbQueryConfig();
  this.dbEntityManager = new DbEntityManager(dbOomConfig);
  this.dbEntitySql = new DbEntitySql(this);
  // static init
  if (defaultDbOom == null) {
    log.info("Default DbOom is created.");
    defaultDbOom = this;
  }
  else {
    log.warn("Multiple DbOom detected.");
    defaultDbOom = null;
  }
}

代码示例来源: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

@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 testErrorWithThrowable() {
  //given
  throwable = mock(Throwable.class);
  //when
  logger.error(LoggerConstants.ERROR_MESSAGE, throwable);
  //then
  verify(log).error(LoggerConstants.ERROR_MESSAGE, throwable);
}

相关文章