Class Logger


  • public final class Logger
    extends java.lang.Object
    A singleton class that allows logging which is consistent with logs from the internal GLIDE core. The logger can be set up in 2 ways -
    1. By calling Logger.init, which configures the logger only if it wasn't previously configured.
    2. By calling Logger.setLoggerConfig, which replaces the existing configuration, and means that new logs will not be saved with the logs that were sent before the call.
    If none of these functions are called, the first log attempt will initialize a new logger with default configuration.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Logger.Level  
    • Constructor Summary

      Constructors 
      Constructor Description
      Logger()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Logger.Level getLoggerLevel()  
      static void init()
      Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to replace an existing logger.
      static void init​(@NonNull Logger.Level level)
      Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to replace an existing logger.
      static void init​(@NonNull Logger.Level level, java.lang.String fileName)
      Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to replace an existing logger.
      static void init​(@NonNull java.lang.String fileName)
      Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to replace an existing logger.
      static void log​(@NonNull Logger.Level level, @NonNull java.lang.String logIdentifier, @NonNull java.lang.String message)
      Logs the provided message if the provided log level is lower than the logger level.
      static void log​(@NonNull Logger.Level level, @NonNull java.lang.String logIdentifier, @NonNull java.lang.String message, @NonNull java.lang.Throwable throwable)
      Logs the provided exception or error if the provided log level is lower than the logger level.
      static void log​(@NonNull Logger.Level level, @NonNull java.lang.String logIdentifier, @NonNull java.util.function.Supplier<java.lang.String> messageSupplier)
      Logs the provided message if the provided log level is lower than the logger level.
      static void log​(@NonNull Logger.Level level, @NonNull java.lang.String logIdentifier, @NonNull java.util.function.Supplier<java.lang.String> messageSupplier, @NonNull java.lang.Throwable throwable)
      Logs the provided exception or error if the provided log level is lower than the logger level.
      static void setLoggerConfig()
      Creates a new logger instance.
      static void setLoggerConfig​(@NonNull Logger.Level level)
      Creates a new logger instance and configure it with the provided log level.
      static void setLoggerConfig​(@NonNull Logger.Level level, java.lang.String fileName)
      Creates a new logger instance and configure it with the provided log level and file name.
      static void setLoggerConfig​(java.lang.String fileName)
      Creates a new logger instance and configure it with the provided file name and default log level.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Logger

        public Logger()
    • Method Detail

      • init

        public static void init​(@NonNull
                                @NonNull Logger.Level level,
                                java.lang.String fileName)
        Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to replace an existing logger. The logger will filter all logs with a level lower than the given level.
        Parameters:
        level - Set the logger level to one of [DEFAULT, ERROR, WARN, INFO, DEBUG, TRACE, OFF]. To turn off logging completely, set the level to Logger.Level.OFF.
        fileName - The target of the logs will be the file mentioned.
      • init

        public static void init​(@NonNull
                                @NonNull java.lang.String fileName)
        Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to replace an existing logger. The logger will filter all logs with a level lower than the default level decided by Glide core. All logs will be printed to the console.
        Parameters:
        fileName - The target of the logs will be the file mentioned.
      • init

        public static void init()
        Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to replace an existing logger. The logger will filter all logs with a level lower than the default level decided by Glide core. The logs will be written to the console.
      • init

        public static void init​(@NonNull
                                @NonNull Logger.Level level)
        Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to replace an existing logger. The logger will filter all logs with a level lower than the given level. The logs will be written to the console.
        Parameters:
        level - Set the logger level to one of [DEFAULT, ERROR, WARN, INFO, DEBUG, TRACE] . To turn off logging completely, set the level to Logger.Level.OFF.
      • log

        public static void log​(@NonNull
                               @NonNull Logger.Level level,
                               @NonNull
                               @NonNull java.lang.String logIdentifier,
                               @NonNull
                               @NonNull java.util.function.Supplier<java.lang.String> messageSupplier)
        Logs the provided message if the provided log level is lower than the logger level. This overload takes a Supplier to lazily construct the message.
        Parameters:
        level - The log level of the provided message.
        logIdentifier - The log identifier should give the log a context.
        messageSupplier - The Supplier of the message to log.
      • log

        public static void log​(@NonNull
                               @NonNull Logger.Level level,
                               @NonNull
                               @NonNull java.lang.String logIdentifier,
                               @NonNull
                               @NonNull java.lang.String message)
        Logs the provided message if the provided log level is lower than the logger level.
        Parameters:
        level - The log level of the provided message.
        logIdentifier - The log identifier should give the log a context.
        message - The message to log.
      • log

        public static void log​(@NonNull
                               @NonNull Logger.Level level,
                               @NonNull
                               @NonNull java.lang.String logIdentifier,
                               @NonNull
                               @NonNull java.lang.String message,
                               @NonNull
                               @NonNull java.lang.Throwable throwable)
        Logs the provided exception or error if the provided log level is lower than the logger level.
        Parameters:
        level - The log level of the provided message.
        logIdentifier - The log identifier should give the log a context.
        message - The message to log with the exception.
        throwable - The exception or error to log.
      • log

        public static void log​(@NonNull
                               @NonNull Logger.Level level,
                               @NonNull
                               @NonNull java.lang.String logIdentifier,
                               @NonNull
                               @NonNull java.util.function.Supplier<java.lang.String> messageSupplier,
                               @NonNull
                               @NonNull java.lang.Throwable throwable)
        Logs the provided exception or error if the provided log level is lower than the logger level. This overload takes a Supplier to lazily construct the message.
        Parameters:
        level - The log level of the provided message.
        logIdentifier - The log identifier should give the log a context.
        messageSupplier - The Supplier of the message to log.
        throwable - The exception or error to log.
      • setLoggerConfig

        public static void setLoggerConfig​(@NonNull
                                           @NonNull Logger.Level level,
                                           java.lang.String fileName)
        Creates a new logger instance and configure it with the provided log level and file name.
        Parameters:
        level - Set the logger level to one of [DEFAULT, ERROR, WARN, INFO, DEBUG, TRACE, OFF] . If log level isn't provided, the logger will be configured with default configuration decided by Glide core.
        fileName - If provided, the target of the logs will be the file mentioned. Otherwise, logs will be printed to stdout.
      • setLoggerConfig

        public static void setLoggerConfig​(@NonNull
                                           @NonNull Logger.Level level)
        Creates a new logger instance and configure it with the provided log level. The logs will be written to stdout. To turn off the logger, use setLoggerConfig(Level.OFF).
        Parameters:
        level - Set the logger level to one of [DEFAULT, ERROR, WARN, INFO, DEBUG, TRACE, OFF] . If log level isn't provided, the logger will be configured with default configuration decided by Glide core.
      • setLoggerConfig

        public static void setLoggerConfig​(java.lang.String fileName)
        Creates a new logger instance and configure it with the provided file name and default log level. The logger will filter all logs with a level lower than the default level decided by the Glide core.
        Parameters:
        fileName - If provided, the target of the logs will be the file mentioned. Otherwise, logs will be printed to stdout.
      • setLoggerConfig

        public static void setLoggerConfig()
        Creates a new logger instance. The logger will filter all logs with a level lower than the default level decided by Glide core. The logs will be written to stdout.
      • getLoggerLevel

        public static Logger.Level getLoggerLevel()