trifle-logs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e1b23397fff0b91597084b3ec81530168aa48069e514914030bfbe6019d589cf
4
+ data.tar.gz: 52780055b0054daa04ef485ce0c4e38c446ebf00a8cc55c5143f91c2c4ba6897
5
+ SHA512:
6
+ metadata.gz: 60ead56494806f3afd4a6b3dd08ad33c5462f38bdeb6562f4b98df507b0ea7725eb14d07aacf2dce48c28797a26ad6d56e90eb1dcd00a9284297512046cb496a
7
+ data.tar.gz: 30a78657d005ef359249ca3542888cdac815aa4374d2cc4d87b9ec5ff79da5ff53d63c6d7efaa4e56e6f7d53c07258d41e21299eb6d1ba42a086b8bcc143aacc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,15 @@
1
+ inherit_mode:
2
+ merge:
3
+ - Exclude
4
+
5
+ AllCops:
6
+ TargetRubyVersion: '2.6'
7
+ Exclude:
8
+ - 'bin/**/*'
9
+ - 'Rakefile'
10
+ - 'spec/**/*'
11
+ - 'Gemfile'
12
+ - trifle-logs.gemspec
13
+
14
+ Style/Documentation:
15
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-09-04
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at jozef@hey.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in logs.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ trifle-logs (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ byebug (11.1.3)
11
+ diff-lcs (1.5.0)
12
+ json (2.6.2)
13
+ parallel (1.22.1)
14
+ parser (3.1.2.1)
15
+ ast (~> 2.4.1)
16
+ rainbow (3.1.1)
17
+ rake (13.0.6)
18
+ regexp_parser (2.3.1)
19
+ rexml (3.2.5)
20
+ rspec (3.11.0)
21
+ rspec-core (~> 3.11.0)
22
+ rspec-expectations (~> 3.11.0)
23
+ rspec-mocks (~> 3.11.0)
24
+ rspec-core (3.11.0)
25
+ rspec-support (~> 3.11.0)
26
+ rspec-expectations (3.11.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.11.0)
29
+ rspec-mocks (3.11.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.11.0)
32
+ rspec-support (3.11.0)
33
+ rubocop (1.35.1)
34
+ json (~> 2.3)
35
+ parallel (~> 1.10)
36
+ parser (>= 3.1.2.1)
37
+ rainbow (>= 2.2.2, < 4.0)
38
+ regexp_parser (>= 1.8, < 3.0)
39
+ rexml (>= 3.2.5, < 4.0)
40
+ rubocop-ast (>= 1.20.1, < 2.0)
41
+ ruby-progressbar (~> 1.7)
42
+ unicode-display_width (>= 1.4.0, < 3.0)
43
+ rubocop-ast (1.21.0)
44
+ parser (>= 3.1.1.0)
45
+ ruby-progressbar (1.11.0)
46
+ unicode-display_width (2.1.0)
47
+
48
+ PLATFORMS
49
+ arm64-darwin-21
50
+
51
+ DEPENDENCIES
52
+ bundler (~> 2.1)
53
+ byebug
54
+ rake (~> 13.0)
55
+ rspec (~> 3.0)
56
+ rubocop (~> 1.21)
57
+ trifle-logs!
58
+
59
+ BUNDLED WITH
60
+ 2.3.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Jozef Vaclavik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Logs
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/logs`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'logs'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install logs
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/logs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/logs/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Logs project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/logs/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "trifle/logs"
6
+ require "byebug"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require "irb"
16
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trifle
4
+ module Logs
5
+ class Configuration
6
+ attr_writer :driver
7
+ attr_accessor :timestamp_formatter, :content_formatter
8
+
9
+ def initialize; end
10
+
11
+ def driver
12
+ raise DriverNotFound if @driver.nil?
13
+
14
+ @driver
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+
5
+ module Trifle
6
+ module Logs
7
+ module Driver
8
+ class File
9
+ attr_accessor :path, :suffix, :read_size
10
+
11
+ def initialize(path:, suffix: '%Y/%m/%d', read_size: 1000)
12
+ @path = path
13
+ @suffix = suffix
14
+ @read_size = read_size
15
+ @files = {}
16
+ end
17
+
18
+ def filename_for(namespace:)
19
+ "#{path}/#{namespace}/#{Time.now.strftime(suffix)}.log"
20
+ end
21
+
22
+ def logfile_for(namespace:)
23
+ @files[namespace] = begin
24
+ filename = filename_for(namespace: namespace)
25
+ FileUtils.mkdir_p(::File.dirname(filename))
26
+ ::File.new(
27
+ filename_for(namespace: namespace), 'a', encoding: 'utf-8'
28
+ )
29
+ end
30
+ end
31
+
32
+ def dump(message, namespace:)
33
+ file = logfile_for(namespace: namespace)
34
+ file.write("#{message}\n")
35
+ file.flush
36
+ true
37
+ end
38
+
39
+ def search(namespace:, pattern:, file_loc: nil, direction: nil)
40
+ files = files_for(namespace: namespace)
41
+ return Trifle::Logs::Result.new if files.count.zero?
42
+
43
+ send("search_#{direction}_in_file", files, file_loc, pattern)
44
+ end
45
+
46
+ def search__in_file(files, file_loc, pattern)
47
+ file, _line, length = file_for(files, file_loc: file_loc)
48
+
49
+ min_line = [length - read_size, 1].max
50
+ max_line = length
51
+
52
+ Trifle::Logs::Result.new(
53
+ read(file, min_line, max_line, pattern),
54
+ min_loc: "#{file}##{min_line}", max_loc: "#{file}##{max_line}"
55
+ )
56
+ end
57
+
58
+ def search_next_in_file(files, file_loc, pattern) # rubocop:disable Metrics/MethodLength
59
+ file, line, length = file_for(files, file_loc: file_loc)
60
+ if line == length
61
+ cfile, cline, clength = next_file_for(files, file) if line == length
62
+ return Trifle::Logs::Result.new(max_loc: "#{file}##{line}") if cfile.nil?
63
+
64
+ file, line, length = cfile, cline, clength # rubocop:disable Style/ParallelAssignment
65
+ end
66
+
67
+ max_line = [line + read_size, length].min
68
+
69
+ Trifle::Logs::Result.new(
70
+ read(file, line, max_line, pattern),
71
+ max_loc: "#{file}##{max_line}"
72
+ )
73
+ end
74
+
75
+ def search_prev_in_file(files, file_loc, pattern) # rubocop:disable Metrics/MethodLength
76
+ file, line, _length = file_for(files, file_loc: file_loc)
77
+ if line == 1
78
+ cfile, cline, clength = prev_file_for(files, file)
79
+ return Trifle::Logs::Result.new(min_loc: "#{file}##{line}") if cfile.nil?
80
+
81
+ file, line, _length = cfile, cline, clength # rubocop:disable Style/ParallelAssignment
82
+ end
83
+
84
+ min_line = [line - read_size, 1].max
85
+
86
+ Trifle::Logs::Result.new(
87
+ read(file, min_line, line, pattern),
88
+ min_loc: "#{file}##{min_line}"
89
+ )
90
+ end
91
+
92
+ def read(file, from, to, pattern)
93
+ # sed -n '2,4p;5q' test/lolz/2022/09_06.log | rg '.*' --json
94
+ # head -4 test/lolz/2022/09_06.log | tail +2 | rg '.*' --json
95
+ cmd = "sed -n '#{from},#{to}p;#{to + 1}q' #{file} | rg '#{pattern || '.*'}' --json"
96
+ _stdin, stdout, _stderr = Open3.popen3(cmd)
97
+ stdout.map { |l| JSON.parse(l) }
98
+ end
99
+
100
+ def prev_file_for(files, file)
101
+ idx = files.index(file)
102
+ return [nil, nil, nil] if idx.zero? # prev file doesnt exist
103
+
104
+ file = files[idx - 1]
105
+ [file, length_of(file), length_of(file)]
106
+ end
107
+
108
+ def next_file_for(files, file)
109
+ idx = files.index(file)
110
+ return [nil, nil, nil] if idx == files.length - 1 # next file doesnt exist
111
+
112
+ file = files[idx + 1]
113
+ [file, 1, length_of(file)]
114
+ end
115
+
116
+ def file_for(files, file_loc: nil)
117
+ latest = files.last
118
+ return [latest, length_of(latest), length_of(latest)] unless file_loc
119
+
120
+ file, line = file_loc.split('#')
121
+ return [latest, length_of(latest), length_of(latest)] unless files.include?(file)
122
+
123
+ [file, line.to_i, length_of(latest)]
124
+ end
125
+
126
+ def files_for(namespace:)
127
+ Dir.glob("#{path}/#{namespace}/**/*.log").sort
128
+ end
129
+
130
+ def length_of(file)
131
+ `wc -l #{file}`.split.first.to_i
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Trifle
6
+ module Logs
7
+ module Formatter
8
+ module Content
9
+ class Json
10
+ def format(scope, message)
11
+ {
12
+ scope: scope,
13
+ content: message
14
+ }.to_json
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trifle
4
+ module Logs
5
+ module Formatter
6
+ module Content
7
+ class Text
8
+ def format(scope, message)
9
+ [
10
+ scope.map { |pair| pair.join(':') }.join(';'),
11
+ message
12
+ ].join(' ')
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trifle
4
+ module Logs
5
+ module Formatter
6
+ class Timestamp
7
+ def format(timestamp)
8
+ timestamp.strftime('%Y-%m-%dT%H:%M:%S.%6N')
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trifle
4
+ module Logs
5
+ module Operations
6
+ class Dump
7
+ attr_reader :namespace, :payload, :scope
8
+
9
+ def initialize(**keywords)
10
+ @namespace = keywords.fetch(:namespace)
11
+ @payload = keywords.fetch(:payload)
12
+ @scope = keywords.fetch(:scope)
13
+ @config = keywords[:config]
14
+ end
15
+
16
+ def config
17
+ @config || Trifle::Logs.default
18
+ end
19
+
20
+ def formatted
21
+ [
22
+ config.timestamp_formatter.format(Time.now),
23
+ config.content_formatter.format(scope, payload)
24
+ ].join(' ')
25
+ end
26
+
27
+ def perform
28
+ config.driver.dump(
29
+ formatted, namespace: namespace
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trifle
4
+ module Logs
5
+ module Operations
6
+ class Searcher
7
+ attr_reader :namespace, :pattern, :min_loc, :max_loc
8
+
9
+ def initialize(**keywords)
10
+ @namespace = keywords.fetch(:namespace)
11
+ @pattern = keywords.fetch(:pattern)
12
+ @config = keywords[:config]
13
+ @min_loc = keywords[:min_loc]
14
+ @max_loc = keywords[:max_loc]
15
+ end
16
+
17
+ def config
18
+ @config || Trifle::Logs.default
19
+ end
20
+
21
+ def perform
22
+ result = config.driver.search(
23
+ namespace: namespace, pattern: pattern
24
+ )
25
+ @min_loc = result.min_loc
26
+ @max_loc = result.max_loc
27
+ result
28
+ end
29
+
30
+ def prev
31
+ return Trifle::Logs::Result.new if @min_loc.nil?
32
+
33
+ result = config.driver.search(
34
+ namespace: namespace, pattern: pattern,
35
+ file_loc: @min_loc, direction: :prev
36
+ )
37
+
38
+ @min_loc = result.min_loc
39
+ result
40
+ end
41
+
42
+ def next
43
+ return Trifle::Logs::Result.new if @max_loc.nil?
44
+
45
+ result = config.driver.search(
46
+ namespace: namespace, pattern: pattern,
47
+ file_loc: @max_loc, direction: :next
48
+ )
49
+
50
+ @max_loc = result.max_loc
51
+ result
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trifle
4
+ module Logs
5
+ class Result
6
+ attr_reader :min_loc, :max_loc
7
+
8
+ def initialize(lines = [], min_loc: nil, max_loc: nil)
9
+ @lines = lines
10
+ @min_loc = min_loc
11
+ @max_loc = max_loc
12
+ end
13
+
14
+ def meta
15
+ @lines.last || {}
16
+ end
17
+
18
+ def data
19
+ meta.dig('data', 'stats', 'matches').to_i.positive? ? @lines[1..-3] : []
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trifle
4
+ module Logs
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'logs/version'
4
+ require_relative 'logs/configuration'
5
+ require_relative 'logs/result'
6
+ require_relative 'logs/driver/file'
7
+ require_relative 'logs/operations/dump'
8
+ require_relative 'logs/operations/searcher'
9
+ require_relative 'logs/formatter/timestamp'
10
+ require_relative 'logs/formatter/content/text'
11
+ require_relative 'logs/formatter/content/json'
12
+
13
+ module Trifle
14
+ module Logs
15
+ class Error < StandardError; end
16
+ class DriverNotFound < Error; end
17
+
18
+ def self.default
19
+ @default ||= Configuration.new
20
+ end
21
+
22
+ def self.configure
23
+ yield(default)
24
+
25
+ default
26
+ end
27
+
28
+ def self.dump(namespace, payload, scope: {}, config: nil)
29
+ Trifle::Logs::Operations::Dump.new(
30
+ namespace: namespace,
31
+ payload: payload,
32
+ scope: scope,
33
+ config: config
34
+ ).perform
35
+ end
36
+
37
+ def self.searcher(namespace, pattern: nil, config: nil, min_loc: nil, max_loc: nil)
38
+ Trifle::Logs::Operations::Searcher.new(
39
+ namespace: namespace,
40
+ pattern: pattern,
41
+ config: config,
42
+ min_loc: min_loc,
43
+ max_loc: max_loc
44
+ )
45
+ end
46
+ end
47
+ end
data/sig/logs.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Logs
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/trifle/logs/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'trifle-logs'
7
+ spec.version = Trifle::Logs::VERSION
8
+ spec.authors = ['Jozef Vaclavik']
9
+ spec.email = ['jozef@hey.com']
10
+
11
+ spec.summary = "Simple log dumps and regexp search."
12
+ spec.description = "Trifle::Logs is a way too simple log store with quick search on top of it"
13
+ spec.homepage = 'https://trifle.io'
14
+ spec.licenses = ['MIT']
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = 'https://github.com/trifle-io/trifle-logs'
19
+ spec.metadata["changelog_uri"] = 'https://trifle.io/trifle-logs/changelog'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency('bundler', '~> 2.1')
33
+ spec.add_development_dependency('byebug', '>= 0')
34
+ spec.add_development_dependency('rspec', '~> 3.2')
35
+ spec.add_development_dependency('rubocop', '1.0.0')
36
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trifle-logs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jozef Vaclavik
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-09-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0
69
+ description: Trifle::Logs is a way too simple log store with quick search on top of
70
+ it
71
+ email:
72
+ - jozef@hey.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - CHANGELOG.md
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/trifle/logs.rb
89
+ - lib/trifle/logs/configuration.rb
90
+ - lib/trifle/logs/driver/file.rb
91
+ - lib/trifle/logs/formatter/content/json.rb
92
+ - lib/trifle/logs/formatter/content/text.rb
93
+ - lib/trifle/logs/formatter/timestamp.rb
94
+ - lib/trifle/logs/operations/dump.rb
95
+ - lib/trifle/logs/operations/searcher.rb
96
+ - lib/trifle/logs/result.rb
97
+ - lib/trifle/logs/version.rb
98
+ - sig/logs.rbs
99
+ - trifle-logs.gemspec
100
+ homepage: https://trifle.io
101
+ licenses:
102
+ - MIT
103
+ metadata:
104
+ homepage_uri: https://trifle.io
105
+ source_code_uri: https://github.com/trifle-io/trifle-logs
106
+ changelog_uri: https://trifle.io/trifle-logs/changelog
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 2.6.0
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.3.3
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Simple log dumps and regexp search.
126
+ test_files: []