Sha256: 1ee8a0d21f3048d44a194f892cce682a5a6ea06644f671a4cf397697c610b811

Contents?: true

Size: 1.84 KB

Versions: 11

Compression:

Stored size: 1.84 KB

Contents

grammar Formatting

  rule format_string
    (token / literal)+
  end

  rule literal
    . {
      def value(log_line, color)
        # context-independent...
        self.text_value
      end
    }
  end

  rule token
    remote_addr / remote_user / time_local / request / status / body_bytes_sent / http_referer / http_user_agent / proxy_addresses
  end

  rule remote_addr
    '%a' <Node> {
      def value(log_line, color)
        if color && Sickill::Rainbow.enabled
          # 24 = 15 + 9, the extra amount of bytes required for the ANSI escape codes...
          "%24s" % foreground(log_line.remote_address, color)
        else
          "%15s" % log_line.remote_address
        end
      end
    }
  end

  rule remote_user
    '%u' <Node> {
      def value(log_line, color)
        foreground(log_line.remote_user, color)
      end
    }
  end

  rule time_local
    '%t' <Node> {
      def value(log_line, color)
        foreground(log_line.to_date_s, color)
      end
    }
  end

  rule request
    '%r' <Node> {
      def value(log_line, color)
        foreground(log_line.to_request_s, color)
      end
    }
  end

  rule status
    '%s' <Node> {
      def value(log_line, color)
        foreground(log_line.status, color)
      end
    }
  end

  rule body_bytes_sent
    '%b' <Node> {
      def value(log_line, color)
        foreground(log_line.body_bytes_sent, color)
      end
    }
  end

  rule http_referer
    '%R' <Node> {
      def value(log_line, color)
        foreground(log_line.to_referer_s, color)
      end
    }
  end

  rule http_user_agent
    '%U' <Node> {
      def value(log_line, color)
        foreground(log_line.to_agent_s, color)
      end
    }
  end

  rule proxy_addresses
    '%p' <Node> {
      def value(log_line, color)
        (log_line.proxy_addresses || []).join(", ").foreground(color)
      end
    }
  end

end

# vim:syntax=ruby

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ntail-1.2.0 lib/ntail/formatting.treetop
ntail-1.1.4 lib/ntail/formatting.treetop
ntail-1.1.3 lib/ntail/formatting.treetop
ntail-1.1.2 lib/ntail/formatting.treetop
ntail-1.1.1 lib/ntail/formatting.treetop
ntail-1.1.0 lib/ntail/formatting.treetop
ntail-1.0.2 lib/ntail/formatting.treetop
ntail-1.0.0 lib/ntail/formatting.treetop
ntail-0.2.0 lib/ntail/formatting.treetop
ntail-0.1.0 lib/ntail/formatting.treetop
ntail-0.0.12 lib/ntail/formatting.treetop