0.0
No release in over a year
Trifle::Logs is a way too simple log store with quick search on top of it
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 2.1
>= 0
~> 3.2
= 1.0.0
 Project Readme

Trifle::Logs

Gem Version Ruby

Simple log storage where you can dump your data. It allows you to search on top of your log files with ripgrep for fast regexp queries and utilises head and tail to paginate through a file.

Documentation

For comprehensive guides, API reference, and examples, visit trifle.io/trifle-logs

Installation

Add this line to your application's Gemfile:

gem 'trifle-logs'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install trifle-logs

Quick Start

1. Configure

require 'trifle/logs'

Trifle::Logs.configure do |config|
  config.driver = Trifle::Logs::Driver::File.new(path: './logs')
  config.formatter = Trifle::Logs::Formatter::Json.new
end

2. Dump logs

Trifle::Logs.dump('test', 'This is test message')
Trifle::Logs.dump('test', 'Or another message')
Trifle::Logs.dump('test', 'That someone cares about')

3. Search logs

search = Trifle::Logs.searcher('test', pattern: 'test')
result = search.perform
result.data
#=> [
#     {
#       "type"=>"match",
#       "data"=>{
#         "path"=>{"text"=>"<stdin>"},
#         "lines"=>{"text"=>"2022-09-17T08:33:04.843195 {\"scope\":{},\"content\":\"This is test message\"}\n"},
#         "line_number"=>1,
#         "absolute_offset"=>0,
#         "submatches"=>[{"match"=>{"text"=>"test"}, "start"=>58, "end"=>62}]
#       }
#     }
#   ]

Features

  • File-based storage - Simple, reliable log storage
  • Fast search - Uses ripgrep for high-performance regex searches
  • Flexible formatting - JSON, text, and custom formatters
  • Pagination support - Efficient log browsing with head/tail
  • Structured logging - Scope and metadata support
  • Production ready - Handles log rotation and large files

Drivers

Currently supports:

  • File - Local file system storage with rotation support

Formatters

  • JSON - Structured JSON output with timestamps
  • Text - Plain text formatting for human readability
  • Timestamp - Adds automatic timestamping to all entries

Testing

Tests verify log storage, search functionality, and formatter behavior. To run the test suite:

$ bundle exec rspec

Ensure ripgrep is installed locally for search functionality tests.

Tests are meant to be simple and isolated. Every test should be independent and able to run in any order. Tests should be self-contained and set up their own configuration.

Use single layer testing to focus on testing a specific class or module in isolation. Use appropriate stubbing for file system operations when testing drivers and formatters.

Repeat yourself in test setup for clarity rather than complex shared setups that can hide dependencies.

Tests verify that logs are properly written, search operations return expected results, and formatters produce correct output. File system tests use temporary directories to avoid conflicts.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/trifle-io/trifle-logs.

License

The gem is available as open source under the terms of the MIT License.