Module: LogTool
- Defined in:
- lib/logtool.rb,
lib/logtool/block.rb,
lib/logtool/query.rb,
lib/logtool/parser.rb
Defined Under Namespace
Class Method Summary collapse
- .execute ⇒ Object
- .fatal_error(err_msg = nil) ⇒ Object
- .parse_args ⇒ Object
- .supported_modes ⇒ Object
- .usage ⇒ Object
Class Method Details
.execute ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/logtool.rb', line 59 def self.execute = parse_args blocks = Parser.parse_blocks([:input_file]) case [:mode] when 'query' then query = Query.new(blocks, ) query.run else puts "Mode not implemented"; exit 1 end end |
.fatal_error(err_msg = nil) ⇒ Object
35 36 37 38 39 |
# File 'lib/logtool.rb', line 35 def self.fatal_error(err_msg=nil) puts err_msg if err_msg puts usage exit 1 end |
.parse_args ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/logtool.rb', line 45 def self.parse_args fatal_error if ARGV.size < 2 = {} [:input_file] = ARGV[0] [:mode] = ARGV[1] [:mode_args] = ARGV[2..-1] fatal_error("Invalid mode") unless self.supported_modes.include?([:mode]) return end |
.supported_modes ⇒ Object
41 42 43 |
# File 'lib/logtool.rb', line 41 def self.supported_modes %W(query) end |
.usage ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/logtool.rb', line 8 def self.usage <<USAGE Usage: logtool file mode mode_options File is the rails log file that should be parsed. Mode can be either gtk or query. For gtk, a window will open and let you explore the log file. For query, you can write a query that will be executed on the log entries. == Query mode == When using the query mode, mode_options should be in the following format: filter information [options]. The first parameter filters the log entries, the second one is the information you want to retrieve. The last one is the only optional one, where you can specify further options. ==filter== Boolean Operators: and, or, not Value Operators ==, <=, >=, <, > Values: ip, method, response, asset ==information to retrieve== ip, head, tail, method, time ==options== -l num: shows only the last num entries. Examples: logtool log/production.log query "ip == 127.0.0.1" head logtool log/production.log query "(ip == 127.0.0.1) and not asset" head logtool log/production.log query "(ip == 127.0.0.1) or (ip == 0.0.0.0) and not asset" head logtool log/production.log query "response > 200" ip USAGE end |