LogSpan class abstract

Base class for all log spans - a mutable tree structure.

Spans are composable building blocks for log output. Each span knows its parent and can be manipulated in place (replaced, removed, wrapped).

Class hierarchy

LogSpan (abstract base)
├── LeafSpan (no children)
│   ├── PlainText
│   ├── Whitespace
│   ├── NewLine
│   └── EmptySpan
├── SingleChildSpan (one child)
│   ├── AnsiStyled
│   └── Bordered
├── MultiChildSpan (ordered children)
│   └── SpanSequence
└── SlottedSpan (named children)
    └── Surrounded

Example: Custom span

class EmojiSpan extends LeafSpan {
  final String emoji;

  EmojiSpan(this.emoji);

  @override
  void render(ConsoleMessageBuffer buffer) {
    buffer.write(emoji);
  }
}

Example: Transforming spans

void transform(LogSpan root, LogRecord record) {
  // Replace timestamp with emoji
  root.findFirst<Timestamp>()?.replaceWith(LevelEmoji(record.level));

  // Remove class name
  root.findFirst<ClassName>()?.remove();

  // Wrap message with border
  root.findFirst<Message>()?.wrap((child) => Bordered(child: child));
}
Implementers
Annotations
  • @experimental

Constructors

LogSpan()
Base class for all log spans - a mutable tree structure.

Properties

allAncestors Iterable<LogSpan>
Returns all ancestors from parent to root.
no setter
allChildren Iterable<LogSpan>
All direct children of this span.
no setter
allDescendants Iterable<LogSpan>
Returns all descendants (including self) in pre-order.
no setter
hashCode int
The hash code for this object.
no setterinherited
parent LogSpan?
Parent span in the tree, or null if this is the root.
no setter
root LogSpan
Returns the root span of the tree.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build() LogSpan
Builds this span into another span, or returns itself if already terminal.
findAll<T extends LogSpan>() Iterable<T>
Finds all descendants (including self) of type T.
findFirst<T extends LogSpan>() → T?
Finds the first descendant (including self) of type T.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove() bool
Removes this span from its parent.
render(ConsoleMessageBuffer buffer) → void
Renders this span to the buffer.
replaceWith(LogSpan newSpan) bool
Replaces this span in its parent with newSpan.
toString() String
A string representation of this object.
inherited
wrap(LogSpan wrapper(LogSpan child)) → void
Wraps this span with a wrapper span.

Operators

operator ==(Object other) bool
The equality operator.
inherited