logspot 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +3 -0
- data/README.md +30 -1
- data/lib/lo_gspot/output/wrap.rb +4 -0
- data/lib/logspot.rb +18 -6
- data/logspot.gemspec +1 -1
- data/spec/logspot_spec.rb +59 -5
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4edef053fc6b53e57b5189c8d2ff6c1750d578f
|
4
|
+
data.tar.gz: b28973b319462b292ede579ee2673b4df401bacb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee34d18e23317aceda4d2accaf75292444a2aa23a42993ba8916f63cdd638927a0a118d6acd2786caef16fc72a7e780bcda19df07d19ac18760145e7414d2591
|
7
|
+
data.tar.gz: 539e68ee94ad552ae5bfd19416e2a2fb0bc9eeff0b53b8c1773210e817e277a03e24cd6a4ba583fee007b902ef82ad07c2646bcf316489cf8c14a935b580a66c
|
data/.rspec
ADDED
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
|
-
|
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
|
```
|
data/lib/lo_gspot/output/wrap.rb
CHANGED
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
|
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 =
|
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
|
-
@
|
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,
|
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 :
|
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
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
|
-
|
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.
|
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.
|
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
|
+
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
|