Skip to content

io microsphere logging log4j2 LogEventComparator

github-actions[bot] edited this page May 30, 2026 · 5 revisions

LogEventComparator

Type: Class | Module: microsphere-log4j2 | Package: io.microsphere.logging.log4j2 | Since: 1.0.0

Source: microsphere-log4j2/src/main/java/io/microsphere/logging/log4j2/LogEventComparator.java

Overview

The Comparator for LogEvent based on logging time

Declaration

public class LogEventComparator implements Comparator<LogEvent>

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.14-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Method Examples

compare

LogEvent event1 = ...; // earlier event
  LogEvent event2 = ...; // later event
  int result = LogEventComparator.INSTANCE.compare(event1, event2);
  // result < 0 means event1 occurred before event2

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-log4j2</artifactId>
    <version>${microsphere-logging.version}</version>
</dependency>

Tip: Use the BOM (microsphere-logging-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.logging.log4j2.LogEventComparator;

API Reference

Public Methods

Method Description
compare Singleton instance

Method Details

compare

public int compare(LogEvent o1, LogEvent o2)

Singleton instance / public static final LogEventComparator INSTANCE = new LogEventComparator();

private LogEventComparator() { }

/** Compares two LogEvent instances by their logging timestamp. Returns a negative integer, zero, or a positive integer if the first event's time is earlier than, equal to, or later than the second.

Example Usage

`LogEvent event1 = ...; // earlier event
  LogEvent event2 = ...; // later event
  int result = LogEventComparator.INSTANCE.compare(event1, event2);
  // result

## See Also

- `LogEvent#getTimeMillis()`

---

*This documentation was auto-generated from the source code of [microsphere-logging](https://github.com/microsphere-projects/microsphere-logging).*

Clone this wiki locally