logspot 0.4.0 → 0.5.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
  SHA1:
3
- metadata.gz: 6595774b426267654aafd83076d8e173ca7b320d
4
- data.tar.gz: 25d9c409f6bf3db7a88860332a77620f8994c501
3
+ metadata.gz: a4edef053fc6b53e57b5189c8d2ff6c1750d578f
4
+ data.tar.gz: b28973b319462b292ede579ee2673b4df401bacb
5
5
  SHA512:
6
- metadata.gz: 5d9fd46216eda1d1ed768d84fd79dba9709d608691f35468ad66f7818042590cce959e550b6f48b5afa704882da4d55f09126e422281ef1a7a892493fc69f27e
7
- data.tar.gz: 55cb548f9c70e5562ffb9974b7f105b98be5da1af1da1129d52e738973cbd00a03b665e58137417799e4a38efb8b8f6d40fb6d08f1f0f2db129594774794b81d
6
+ metadata.gz: ee34d18e23317aceda4d2accaf75292444a2aa23a42993ba8916f63cdd638927a0a118d6acd2786caef16fc72a7e780bcda19df07d19ac18760145e7414d2591
7
+ data.tar.gz: 539e68ee94ad552ae5bfd19416e2a2fb0bc9eeff0b53b8c1773210e817e277a03e24cd6a4ba583fee007b902ef82ad07c2646bcf316489cf8c14a935b580a66c
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
data/README.md CHANGED
@@ -1,5 +1,34 @@
1
1
  #LoGspot
2
2
 
3
+ ##Usage
4
+
5
+ ### Initialization
6
+
7
+ ```
8
+ logger = LoGspot.new('/home/user/logs/production.log')
9
+ logger = LoGspot.new # STDOUT
10
+ ```
11
+
12
+ ### Output
13
+
14
+ ```
15
+ logger.info 'Foo' # [2015/01/20 22:13:42 INFO] Foo
16
+ ```
17
+
18
+ ```
19
+ logger.tagged 'Foo: ' do
20
+ logger.info 'Bar'
21
+ logger.info 'Foo'
22
+ end
23
+ # [2015/01/20 22:13:42 INFO] Foo: Bar
24
+ # [2015/01/20 22:13:42 INFO] Foo: Foo
25
+ ```
26
+
3
27
  ```
4
- LoGspot.new('/home/user/logs/production.log')
28
+ logger.tagged_list 'Foo: ' do
29
+ logger.info 'Bar'
30
+ logger.info 'Foo'
31
+ end
32
+ # [2015/01/20 22:13:42 INFO] Foo: Bar
33
+ # Foo
5
34
  ```
@@ -8,6 +8,10 @@ class LoGspot::Output::Wrap
8
8
  wrapper.call(output, data)
9
9
  end
10
10
 
11
+ def inner_output
12
+ output
13
+ end
14
+
11
15
  private
12
16
 
13
17
  attr_reader :wrapper, :output
data/lib/logspot.rb CHANGED
@@ -3,16 +3,16 @@ require_relative 'initialize'
3
3
  class LoGspot
4
4
  LOG_LEVELS = %w(DEBUG INFO WARN ERROR FATAL)
5
5
 
6
- def initialize(file_or_file_name = STDOUT, wrapper = nil)
6
+ def initialize(file_or_file_name = STDOUT, wrapper: nil, tag_format: '[%{time} %{level}] ', time_format: '%Y/%m/%d %H:%M:%S', tag_block: nil)
7
7
  wrapper = ->(output, data) {
8
- base = "[#{Time.now.strftime('%Y/%m/%d %H:%M:%S')} #{level}] "
8
+ base = tag_block ? tag_block.(Time.current, level) : tag_format % { time: Time.current.strftime(time_format), level: level }
9
9
  if data[:space]
10
10
  base = ' ' * base.length
11
11
  end
12
12
  output.puts(message: "#{base}#{data[:message]}")
13
13
  }
14
- @file = Output::File.new(file_or_file_name)
15
- @output = @original_output = Output::Wrap.new(wrapper, @file)
14
+ @raw_output = @file = Output::File.new(file_or_file_name)
15
+ @top_output = @output = Output::Wrap.new(wrapper, @file)
16
16
  @level = nil
17
17
  end
18
18
 
@@ -76,7 +76,19 @@ class LoGspot
76
76
  end
77
77
 
78
78
  def untagged(&block)
79
- previous_output, @output = output, original_output
79
+ previous_output, @output = output, output.inner_output
80
+ block.call
81
+ @output = previous_output
82
+ end
83
+
84
+ def top(&block)
85
+ previous_output, @output = output, top_output
86
+ block.call
87
+ @output = previous_output
88
+ end
89
+
90
+ def raw(&block)
91
+ previous_output, @output = output, raw_output
80
92
  block.call
81
93
  @output = previous_output
82
94
  end
@@ -93,7 +105,7 @@ class LoGspot
93
105
 
94
106
  private
95
107
 
96
- attr_reader :original_output, :output, :level
108
+ attr_reader :raw_output, :top_output, :output, :level
97
109
 
98
110
  def write(l, *args, &block)
99
111
  @level = l
data/logspot.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logspot'
3
- s.version = '0.4.0'
3
+ s.version = '0.5.0'
4
4
  s.authors = ['Tetsuri Moriya']
5
5
  s.email = ['tetsuri.moriya@gmail.com']
6
6
  s.summary = 'Logger'
data/spec/logspot_spec.rb CHANGED
@@ -2,20 +2,74 @@ require 'spec_helper'
2
2
 
3
3
  describe LoGspot do
4
4
  let(:filename) { File.expand_path('../../tmp/spec.log', __FILE__) }
5
- let(:logger) { LoGspot.new(filename) }
5
+
6
+ before do
7
+ FileUtils.rm(filename)
8
+ end
9
+
10
+ let(:tag_format) { '' }
11
+ let(:logger) { LoGspot.new(filename, tag_format: tag_format) }
6
12
  let(:read) { -> { File.read(filename) } }
7
13
 
8
14
  describe '#write' do
9
- it 'should output' do
15
+ it 'should output properly' do
10
16
  logger.info('test')
11
- expect(read.call).to include 'test'
17
+ expect(read.()).to eq "test\n"
12
18
  end
13
19
  end
14
20
 
15
21
  describe '#value' do
16
- it 'should output' do
22
+ it 'should output properly' do
17
23
  logger.value(:info, test: 'test')
18
- expect(read.call).to include 'test: test'
24
+ expect(read.()).to eq "test: test\n"
25
+ end
26
+ end
27
+
28
+ describe '#tagged' do
29
+ it 'should output properly' do
30
+ logger.tagged('tag') do
31
+ logger.info('test')
32
+ end
33
+ expect(read.()).to eq "tagtest\n"
34
+ end
35
+ end
36
+
37
+ describe '#untagged' do
38
+ it 'should output properly' do
39
+ logger.tagged('tag') do
40
+ logger.tagged('tag2') do
41
+ logger.untagged do
42
+ logger.info('test')
43
+ end
44
+ end
45
+ end
46
+ expect(read.()).to eq "tagtest\n"
47
+ end
48
+ end
49
+
50
+ describe '#top' do
51
+ let(:tag_format) { 'a' }
52
+
53
+ it 'should output properly' do
54
+ logger.tagged('tag') do
55
+ logger.top do
56
+ logger.info('test')
57
+ end
58
+ end
59
+ expect(read.()).to eq "atest\n"
60
+ end
61
+ end
62
+
63
+ describe '#raw' do
64
+ let(:tag_format) { 'a' }
65
+
66
+ it 'should output properly' do
67
+ logger.tagged('tag') do
68
+ logger.raw do
69
+ logger.info('test')
70
+ end
71
+ end
72
+ expect(read.()).to eq "test\n"
19
73
  end
20
74
  end
21
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logspot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tetsuri Moriya
@@ -46,6 +46,7 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
+ - ".rspec"
49
50
  - ".ruby-version"
50
51
  - Gemfile
51
52
  - Gemfile.lock