File viewer for Vaadin - Vaadin Add-on Directory
Log viewer / glogg
# File Viewer for Vaadin
**Browse and search large log files directly in your Vaadin application.**
File Viewer makes it easy to inspect application logs and other large text files. Inspired by [glogg](https://github.com/nickbnf/glogg), it brings log viewing and monitoring into your Vaadin UI.
## Live demo
A live demo is available at [pacos.dev](https://pacos.dev). Sign in as a guest, then select **Applications → Glogg** from the system’s top menu.
## Getting started
Add the component to your Vaadin view and open a file using its path:
```java
import java.nio.file.Path;
import org.vaadin.addons.viewer.FileViewer;
FileViewer fileViewer = new FileViewer();
add(fileViewer);
fileViewer.openFile(Path.of("/var/log/application.log"));
```
The file is opened using UTF-8 by default. To open a file with a different character encoding, pass a `Charset`:
```java
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
fileViewer.openFile(Path.of("/var/log/application.log"), StandardCharsets.UTF_8);
fileViewer.openFile(Path.of("/var/log/legacy.log"), Charset.forName("windows-1250"));
```
## Configuration
You can configure polling, search visibility, and font resizing by passing a `FileViewerConfig` to the viewer. The default configuration enables all three features and uses a polling interval of 3 seconds.
```java
import org.vaadin.addons.viewer.DefaultFileViewerConfig;
import org.vaadin.addons.viewer.FileViewer;
import org.vaadin.addons.viewer.FileViewerConfig;
FileViewerConfig config = new DefaultFileViewerConfig() {
@Override
public boolean pollingEnabled() {
return true;
}
@Override
public int pollingInterval() {
return 3; // seconds
}
@Override
public boolean searchViewVisible() {
return true;
}
@Override
public boolean fontResizeAllowed() {
return true;
}
};
FileViewer fileViewer = new FileViewer(config);
add(fileViewer);
fileViewer.openFile(Path.of("/var/log/application.log"));
```
Configuration options:
| Option | Description |
| --- | --- |
| `pollingEnabled()` | Enables polling and displays the polling controls. |
| `pollingInterval()` | Initial polling interval in seconds. The UI allows values from 1 to 30 seconds. |
| `searchViewVisible()` | Shows or hides the search bar and search-results grid. |
| `fontResizeAllowed()` | Shows or hides controls for changing font size, line height, and row height. |
You can use `new FileViewer()` for the default configuration without explicitly creating a `FileViewerConfig`.
## Features
- **Large file browsing** — navigate large text files smoothly.
- **Multiple files** — open several files in separate tabs and switch between them.
- **Powerful search** — find matching lines using case-sensitive or case-insensitive search, including regular expressions.
- **Live updates** — monitor log files for newly appended entries without reopening the file.
- **Updated search results** — find new matching lines as log entries arrive.
- **Character encoding support** — choose the appropriate encoding for each file.
- **Adjustable display** — change font size, line spacing, and row height for comfortable reading.
## Live log monitoring
File Viewer is designed for append-only log files. It detects newly appended content; file truncation, replacement, rotation, and overwrites that do not change file size are not detected reliably.
For a responsive UI when polling is enabled, configure Vaadin Push in your application.
## Source code
[View File Viewer on GitHub](https://github.com/radekpakula/FileViewer)
Online Demo
View on GitHub
Mother website
File viewer for Vaadin version 1.0.0
File viewer for Vaadin version 2.0.1
- Compilation for Vaadin24
- Font resize allowed
- Move to first/last line
File viewer for Vaadin version 3.0.0
Updated to Vaadin 25.0.0
File viewer for Vaadin version 3.1.0
# File Viewer for Vaadin 3.1.0
- **Per-file character encoding:** Open files using a selected character set, including UTF-8 and Windows-1250.
- **Improved search:** Search supports case-sensitive and case-insensitive matching, regular expressions, and incremental updates to results as new log entries are appended.
- **Live log monitoring:** Appended content can be picked up while a file is open, with search results refreshed as well.
- **Adjustable display:** Configure the initial font size, line height, and row height, and let users adjust them in the viewer.
- **Multiple-file workflow:** Open files in separate tabs and search within the selected file.
## Reliability improvements
- Validate search expressions and display settings before applying them.
- Improve handling of invalid configuration values and viewer inputs.
- Make polling and search lifecycle handling more robust, including closing tabs while searches are active.
- Add tests for file-indexing and polling I/O failures.