Class TCLogStatistic


  • public class TCLogStatistic
    extends Object
    Class for keeping up-to-date statistics from log4j appender Attention: singleton. Can be changed to a class with state
    • Method Detail

      • init

        @Nullable
        public static TCLogStatistic init​(@NotNull
                                          org.apache.logging.log4j.core.LogEvent event,
                                          @Nullable
                                          String appenderName,
                                          @Nullable
                                          String logFileName,
                                          @NotNull
                                          TimeService timeService,
                                          @Nullable
                                          String periods)
        Create a new instance if the instance is not created or change current instance or do nothing if the log level is low or do nothing if the appender is not being tracked
        Parameters:
        event - log event with log level
        appenderName - appender created event
        logFileName - the file contains a event
        timeService - time service, it will be used to obtain current time
        periods - observed time intervals. configuration with ";" delimiter, like "10m; 1h; 1d; 30d; 1y"
        Returns:
        new or old instance
      • isEnabledForEvent

        public static boolean isEnabledForEvent​(@NotNull
                                                org.apache.logging.log4j.core.LogEvent event)
      • remove

        public static void remove()
      • add

        public void add​(@Nullable
                        String appenderName,
                        @NotNull
                        org.apache.logging.log4j.core.LogEvent event,
                        @NotNull
                        String logFileName,
                        @Nullable
                        org.apache.logging.log4j.core.Layout<? extends Serializable> layout)
        Add event to statistics
        Parameters:
        appenderName - appender created event
        event - new event
        logFileName - log file name
        layout -
      • getLogFileName

        @Nullable
        public String getLogFileName()
        Get log file name with last error
        Returns:
        log file name with last error
      • getCaptureErrorMessages

        @Nullable
        public List<String> getCaptureErrorMessages()
        Get last error message
        Returns:
        last error message
      • getStatistic

        @NotNull
        public IntervalStatistic getStatistic()
        Get actual statistic
        Returns:
        actual statistic
      • getLastErrorTime

        @Nullable
        public Date getLastErrorTime()
        Get last error time
        Returns:
        last error time
      • rollOver

        public void rollOver​(@Nullable
                             String appenderName,
                             @NotNull
                             String logFileName,
                             int backupIndex)
        Change the file name if log4j wants to rotate log files
        Parameters:
        appenderName - rotated appender
        logFileName - orig file name