Ruby: check if object is nil

前端 未结 3 981
轮回少年
轮回少年 2021-02-14 16:07
  def parse( line )
    _, remote_addr, status, request, size, referrer, http_user_agent, http_x_forwarded_for = /^([^\\s]+) - (\\d+) \\\"(.+)\\\" (\\d+) \\\"(.*)\\\" \\         


        
3条回答
  •  盖世英雄少女心
    2021-02-14 16:27

    To write to a file:

    File.open("file.txt", "w") do |file|
      file.puts "whatever"
    end
    

    As I write in a comment above - you didn't say what is nil. Also, check whether referrer contains what you think it contains. EDIT I see it's request that is nil. Obviously, regexp trouble.

    Use rubular.com to easily test your regexp. Copy a line from your input file into "Your test string", and your regexp into "Your regular expression", and tweak until you get a highlight in "Match result".

    Also, what are "wrong logging strings"? If we're talking Apache, log format is configurable.

提交回复
热议问题