logm 0.0.4 → 0.0.5
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/bin/logm +5 -1
- data/lib/logmerge.rb +9 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dca096ee5abe2f77c4f7ff1e746d3a62392ff51cdad344aded0d170abcc4aaa
|
4
|
+
data.tar.gz: cdb8027b35fe79d15be8918ab52f8e10a616528755c9d07c8bb2952c0bc58f36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 665aad4a847b0de8537c0e0e137d401165f0dc62014a4b79123f871838dff4a46acdc142c0a7340b25f58e9e9394281863ccbb3308ea1b32c3c2451b68d2f9b6
|
7
|
+
data.tar.gz: 6657a1b8d915cfb2e07fb2eebfde55c88032b2b4c0fbcd81dde2f2bac792fc01f655788d0d8468c863d2113a841092553746aac3db63c7d5f34ccd1df1f45b40
|
data/bin/logm
CHANGED
@@ -11,10 +11,14 @@ OptionParser.new do |opts|
|
|
11
11
|
opts.on("-eENDTIME", "--endTime=ENDTIME", "endTime") do |time|
|
12
12
|
options[:endTime] = time
|
13
13
|
end
|
14
|
+
opts.on("-a", "--autotag", "endTime") do
|
15
|
+
options[:autotag] = true
|
16
|
+
end
|
14
17
|
end.parse!
|
15
18
|
|
16
19
|
options[:startTime] ||= Time.at(0)
|
17
20
|
options[:endTime] ||= Time.at(2000000000000)
|
21
|
+
options[:autotag] ||= false
|
18
22
|
|
19
|
-
merge = LogMerge.new(ARGV, options[:startTime], options[:endTime])
|
23
|
+
merge = LogMerge.new(ARGV, options[:startTime], options[:endTime], options[:autotag])
|
20
24
|
merge.merge
|
data/lib/logmerge.rb
CHANGED
@@ -36,7 +36,7 @@ end
|
|
36
36
|
|
37
37
|
class Log
|
38
38
|
attr_accessor :file, :line, :next, :offet, :tag, :timestamp, :next_timestamp, :finished
|
39
|
-
def initialize(path)
|
39
|
+
def initialize(path, autotag=false)
|
40
40
|
@offset = 0
|
41
41
|
if path.include?(':')
|
42
42
|
parts = path.split(':')
|
@@ -46,6 +46,9 @@ class Log
|
|
46
46
|
@tag = parts[2]
|
47
47
|
end
|
48
48
|
end
|
49
|
+
if @tag.nil? && autotag
|
50
|
+
@tag = File.basename(path)
|
51
|
+
end
|
49
52
|
@file = File.open(path)
|
50
53
|
@finished = false
|
51
54
|
buffer
|
@@ -79,12 +82,8 @@ class Log
|
|
79
82
|
elsif current =~ /^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d[+-]\d\d\d\d/
|
80
83
|
current[0...28] = "[#{timestamp.to_s}]"
|
81
84
|
end
|
82
|
-
current
|
83
|
-
end
|
84
|
-
|
85
|
-
def append(current, timestamp=nil)
|
86
85
|
current.prepend("[#{@tag}]") if @tag && timestamp
|
87
|
-
|
86
|
+
current
|
88
87
|
end
|
89
88
|
|
90
89
|
def buffer
|
@@ -102,7 +101,7 @@ class Log
|
|
102
101
|
# puts "current: #{current}"
|
103
102
|
@timestamp = parseTimestamp(current)
|
104
103
|
# puts "timestamp: #{@timestamp}"
|
105
|
-
|
104
|
+
@line.push(current)
|
106
105
|
timestamp_index = timestamp_index + 1 if @timestamp.nil?
|
107
106
|
end
|
108
107
|
|
@@ -115,7 +114,7 @@ class Log
|
|
115
114
|
next_timestamp = parseTimestamp(current)
|
116
115
|
# puts "next_timestamp: #{next_timestamp}"
|
117
116
|
file.unreadline(current + "\n") && break unless next_timestamp.nil?
|
118
|
-
|
117
|
+
@line.push(current)
|
119
118
|
end
|
120
119
|
rescue EOFError
|
121
120
|
@finished = true if @line.empty?
|
@@ -130,8 +129,8 @@ end
|
|
130
129
|
|
131
130
|
class LogMerge
|
132
131
|
attr_reader :logs, :startTime, :endTime
|
133
|
-
def initialize(files, startTime=Time.at(0), endTime=Time.at(2000000000000))
|
134
|
-
@logs = files.map {|f| Log.new(f)}
|
132
|
+
def initialize(files, startTime=Time.at(0), endTime=Time.at(2000000000000), autotag=false)
|
133
|
+
@logs = files.map {|f| Log.new(f, autotag)}
|
135
134
|
@startTime = DateTime.parse(startTime.to_s)
|
136
135
|
@endTime = DateTime.parse(endTime.to_s)
|
137
136
|
end
|