Package org.logevents

Class LogEvent

  • All Implemented Interfaces:
    org.slf4j.event.LoggingEvent

    public class LogEvent
    extends Object
    implements org.slf4j.event.LoggingEvent
    The representation of a log event. This class is passed to all LogEventObserver instances and used internally.

    When using LogEvent, be aware that getCallerLocation() is initialized lazily. This will fail it's not accessed the first time inside a call to LogEventObserver (for example, if accessed in another thread or after LogEventObserver.logEvent(LogEvent) returned).

    Author:
    Johannes Brodwall
    • Constructor Detail

      • LogEvent

        public LogEvent​(String loggerName,
                        org.slf4j.event.Level level,
                        org.slf4j.Marker marker,
                        String messageFormat,
                        Object[] args)
    • Method Detail

      • getStaticMdcProperties

        public Map<String,​String> getStaticMdcProperties()
      • getLevel

        public org.slf4j.event.Level getLevel()
        Specified by:
        getLevel in interface org.slf4j.event.LoggingEvent
      • getMarker

        public org.slf4j.Marker getMarker()
      • getMarkers

        public List<org.slf4j.Marker> getMarkers()
        Specified by:
        getMarkers in interface org.slf4j.event.LoggingEvent
      • getLoggerName

        public String getLoggerName()
        Specified by:
        getLoggerName in interface org.slf4j.event.LoggingEvent
      • getAbbreviatedLoggerName

        public String getAbbreviatedLoggerName​(int maxLength)
        Returns the logger name restricted as much as possible to fit maxLength characters. The final component of the name is prioritized, then each part from the beginning. For example "org.example.Logger" will be abbreviated to "o.e.Logger" or "org.e.Logger".
      • getAbbreviatedClassName

        public static String getAbbreviatedClassName​(String className,
                                                     int maxLength)
        Returns the logger name restricted as much as possible to fit maxLength characters. The final component of the name is prioritized, then each part from the beginning. For example "org.example.Logger" will be abbreviated to "o.e.Logger" or "org.e.Logger".
      • getMessage

        public String getMessage()
        Specified by:
        getMessage in interface org.slf4j.event.LoggingEvent
      • getThreadName

        public String getThreadName()
        Specified by:
        getThreadName in interface org.slf4j.event.LoggingEvent
      • getArguments

        public List<Object> getArguments()
        Specified by:
        getArguments in interface org.slf4j.event.LoggingEvent
      • getArgumentArray

        public Object[] getArgumentArray()
        Specified by:
        getArgumentArray in interface org.slf4j.event.LoggingEvent
      • getTimeStamp

        public long getTimeStamp()
        Specified by:
        getTimeStamp in interface org.slf4j.event.LoggingEvent
      • getThrowable

        public Throwable getThrowable()
        Specified by:
        getThrowable in interface org.slf4j.event.LoggingEvent
      • getKeyValuePairs

        public List<org.slf4j.event.KeyValuePair> getKeyValuePairs()
        Specified by:
        getKeyValuePairs in interface org.slf4j.event.LoggingEvent
      • getInstant

        public Instant getInstant()
      • getLocalTime

        public LocalTime getLocalTime()
      • getRootThrowable

        public Throwable getRootThrowable()
      • getCallerLocation

        public StackTraceElement getCallerLocation()
        The StackTraceElement from which a method on Logger was first called to cause this logging event. Is initialized lazily and must be called first time during the log observation.
      • getSimpleCallerLocation

        public String getSimpleCallerLocation()
        Returns the logging location in a format that is usually clickable in IntelliJ, e.g. LogEvent.getSimpleCallerLocation(LogEvent.java:259)
      • getCallerLine

        public int getCallerLine()
      • getCallerMethodName

        public String getCallerMethodName()
      • getCallerClassName

        public String getCallerClassName()
      • getCallerFileName

        public String getCallerFileName()
      • getMdc

        public String getMdc()
      • getKeyValuePairsString

        public String getKeyValuePairsString()
      • compareTo

        public int compareTo​(LogEvent other)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • isBelowThreshold

        public boolean isBelowThreshold​(org.slf4j.event.Level threshold)