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

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

本文整理了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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. /**
  2. * If we had any warnings during the loading process, report them now.
  3. */
  4. void reportWarnings() {
  5. if (hasUnrecognized) {
  6. final StringBuilder keywords = new StringBuilder();
  7. for (final Map.Entry<String,Object> entry : header.entrySet()) {
  8. if (entry.getValue() == null) {
  9. if (keywords.length() != 0) {
  10. keywords.append(", ");
  11. }
  12. keywords.append(entry.getKey());
  13. }
  14. }
  15. final LogRecord record = Messages.getResources(null).getLogRecord(Level.WARNING,
  16. Messages.Keys.UnknownKeywordInRecord_2, file, keywords.toString());
  17. record.setLoggerName(Loggers.COORDINATE_OPERATION);
  18. Logging.log(NTv2.class, "createMathTransform", record);
  19. }
  20. }
  21. }

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

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

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

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

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

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

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

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

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

  1. /**
  2. * Compares the given CRS description with the authoritative description.
  3. * If the comparison produces a warning, a message will be recorded to the given logger.
  4. *
  5. * @param crs the CRS to compare with the authoritative description.
  6. * @param logger the logger where to report warnings, if any.
  7. * @param classe the class to declare as the source of the warning.
  8. * @param method the method to declare as the source of the warning.
  9. * @throws FactoryException if an error occurred while querying the authority factory.
  10. */
  11. public static void withAuthority(final CoordinateReferenceSystem crs, final String logger,
  12. final Class<?> classe, final String method) throws FactoryException
  13. {
  14. final DefinitionVerifier verification = DefinitionVerifier.withAuthority(crs, null, false);
  15. if (verification != null) {
  16. final LogRecord record = verification.warning(true);
  17. if (record != null) {
  18. record.setLoggerName(logger);
  19. Logging.log(classe, method, record);
  20. }
  21. }
  22. }

相关文章