Log Viewer
Monospace streaming log display with level coloring.
Preview
1[info] server started
2[info] connected to database
3[warn] slow query: 1.2s
Arguments
log_viewer(lines=['[info] server started', '[info] connected to database', '[warn] slow query: 1.2s'])
Usage
views.py
python
from djust import LiveView
from djust.components import LogViewer
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = LogViewer(lines=['[info] server started', '[info] connected to database', '[warn] slow query: 1.2s'])my_template.html
django
{{ component }}Needs its script on the page: <script src="{% static 'djust_components/log-viewer.js' %}"></script>. djust ships it; without it the markup renders but does not update in the browser.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| lines | list | None | None | list of log line strings |
| stream_event | str — the event your server pushes to it | '' | djust event for receiving new log lines |
| show_line_numbers | bool | True | show line numbers (default True) |
| auto_scroll | bool | True | auto-scroll to bottom on new lines (default True) |
| filter_level | str | '' | filter to specific level (info/warn/error/debug) |
| wrap | bool | False | wrap long lines (default False) |
| max_lines | int | 0 | maximum lines to display (0 = unlimited) |
| custom_class | str | '' | additional CSS classes |
| **kwargs | — passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state | — | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.log_viewer | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 7 of this component's classes at line 2172, 2173, 2174, 2176, 2177, 2179, 2180. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |