log-viewer only.Expand description
A live, searchable log: entries with a level, an optional timestamp and target, and a message, streamed in from threads or tasks.
State keeps the newest entries up to a limit, dropping the oldest,
so memory stays bounded however long the log runs. It filters by
level, searches messages with every match marked, follows the newest
line, pauses and resumes the stream, and selects lines to copy. Only
the lines in view are built, as in a
virtual list.
subscription creates a bounded channel and emits Event::Ready
with its Sender once. Producers send Entry values through clones
of the sender, and entries arrive in batches as Event::Received.
Copying returns Output::Copy with the text, for the app to write to
the clipboard, and the search shortcut returns Output::FocusSearch,
for the app to answer with focus_search. Lines can carry a context
menu, such as the one from menu(), through
LogViewer::context_menu.
use iced::{Element, Subscription, Task};
use iced_cube::data::log_viewer::{self, Event, Level, Output, State, entry, log_viewer};
#[derive(Debug, Clone)]
enum Message {
Logs(Event),
}
struct App {
logs: State,
sender: Option<log_viewer::Sender>,
}
impl App {
fn update(&mut self, message: Message) -> Task<Message> {
let Message::Logs(event) = message;
match self.logs.update(event) {
Some(Output::Ready(mut sender)) => {
let _ = sender.try_send(entry(Level::Info, "Listening on :8080"));
self.sender = Some(sender);
Task::none()
}
Some(Output::Copy(text)) => iced::clipboard::write(text),
Some(Output::FocusSearch) => log_viewer::focus_search(&self.logs),
None => Task::none(),
}
}
fn view(&self) -> Element<'_, Message> {
log_viewer(&self.logs).height(400).on_event(Message::Logs).into()
}
fn subscription(&self) -> Subscription<Message> {
log_viewer::subscription().map(Message::Logs)
}
}Structs§
- Entry
- One log line.
- Line
Style - The colours of a line.
- LogViewer
- A log viewer builder. Convert it into an
Elementto render. - State
- The kept entries, the filters, the search, the selection and whether the log follows its newest line.
Enums§
- Action
- What a log keyboard shortcut does.
- Event
- Everything that changes a log.
- Level
- How severe an entry is.
- Menu
Item - An entry of the context menu from
menu. - Output
- What the app may need to act on after an
Event.
Constants§
- BATCH_
SIZE - The most entries delivered in one
Event::Received. - BREAKPOINT
- Below this width the toolbar stacks its parts.
- CHANNEL_
CAPACITY - How many entries a producer can send before it has to wait.
- DEFAULT_
LIMIT - The most entries kept unless the state is given another limit.
- ROW_
HEIGHT - Height of a line that does not wrap.
- SEARCH_
ID - The default widget id of the search field.
- STACKED_
ROW_ HEIGHT - Height of a line that does not wrap below the
BREAKPOINT, where the message sits under the timestamp, level and target.
Functions§
- default_
keymap - The default log shortcuts:
- entry
- Creates an entry. Add a timestamp and a target with the builder methods.
- focus_
search - Focuses the search field of
state’s log. - level_
colour - The colour of a level’s tag.
- line_
style - Resolves a line’s colours. Lines take the list rows’ colours, with the accent’s text on a selected line, and an error line is tinted when nothing else colours it. The current match is marked more strongly than the others.
- log_
viewer - Renders
state: a toolbar with the search, level filters and actions, above the lines. Withouton_eventeverything renders disabled. - match_
label - The text beside the search field: “3 of 12” for the current match of all matches, “12 found” before one is current, “None” when nothing matches, and empty without a search.
- menu
- A context menu to pass to
LogViewer::context_menu: copy the line or only its message, or show only lines of its level. Turn the chosen entry into an event withMenuItem::event. - stream
- The stream behind
subscription, for driving it without a runtime. - subscription
- Owns the channel entries arrive on. Emits
Event::Readyfirst, then batches of up toBATCH_SIZEentries.