Class LoggerFactory

  • All Implemented Interfaces:
    Prioritized, java.lang.Comparable<Prioritized>
    Direct Known Subclasses:
    ACLLoggerFactory, JDKLoggerFactory, NoOpLoggerFactory, Sfl4jLoggerFactory

    public abstract class LoggerFactory
    extends java.lang.Object
    implements Prioritized
    The LoggerFactory serves as an abstract base class for creating and managing instances of the Logger type. It also implements the Prioritized interface, allowing subclasses to define priority-based ordering.

    Implementations should provide the delegate logger class name and create a new logger instance using the provided name. Subclasses can override the methods to customize the behavior of logger creation and availability checks.

    Example Usage

    
     public class MyLoggerFactory extends LoggerFactory {
         private final String delegateLoggerClassName = "com.example.Logger";
    
         public MyLoggerFactory() {
             // Set appropriate priority if needed
         }
    
         protected String getDelegateLoggerClassName() {
             return delegateLoggerClassName;
         }
    
         public Logger createLogger(String name) {
             return new MyLogger(name);
         }
     }
     
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    Logger, Prioritized
    • Constructor Detail

      • LoggerFactory

        public LoggerFactory()
    • Method Detail

      • getLogger

        @Nonnull
        public static Logger getLogger​(java.lang.Class<?> type)
        Get an instance of Logger by type
        Parameters:
        type - the type
        Returns:
        non-null
      • getLogger

        @Nonnull
        public static Logger getLogger​(java.lang.String name)
        Get an instance of Logger by name
        Parameters:
        name - the name of Logger
        Returns:
        Logger
      • isAvailable

        protected boolean isAvailable()
        Current LoggerFactory is available or not
        Returns:
        true if available
      • getDelegateLoggerClassName

        @Nonnull
        protected abstract java.lang.String getDelegateLoggerClassName()
        The class name of delegate Logger
        Returns:
        non-null
      • createLogger

        public abstract Logger createLogger​(java.lang.String name)
        Create a new Logger
        Parameters:
        name - the name of Logger
        Returns:
        non-null