Class CompactOneLineFormatter
java.lang.Object
java.util.logging.Formatter
zeroecho.logging.CompactOneLineFormatter
A compact single-line
Formatter for JUL log
records.
Each record is rendered into one line containing:
- timestamp in
yyyy-MM-dd HH:mm:ss.SSSformat (local time zone), - log level name,
- current thread name,
- source class and method (abbreviated),
- the formatted message with whitespace collapsed,
- and, if present, exception information: exception type, message, and first stack frame, rendered inline.
This formatter is designed for console or file logs where compactness and readability in a single line per record are preferred over multi-line stack traces. Exception stack traces are summarized to avoid overwhelming output; only the first frame is shown.
Example output
2025-09-10 22:15:32.184 INFO [main] c.e.d.p.MyService#start - Started service
2025-09-10 22:15:33.201 SEVERE [worker-1] c.e.d.p.Worker#run - Task failed
| ex=IllegalStateException: bad state @ Worker.java:42
Abbreviation rules
- Package names are reduced to their initials (e.g.,
com.example.deep.package.MyService→c.e.d.p.MyService). - Simple class names are shortened by keeping uppercase letters before the
last uppercase, and then the last uppercase plus the suffix (e.g.,
MyServiceManager→MSManager,XmlHttpRequest→XHR,UserDAO→UDAO,FooBar→FBar).
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a formatter using the system time zone for timestamps. -
Method Summary
Methods inherited from class Formatter
formatMessage, getHead, getTail
-
Constructor Details
-
CompactOneLineFormatter
public CompactOneLineFormatter()Creates a formatter using the system time zone for timestamps.
-
-
Method Details
-
format
Formats aLogRecordinto a single line.The message text has runs of whitespace collapsed to a single space. If
LogRecord.getThrown()is non-null, the formatter appends a compact suffix in the form" | ex=<Type>: <message> @ <firstStackFrame>".
-