org.apache.sis.util.logging.Logging.log()方法的使用及代码示例

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

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

Logging.log介绍

[英]Logs the given record to the logger associated to the given class. This convenience method performs the following steps:

  • Unconditionally LogRecord#setSourceClassName(String)to the Class#getCanonicalName() of the given class;
  • Unconditionally LogRecord#setSourceMethodName(String)to the given value;
  • Get the logger for the LogRecord#getLoggerName() if specified, or for the classe package name otherwise;
  • LogRecord#setLoggerName(String) of the given record, if not already set;
  • Logger#log(LogRecord) the modified record.
    [中]将给定记录记录到与给定类关联的记录器。此方便方法执行以下步骤:
    *无条件地将#setSourceClassName(String)记录到给定类的#getCanonicalName()类;
    *无条件日志记录#将sourcemethodname(字符串)设置为给定值;
    *获取LogRecord#getLoggerName()的记录器(如果指定),或者获取classe包名称的记录器(否则);
    *LogRecord#如果尚未设置,则设置给定记录的LoggerName(字符串);
    *记录器#记录(LogRecord)修改后的记录。

代码示例

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
 * Logs the given record. This method pretend that the record has been logged by
 * {@code EPSGFactory.install(…)} because it is the public API using this class.
 */
static void log(final LogRecord record) {
  record.setLoggerName(Loggers.CRS_FACTORY);
  Logging.log(EPSGFactory.class, "install", record);
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
 * Do the logging of the warning prepared by the above methods.
 * This method declares {@code MultiAuthoritiesFactory.getAuthorityFactory(…)}
 * as the source of the log since it is the nearest public API.
 */
private void log(final LogRecord record) {
  record.setLoggerName(Loggers.CRS_FACTORY);
  Logging.log(MultiAuthoritiesFactory.class, "getAuthorityFactory", record);
}

代码示例来源:origin: apache/sis

/**
 * Logs the given record. This method pretend that the record has been logged by
 * {@code EPSGFactory.install(…)} because it is the public API using this class.
 */
static void log(final LogRecord record) {
  record.setLoggerName(Loggers.CRS_FACTORY);
  Logging.log(EPSGFactory.class, "install", record);
}

代码示例来源:origin: apache/sis

/**
 * Do the logging of the warning prepared by the above methods.
 * This method declares {@code MultiAuthoritiesFactory.getAuthorityFactory(…)}
 * as the source of the log since it is the nearest public API.
 */
private void log(final LogRecord record) {
  record.setLoggerName(Loggers.CRS_FACTORY);
  Logging.log(MultiAuthoritiesFactory.class, "getAuthorityFactory", record);
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
 * Logs the given exception at the given level. This method pretends that the logging come from
 * {@link CRS#getAuthorityFactory(String)}, which is the public facade for {@link #EPSG()}.
 */
private static void log(final Exception e, final boolean isWarning) {
  String message = e.getMessage();        // Prefer the locale of system administrator.
  if (message == null) {
    message = e.toString();
  }
  final LogRecord record = new LogRecord(isWarning ? Level.WARNING : Level.CONFIG, message);
  if (isWarning && !(e instanceof UnavailableFactoryException)) {
    record.setThrown(e);
  }
  record.setLoggerName(Loggers.CRS_FACTORY);
  Logging.log(CRS.class, "getAuthorityFactory", record);
}

代码示例来源:origin: apache/sis

/**
 * Logs the given exception at the given level. This method pretends that the logging come from
 * {@link CRS#getAuthorityFactory(String)}, which is the public facade for {@link #EPSG()}.
 */
private static void log(final Exception e, final boolean isWarning) {
  String message = e.getMessage();        // Prefer the locale of system administrator.
  if (message == null) {
    message = e.toString();
  }
  final LogRecord record = new LogRecord(isWarning ? Level.WARNING : Level.CONFIG, message);
  if (isWarning && !(e instanceof UnavailableFactoryException)) {
    record.setThrown(e);
  }
  record.setLoggerName(Loggers.CRS_FACTORY);
  Logging.log(CRS.class, "getAuthorityFactory", record);
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
   * Invoked when an exception occurred during the creation of a candidate from a code.
   */
  private static void exceptionOccurred(final FactoryException exception) {
    /*
     * use 'getMessage()' instead of 'getLocalizedMessage()' for
     * giving preference to the locale of system administrator.
     */
    final LogRecord record = new LogRecord(Level.FINER, exception.getMessage());
    record.setLoggerName(Loggers.CRS_FACTORY);
    Logging.log(IdentifiedObjectFinder.class, "find", record);
  }
}

代码示例来源:origin: apache/sis

/**
   * Invoked when an exception occurred during the creation of a candidate from a code.
   */
  private static void exceptionOccurred(final FactoryException exception) {
    /*
     * use 'getMessage()' instead of 'getLocalizedMessage()' for
     * giving preference to the locale of system administrator.
     */
    final LogRecord record = new LogRecord(Level.FINER, exception.getMessage());
    record.setLoggerName(Loggers.CRS_FACTORY);
    Logging.log(IdentifiedObjectFinder.class, "find", record);
  }
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Logs a message to the {@code "org.apache.sis.system"} logger.
 */
private static void log(final Level level, final Exception e, final short key, final Object... parameters) {
  final LogRecord record = Messages.getResources(null).getLogRecord(level, key, parameters);
  record.setLoggerName(Loggers.SYSTEM);
  if (e != null) {
    record.setThrown(e);
  }
  Logging.log(null, null, record);            // Let Logging.log(…) infers the public caller.
}

代码示例来源:origin: apache/sis

/**
 * Logs a message to the {@code "org.apache.sis.system"} logger.
 */
private static void log(final Level level, final Exception e, final short key, final Object... parameters) {
  final LogRecord record = Messages.getResources(null).getLogRecord(level, key, parameters);
  record.setLoggerName(Loggers.SYSTEM);
  if (e != null) {
    record.setThrown(e);
  }
  Logging.log(null, null, record);            // Let Logging.log(…) infers the public caller.
}

代码示例来源:origin: org.apache.sis.core/sis-feature

/**
 * Registers the library implementation of the given name (JTS or ESRI) if present; ignore otherwise.
 * The given name shall be the simple name of a {@code Geometries} subclass in the same package.
 * The last registered library will be the default implementation.
 */
private static void register(final String name) {
  String classname = Geometries.class.getName();
  classname = classname.substring(0, classname.lastIndexOf('.')+1).concat(name);
  try {
    implementation = (Geometries) Class.forName(classname).newInstance();
  } catch (ReflectiveOperationException | LinkageError e) {
    LogRecord record = Resources.forLocale(null).getLogRecord(Level.CONFIG,
        Resources.Keys.OptionalLibraryNotFound_2, name, e.toString());
    record.setLoggerName(Loggers.GEOMETRY);
    Logging.log(Geometries.class, "register", record);
  }
}

代码示例来源:origin: apache/sis

/**
 * Registers the library implementation of the given name (JTS or ESRI) if present; ignore otherwise.
 * The given name shall be the simple name of a {@code Geometries} subclass in the same package.
 * The last registered library will be the default implementation.
 */
private static void register(final String name) {
  String classname = Geometries.class.getName();
  classname = classname.substring(0, classname.lastIndexOf('.')+1).concat(name);
  try {
    implementation = (Geometries) Class.forName(classname).newInstance();
  } catch (ReflectiveOperationException | LinkageError e) {
    LogRecord record = Resources.forLocale(null).getLogRecord(Level.CONFIG,
        Resources.Keys.OptionalLibraryNotFound_2, name, e.toString());
    record.setLoggerName(Loggers.GEOMETRY);
    Logging.log(Geometries.class, "register", record);
  }
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
 * Logs a message about a grid which is about to be loaded.
 *
 * @param  caller  the provider to logs as the source class.
 *                 the source method will be set to {@code "createMathTransform"}.
 * @param  file    the grid file, as a {@link String} or a {@link Path}.
 */
static void log(final Class<?> caller, final Object file) {
  final LogRecord record = Resources.forLocale(null).getLogRecord(Level.FINE, Resources.Keys.LoadingDatumShiftFile_1, file);
  record.setLoggerName(Loggers.COORDINATE_OPERATION);
  Logging.log(caller, "createMathTransform", record);
}

代码示例来源:origin: apache/sis

/**
 * Logs a message about a grid which is about to be loaded.
 *
 * @param  caller  the provider to logs as the source class.
 *                 the source method will be set to {@code "createMathTransform"}.
 * @param  file    the grid file, as a {@link String} or a {@link Path}.
 */
static void log(final Class<?> caller, final Object file) {
  final LogRecord record = Resources.forLocale(null).getLogRecord(Level.FINE, Resources.Keys.LoadingDatumShiftFile_1, file);
  record.setLoggerName(Loggers.COORDINATE_OPERATION);
  Logging.log(caller, "createMathTransform", record);
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
   * If we had any warnings during the loading process, report them now.
   */
  void reportWarnings() {
    if (hasUnrecognized) {
      final StringBuilder keywords = new StringBuilder();
      for (final Map.Entry<String,Object> entry : header.entrySet()) {
        if (entry.getValue() == null) {
          if (keywords.length() != 0) {
            keywords.append(", ");
          }
          keywords.append(entry.getKey());
        }
      }
      final LogRecord record = Messages.getResources(null).getLogRecord(Level.WARNING,
          Messages.Keys.UnknownKeywordInRecord_2, file, keywords.toString());
      record.setLoggerName(Loggers.COORDINATE_OPERATION);
      Logging.log(NTv2.class, "createMathTransform", record);
    }
  }
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
   * Invoked when a factory failed to create an object.
   * After invoking this method, the caller will fallback on hard-coded values.
   */
  static void failure(final Object caller, final String method, final FactoryException e, final int code) {
    String message = Resources.format(Resources.Keys.CanNotInstantiateGeodeticObject_1, (Constants.EPSG + ':') + code);
    message = Exceptions.formatChainedMessages(null, message, e);
    final LogRecord record = new LogRecord(Level.WARNING, message);
    if (!(e instanceof UnavailableFactoryException) || AuthorityFactories.failure((UnavailableFactoryException) e)) {
      // Append the stack trace only if the exception is the the one we expect when the factory is not available.
      record.setThrown(e);
    }
    record.setLoggerName(Loggers.CRS_FACTORY);
    Logging.log(caller.getClass(), method, record);
  }
}

代码示例来源:origin: org.apache.sis.core/sis-metadata

/**
 * Returns the connection to the database, creating a new one if needed. This method shall
 * be invoked inside a synchronized block wider than just the scope of this method in order
 * to ensure that the connection is used by only one thread at time. This is also necessary
 * for preventing the background thread to close the connection too early.
 *
 * <p>Callers shall not close the connection returned by this method.
 * The connection will be closed by {@link #closeExpired()} after an arbitrary timeout.</p>
 *
 * @return the connection to the database.
 * @throws SQLException if an error occurred while fetching the connection.
 */
final Connection connection() throws SQLException {
  assert Thread.holdsLock(this);
  Connection c = connection;
  if (c == null) {
    connection = c = dataSource.getConnection();
    Logging.log(MetadataSource.class, "lookup", Initializer.connected(c.getMetaData()));
    scheduleCloseTask();
  }
  return c;
}

代码示例来源:origin: apache/sis

/**
   * Invoked when a factory failed to create an object.
   * After invoking this method, the caller will fallback on hard-coded values.
   */
  static void failure(final Object caller, final String method, final FactoryException e, final int code) {
    String message = Resources.format(Resources.Keys.CanNotInstantiateGeodeticObject_1, (Constants.EPSG + ':') + code);
    message = Exceptions.formatChainedMessages(null, message, e);
    final LogRecord record = new LogRecord(Level.WARNING, message);
    if (!(e instanceof UnavailableFactoryException) || AuthorityFactories.failure((UnavailableFactoryException) e)) {
      // Append the stack trace only if the exception is the the one we expect when the factory is not available.
      record.setThrown(e);
    }
    record.setLoggerName(Loggers.CRS_FACTORY);
    Logging.log(caller.getClass(), method, record);
  }
}

代码示例来源:origin: Geomatys/geotoolkit

/**
 * Deletes this file. This method is invoked automatically when
 * a {@link File} object has been garbage-collected.
 */
@Override
public void dispose() {
  if (delete()) {
    /*
     * Logs the message at the WARNING level because execution of this code
     * means that the application failed to delete itself the temporary file.
     */
    Logging.log(TemporaryFile.class, "delete",
        Loggings.format(Level.WARNING, Loggings.Keys.TemporaryFileGc_1, this));
  }
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
 * Compares the given CRS description with the authoritative description.
 * If the comparison produces a warning, a message will be recorded to the given logger.
 *
 * @param  crs     the CRS to compare with the authoritative description.
 * @param  logger  the logger where to report warnings, if any.
 * @param  classe  the class to declare as the source of the warning.
 * @param  method  the method to declare as the source of the warning.
 * @throws FactoryException if an error occurred while querying the authority factory.
 */
public static void withAuthority(final CoordinateReferenceSystem crs, final String logger,
    final Class<?> classe, final String method) throws FactoryException
{
  final DefinitionVerifier verification = DefinitionVerifier.withAuthority(crs, null, false);
  if (verification != null) {
    final LogRecord record = verification.warning(true);
    if (record != null) {
      record.setLoggerName(logger);
      Logging.log(classe, method, record);
    }
  }
}

相关文章