Kouhei Sutou
null+****@clear*****
Mon Jan 15 14:30:37 JST 2018
Kouhei Sutou 2018-01-15 14:30:37 +0900 (Mon, 15 Jan 2018) New Revision: ac31126aaa4a79a235fe698773e3f69eadd40ae7 https://github.com/groonga/groonga-log/commit/ac31126aaa4a79a235fe698773e3f69eadd40ae7 Message: Move paths parsing code from groonga-query-log Modified files: lib/groonga-log/parser.rb Modified: lib/groonga-log/parser.rb (+25 -0) =================================================================== --- lib/groonga-log/parser.rb 2018-01-15 14:21:04 +0900 (c9534f9) +++ lib/groonga-log/parser.rb 2018-01-15 14:30:37 +0900 (314d3c8) @@ -25,6 +25,8 @@ module GroongaLog \|(?<log_level>.) \|(?:(?<pid>\d+):)? \ (?<message>.*)/x + PATH_TIMESTAMP_PATTERN = /(\d{4})-(\d{2})-(\d{2})- + (\d{2})-(\d{2})-(\d{2})-(\d{6})\z/x class << self def target_line?(line) @@ -36,6 +38,18 @@ module GroongaLog true end + + def sort_paths(paths) + paths.sort_by do |path| + match_data = PATH_TIMESTAMP_PATTERN.match(File.basename(path)) + if match_data + values = match_data.to_a[1..-1].collect(&:to_i) + Time.local(*values) + else + Time.now + end + end + end end def parse(input) @@ -66,6 +80,17 @@ module GroongaLog end end + def parse_paths(paths, &block) + return to_enum(__method__, paths) unless block_given? + + target_paths = self.class.sort_paths(filter_paths(paths)) + target_paths.each do |path| + File.open(path) do |log| + parse(log, &block) + end + end + end + private def log_level_to_symbol(level_text) case level_text -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180115/036e37c9/attachment-0001.htm