module LogLineParser::CommandLineInterface
Constants
- DEFAULT_FORMAT
Public Class Methods
choose_log_parser(log_format)
click to toggle source
# File lib/log_line_parser/command_line_interface.rb, line 150 def self.choose_log_parser(log_format) parser = LogLineParser::PREDEFINED_FORMATS[log_format] parser || LogLineParser.parser(log_format) end
execute()
click to toggle source
# File lib/log_line_parser/command_line_interface.rb, line 155 def self.execute options = parse_options if options[:show_settings] show_settings(options) elsif options[:filter_mode] execute_as_filter(options) else execute_as_converter(options) end end
execute_as_converter(options, output=STDOUT, input=ARGF)
click to toggle source
# File lib/log_line_parser/command_line_interface.rb, line 177 def self.execute_as_converter(options, output=STDOUT, input=ARGF) Converter.new.execute(options, output, input) end
execute_as_filter(options)
click to toggle source
# File lib/log_line_parser/command_line_interface.rb, line 173 def self.execute_as_filter(options) Filter.new.execute(options) end
parse_options()
click to toggle source
# File lib/log_line_parser/command_line_interface.rb, line 98 def self.parse_options options = { log_format: LogLineParser::CombinedLogParser } OptionParser.new("USAGE: #{File.basename($0)} [OPTION]... [LOG_FILE]...") do |opt| opt.on("-c [config_file]", "--config [=config_file]", "Give a configuration file in yaml format") do |config_file| options[:config_file] = config_file end opt.on("-b [bots_config_file]", "--bots-config [=bots_config_file]", "Give a configuration file in yaml format. \ Default bots: #{Bots::DEFAULT_BOTS.join(', ')}") do |config_file| options[:bots_config_file] = config_file end opt.on("-s", "--show-current-settings", "Show the detail of the current settings") do options[:show_settings] = true end opt.on("-f", "--filter-mode", "Mode for choosing log records that satisfy certain criteria") do options[:filter_mode] = true end opt.on("-l [LogFormat]", "--log-format [=LogFormat]", "Specify LogFormat by giving a LogFormat or one of \ formats predefined as #{predefined_options_for_log_format}") do |log_format| options[:log_format] = choose_log_parser(log_format) end opt.on("-o [output_dir]", "--output-dir [=output_dir]", "Specify the output directory for log files") do |output_dir| options[:output_dir] = output_dir end opt.on("-t [format]", "--to [=format]", "Specify a format: csv, tsv or ltsv") do |format| options[:format] = format end opt.on("-e [error_log_file]", "--error-log [=error_log_file]", "Specify a file for error logging") do |error_log_file| options[:error_log_file] = error_log_file end opt.parse! end options end
show_settings(options)
click to toggle source
# File lib/log_line_parser/command_line_interface.rb, line 166 def self.show_settings(options) bots_re = Utils.compile_bots_re_from_config_file(options[:bots_config_file]) parser = options[:log_format] puts "The regular expression for bots: #{bots_re}" puts "LogFormat: #{parser.format_strings}" end
Private Class Methods
predefined_options_for_log_format()
click to toggle source
private class methods
# File lib/log_line_parser/command_line_interface.rb, line 183 def self.predefined_options_for_log_format PREDEFINED_FORMATS.keys. map {|opt| "\"#{opt}\"" }. join(", ") end