trifle-logs 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1b23397fff0b91597084b3ec81530168aa48069e514914030bfbe6019d589cf
4
- data.tar.gz: 52780055b0054daa04ef485ce0c4e38c446ebf00a8cc55c5143f91c2c4ba6897
3
+ metadata.gz: 3d80823ec892e044744fd5735b0fd9ad5666d064548e9cb17c0237c3a29a5361
4
+ data.tar.gz: d043aa96d573be03e1a4dcead50ac4d2f40efd360911e37cbcf7e8ccc1ee3976
5
5
  SHA512:
6
- metadata.gz: 60ead56494806f3afd4a6b3dd08ad33c5462f38bdeb6562f4b98df507b0ea7725eb14d07aacf2dce48c28797a26ad6d56e90eb1dcd00a9284297512046cb496a
7
- data.tar.gz: 30a78657d005ef359249ca3542888cdac815aa4374d2cc4d87b9ec5ff79da5ff53d63c6d7efaa4e56e6f7d53c07258d41e21299eb6d1ba42a086b8bcc143aacc
6
+ metadata.gz: 4e3fb6a9af3c50673010fe0856d3cfb8093b98c669979324ac80e7ae1ce56bdafcb5ea56236afa88cacdec4d7e3083c3b3e8042b8f0bc29fa58d06efe183d08c
7
+ data.tar.gz: 558f07d331c523767cb410b15bfd62e7ae298c93ec772cb3e9dc0e2a398e8bcc38338f01049bf0ad02f1778b0bf2922c5ca7e8b85c39b89f21ea05c59ffaf0d4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trifle-logs (0.1.0)
4
+ trifle-logs (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -8,32 +8,32 @@ module Trifle
8
8
  class File
9
9
  attr_accessor :path, :suffix, :read_size
10
10
 
11
- def initialize(path:, suffix: '%Y/%m/%d', read_size: 1000)
11
+ def initialize(path:, suffix: '%Y/%m/%d', read_size: 100)
12
12
  @path = path
13
13
  @suffix = suffix
14
14
  @read_size = read_size
15
- @files = {}
16
15
  end
17
16
 
18
17
  def filename_for(namespace:)
19
18
  "#{path}/#{namespace}/#{Time.now.strftime(suffix)}.log"
20
19
  end
21
20
 
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
- )
21
+ def locked_file(namespace:, &block)
22
+ filename = filename_for(namespace: namespace)
23
+ FileUtils.mkdir_p(::File.dirname(filename))
24
+ ::File.open(filename, 'a') do |file|
25
+ file.flock(::File::LOCK_EX)
26
+ block.call(file)
27
+ ensure
28
+ file.flock(::File::LOCK_UN)
29
29
  end
30
30
  end
31
31
 
32
32
  def dump(message, namespace:)
33
- file = logfile_for(namespace: namespace)
34
- file.write("#{message}\n")
35
- file.flush
36
- true
33
+ locked_file(namespace: namespace) do |file|
34
+ file.write("#{message}\n")
35
+ end
36
+ message
37
37
  end
38
38
 
39
39
  def search(namespace:, pattern:, file_loc: nil, direction: nil)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Trifle
4
4
  module Logs
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trifle-logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jozef Vaclavik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-20 00:00:00.000000000 Z
11
+ date: 2022-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler