Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arcage/crystal-logreader
Reading lines in the text file which is growing and may be rotated, such as unix system log file.
https://github.com/arcage/crystal-logreader
Last synced: about 7 hours ago
JSON representation
Reading lines in the text file which is growing and may be rotated, such as unix system log file.
- Host: GitHub
- URL: https://github.com/arcage/crystal-logreader
- Owner: arcage
- License: mit
- Created: 2016-11-29T07:16:07.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-07-30T05:13:10.000Z (over 4 years ago)
- Last Synced: 2024-10-25T01:36:38.105Z (about 2 months ago)
- Language: Crystal
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - crystal-logreader - Tailing log file (Logging and monitoring)
README
# LogReader
Reading lines in the text file which is growing and may be rotated, such as unix system log file.
* When the current file reaches EOF, this will wait new line added to the file. (like `tail -f` command)
* Even when the current file is rotated, this will trace new file and continue reading lines.## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
logreader:
github: arcage/crystal-logreader
```## Usage
```crystal
require "logreader"# create LogReader object
log = LogReader.new("/var/log/maillog")# reads single line from the file
# waits new line, when the file reaches EOF
puts log.read_line# iterates each line in the file
log.each do |line|
puts line
end
````LogReader` has only two public instance method `#read_line` and `#each`
`#each` will not finish in normal operation. if you want to stop it, you have to do it forcibly by using `Ctrl+C`, `kill` command etc.
### Internal behaviour
When reading no data for reasons such as EOF, `LogReader` try to read more data every second.
For every consecutive 5 results that no data read, `LogReader` checks whether or not the inode number associated with the file name was changed.
If it had been changed, `LogReader` close current file and re-open the file.
## Contributors
- [arcage](https://github.com/arcage) ʕ·ᴥ·ʔAKJ - creator, maintainer