tex_log_parser 1.0.0.pre.10 → 1.0.0.pre.14

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.
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
-
5
- # @attr [String] message
6
- # @attr [String,nil] source_file
7
- # @attr [Hash<Symbol, Int>,nil] source_lines
8
- # @attr [Hash<Symbol, Int>,nil] log_lines
9
- # @attr [true,false] preformatted
10
- # @attr [:error,:warning,:info,:debug] level
11
- # @attr [Class] pattern
12
- class LogMessage
13
- def initialize(message:, source_file: nil, source_lines: nil, log_lines: nil,
14
- preformatted: false, level: :info, pattern: nil)
15
- @message = message
16
- @source_file = source_file
17
- @source_lines = source_lines
18
- @log_lines = log_lines
19
- @preformatted = preformatted
20
- @level = level
21
- @pattern = pattern
22
- end
23
-
24
- attr_accessor :message, :source_file, :source_lines, :log_lines,
25
- :preformatted, :level
26
-
27
- def to_s
28
- lines = if @source_lines.nil?
29
- ''
30
- else
31
- # @type [Hash<Symbol, Int>] @source_lines
32
- ":#{@source_lines.values.uniq.join('-')}"
33
- end
34
-
35
- message = @message
36
- message = message.split("\n").map(&:strip).join(' ') unless @preformatted
37
- message += "\nLog pattern: '#{@pattern}'" if Logger.debug?
38
-
39
- <<~MSG
40
- #{@source_file}#{lines}: #{@level.to_s.upcase}
41
- #{message}
42
- MSG
43
- end
44
-
45
- def to_json(_options = {})
46
- hash = {
47
- level: @level,
48
- source_file: @source_file,
49
- source_lines: @source_lines,
50
- message: @message,
51
- log_lines: @log_lines,
52
- preformatted: @preformatted
53
- }
54
- hash[:pattern] = @pattern if Logger.debug?
55
- JSON.pretty_generate hash
56
- end
57
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # TODO: Document
4
- module LogPattern
5
- # TODO: Document
6
- # @param [String] _line
7
- # @return [true,false]
8
- def begins_at?(_line)
9
- raise NotImplementedError
10
- end
11
-
12
- # TODO: Document
13
- # @param [Array<String>] _lines
14
- # @return [Array<(LogMessage, Int)>]
15
- def read(_lines)
16
- raise NotImplementedError
17
- end
18
- end
19
-
20
- # TODO: document
21
- # @attr [Regexp] start
22
- # @attr [MatchData] start_match
23
- # @attr [Regexp] ending
24
- module RegExpPattern
25
- include LogPattern
26
-
27
- # @param [Regexp] start
28
- # @param [Hash] ending
29
- # @option ending [Regexp] :pattern
30
- # @option ending [:match,:mismatch] :until
31
- # @option ending [true,false] :inclusive
32
- def initialize(start, ending = { pattern: ->(_) { /^\s*$/ },
33
- until: :match,
34
- inclusive: false })
35
- @start = start
36
- @ending = ending
37
- @ending = ending
38
- end
39
-
40
- # TODO: document
41
- def begins_at?(line)
42
- match = @start.match(line)
43
- @start_match = match unless match.nil?
44
- !match.nil?
45
- end
46
-
47
- # TODO: document
48
- def ends_at?(line)
49
- match = @ending[:pattern][@start_match].match(line)
50
- @end_match = match unless match.nil?
51
- !match.nil? == (@ending[:until] == :match)
52
- end
53
-
54
- # TODO: make failable (e.g. EOF)
55
- # @param [LogBuffer] lines
56
- # @return [Array<(LogMessage, Int)>]
57
- def read(lines)
58
- raise NotImplementedError if @ending.nil?
59
-
60
- ending = lines.find_index(1) { |l| ends_at?(l) }
61
- raise "Did not find end of message (pattern '#{self.class}')." if ending.nil?
62
- ending -= 1 unless @ending[:inclusive]
63
-
64
- # Use ending+1 since ending is the index when we drop the first line!
65
- msg = LogMessage.new(message: lines[0, ending + 1].join("\n"),
66
- preformatted: true, level: nil, pattern: self.class)
67
- [msg, ending + 1]
68
- end
69
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class TexLogParser
4
- VERSION = '1.0.0.pre.10'
5
- end