Class Logging

    • Method Detail

      • setLoggerFactory

        @Configuration
        public static void setLoggerFactory​(LoggerFactory<?> factory)
        Sets a new factory to use for obtaining Logger instances. If the given factory argument is null (the default), then the standard Logging framework will be used.
        Limitation
        SIS classes typically declare a logger constant like below:
        public static final Logger LOGGER = Logging.getLogger("the.logger.name");
        Factory changes will take effect only if this method is invoked before the initialization of such classes.
        Parameters:
        factory - the new logger factory, or null if none.
      • getLoggerFactory

        public static LoggerFactory<?> getLoggerFactory()
        Returns the factory used for obtaining Logger instances, or null if none.
        Returns:
        the current logger factory, or null if none.
      • getLogger

        public static Logger getLogger​(String name)
        Returns a logger for the specified name. If a logger factory has been set, then this method first asks to the factory. This rule gives SIS a chance to redirect logging events to commons-logging or some equivalent framework. Only if no factory was found or if the factory choose to not redirect the loggings, then this method delegate to Logger​.get­Logger(name).
        Parameters:
        name - the logger name.
        Returns:
        a logger for the specified name.
      • getLogger

        public static Logger getLogger​(Class<?> source)
        Returns a logger for the package of the specified class. This convenience method invokes get­Logger(String) with the package name of the given class taken as the logger name.
        Parameters:
        source - the class which will emit a logging message.
        Returns:
        a logger for the specified class.
        Since:
        1.0
      • log

        public static void log​(Class<?> classe,
                               String method,
                               LogRecord record)
        Logs the given record to the logger associated to the given class. This convenience method performs the following steps:
        Parameters:
        classe - the class for which to obtain a logger.
        method - the name of the method which is logging a record.
        record - the record to log.
      • unexpectedException

        public static boolean unexpectedException​(Logger logger,
                                                  Class<?> classe,
                                                  String method,
                                                  Throwable error)
        Invoked when an unexpected error occurred. This method logs a message at Level​.WARNING to the specified logger. The originating class name and method name can optionally be specified. If any of them is null, then it will be inferred from the error stack trace as described below.
        Recommended usage: explicit value for class and method names are preferred to automatic inference for the following reasons:
        • Automatic inference is not 100% reliable, since the Java Virtual Machine is free to omit stack frame in optimized code.
        • When an exception occurred in a private method used internally by a public method, we sometime want to log the warning for the public method instead, since the user is not expected to know anything about the existence of the private method. If a developer really want to know about the private method, the stack trace is still available anyway.
        If the classe or method arguments are null, then the originating class name and method name are inferred from the given error using the first stack trace element for which the class name is inside a package or sub-package of the same name than the logger name.
        Example: if the logger name is "org​.apache​.sis​.image", then this method will uses the first stack trace element where the fully qualified class name starts with "org​.apache​.sis​.image" or "org​.apache​.sis​.image​.io", but not "org​.apache​.sis​.imageio".
        Parameters:
        logger - where to log the error, or null for inferring a default value from other arguments.
        classe - the class where the error occurred, or null for inferring a default value from other arguments.
        method - the method where the error occurred, or null for inferring a default value from other arguments.
        error - the error, or null if none.
        Returns:
        true if the error has been logged, or false if the given error was null or if the logger does not log anything at Level​.WARNING.
        See Also:
        recoverable­Exception(Logger, Class, String, Throwable), severe­Exception(Logger, Class, String, Throwable)
      • recoverableException

        public static boolean recoverableException​(Logger logger,
                                                   Class<?> classe,
                                                   String method,
                                                   Throwable error)
        Invoked when a recoverable error occurred. This method is similar to unexpected­Exception(…) except that it does not log the stack trace and uses a lower logging level.
        Parameters:
        logger - where to log the error, or null for inferring a default value from other arguments.
        classe - the class where the error occurred, or null for inferring a default value from other arguments.
        method - the method name where the error occurred, or null for inferring a default value from other arguments.
        error - the error, or null if none.
        Returns:
        true if the error has been logged, or false if the given error was null or if the logger does not log anything at Level​.FINE.
        See Also:
        unexpected­Exception(Logger, Class, String, Throwable), severe­Exception(Logger, Class, String, Throwable)
      • ignorableException

        public static boolean ignorableException​(Logger logger,
                                                 Class<?> classe,
                                                 String method,
                                                 Throwable error)
        Invoked when an ignorable error occurred. This method is similar to unexpected­Exception(…) except that it uses a lower logging level.
        Parameters:
        logger - where to log the error, or null for inferring a default value from other arguments.
        classe - the class where the error occurred, or null for inferring a default value from other arguments.
        method - the method name where the error occurred, or null for inferring a default value from other arguments.
        error - the error, or null if none.
        Returns:
        true if the error has been logged, or false if the given error was null or if the logger does not log anything at Level​.FINER.
        Since:
        1.0