Class Logger.Builder

  • Enclosing class:
    Logger

    public static class Logger.Builder
    extends java.lang.Object
    Builder for Logger.
    • Constructor Detail

      • Builder

        public Builder()
        Construct a builder, which will perform the same as the global one by default.
    • Method Detail

      • logLevel

        public Logger.Builder logLevel​(int logLevel)
        Set the log level, the logs below of which would not be printed.
        Parameters:
        logLevel - the log level
        Returns:
        the builder
        Since:
        1.3.0
      • tag

        public Logger.Builder tag​(java.lang.String tag)
        Set the tag string when Logger log.
        Parameters:
        tag - the tag string when Logger log
        Returns:
        the builder
      • enableThreadInfo

        public Logger.Builder enableThreadInfo()
        Enable thread info, the thread info would be printed with the log message.
        Returns:
        the builder
        Since:
        1.7.0
        See Also:
        ThreadFormatter
      • disableThreadInfo

        public Logger.Builder disableThreadInfo()
        Disable thread info, the thread info won't be printed with the log message.
        Returns:
        the builder
        Since:
        1.7.0
      • st

        @Deprecated
        public Logger.Builder st​(int depth)
        Deprecated.
        use enableStackTrace(int) instead, since 1.7.0
        Enable stack trace.
        Parameters:
        depth - the number of stack trace elements we should log, 0 if no limitation
        Returns:
        the builder
      • enableStackTrace

        public Logger.Builder enableStackTrace​(int depth)
        Enable stack trace, the stack trace would be printed with the log message.
        Parameters:
        depth - the number of stack trace elements we should log, 0 if no limitation
        Returns:
        the builder
        Since:
        1.7.0
        See Also:
        StackTraceFormatter
      • st

        @Deprecated
        public Logger.Builder st​(java.lang.String stackTraceOrigin,
                                 int depth)
        Deprecated.
        use enableStackTrace(String, int) instead, since 1.7.0
        Enable stack trace.
        Parameters:
        stackTraceOrigin - the origin of stack trace elements from which we should NOT log when logging with stack trace, it can be a package name like "com.elvishew.xlog", a class name like "com.yourdomain.logWrapper", or something else between package name and class name, like "com.yourdomain.". It is mostly used when you are using a logger wrapper
        depth - the number of stack trace elements we should log, 0 if no limitation
        Returns:
        the builder
        Since:
        1.4.0
      • enableStackTrace

        public Logger.Builder enableStackTrace​(java.lang.String stackTraceOrigin,
                                               int depth)
        Enable stack trace, the stack trace would be printed with the log message.
        Parameters:
        stackTraceOrigin - the origin of stack trace elements from which we should NOT log when logging with stack trace, it can be a package name like "com.elvishew.xlog", a class name like "com.yourdomain.logWrapper", or something else between package name and class name, like "com.yourdomain.". It is mostly used when you are using a logger wrapper
        depth - the number of stack trace elements we should log, 0 if no limitation
        Returns:
        the builder
        Since:
        1.7.0
        See Also:
        StackTraceFormatter
      • disableStackTrace

        public Logger.Builder disableStackTrace()
        Disable stack trace, the stack trace won't be printed with the log message.
        Returns:
        the builder
        Since:
        1.7.0
        See Also:
        StackTraceFormatter
      • enableBorder

        public Logger.Builder enableBorder()
        Enable border, the border would surround the entire log content, and separate the log message, thread info and stack trace.
        Returns:
        the builder
        Since:
        1.7.0
        See Also:
        BorderFormatter
      • disableBorder

        public Logger.Builder disableBorder()
        Disable border, the log content won't be surrounded by a border.
        Returns:
        the builder
        Since:
        1.7.0
      • jsonFormatter

        public Logger.Builder jsonFormatter​(JsonFormatter jsonFormatter)
        Set the JSON formatter when Logger log a JSON string.
        Parameters:
        jsonFormatter - the JSON formatter when Logger log a JSON string
        Returns:
        the builder
      • xmlFormatter

        public Logger.Builder xmlFormatter​(XmlFormatter xmlFormatter)
        Set the XML formatter when Logger log a XML string.
        Parameters:
        xmlFormatter - the XML formatter when Logger log a XML string
        Returns:
        the builder
      • throwableFormatter

        public Logger.Builder throwableFormatter​(ThrowableFormatter throwableFormatter)
        Set the throwable formatter when Logger log a message with throwable.
        Parameters:
        throwableFormatter - the throwable formatter when Logger log a message with throwable
        Returns:
        the builder
      • threadFormatter

        public Logger.Builder threadFormatter​(ThreadFormatter threadFormatter)
        Set the thread formatter when Logger logging.
        Parameters:
        threadFormatter - the thread formatter when Logger logging
        Returns:
        the builder
      • stackTraceFormatter

        public Logger.Builder stackTraceFormatter​(StackTraceFormatter stackTraceFormatter)
        Set the stack trace formatter when Logger logging.
        Parameters:
        stackTraceFormatter - the stace trace formatter when Logger logging
        Returns:
        the builder
      • borderFormatter

        public Logger.Builder borderFormatter​(BorderFormatter borderFormatter)
        Set the border formatter when Logger logging.
        Parameters:
        borderFormatter - the border formatter when Logger logging
        Returns:
        the builder
      • addObjectFormatter

        public <T> Logger.Builder addObjectFormatter​(java.lang.Class<T> objectClass,
                                                     ObjectFormatter<? super T> objectFormatter)
        Add an object formatter for specific class of object when Logger log an object.
        Type Parameters:
        T - the type of object
        Parameters:
        objectClass - the class of object
        objectFormatter - the object formatter to add
        Returns:
        the builder
        Since:
        1.1.0
      • addInterceptor

        public Logger.Builder addInterceptor​(Interceptor interceptor)
        Add an interceptor when Logger logging.
        Parameters:
        interceptor - the intercept to add
        Returns:
        the builder
        Since:
        1.3.0
      • printers

        public Logger.Builder printers​(Printer... printers)
        Set the printers used to print the log when Logger log.
        Parameters:
        printers - the printers used to print the log when Logger log
        Returns:
        the builder
      • build

        public Logger build()
        Builds configured Logger object.
        Returns:
        the built configured Logger object