Sha256: 4cf096ca70fd9b8b3fdf16d6baf3bd52d1733f809bfd997a6c292de547929223
Contents?: true
Size: 1.15 KB
Versions: 1
Compression:
Stored size: 1.15 KB
Contents
require 'tailog/version' require 'sinatra/base' class File def tail(n) buffer = 1024 idx = size > buffer ? size - buffer : 0 chunks = [] lines = 0 begin seek(idx) chunk = read(buffer) break unless chunk lines += chunk.count("\n") chunks.unshift chunk idx -= buffer end while lines < ( n + 1 ) && idx >= 0 chunks.join('').split(/\n/).last(n) end end module Tailog class << self attr_accessor :log_path attr_accessor :basic_auth end self.log_path = File.expand_path("log", Dir.pwd) self.basic_auth = proc do |username, password| username == (ENV['TAILOG_USERNAME'] || 'tailog') and password == (ENV['TAILOG_USERNAME'] || 'password') end class App < Sinatra::Base set :root, File.expand_path("../../app", __FILE__) set :public_folder do "#{root}/assets" end set :views do "#{root}/views" end use Rack::Auth::Basic, "Restricted Area", &Tailog.basic_auth helpers do def h(text) Rack::Utils.escape_html(text) end end get '/' do if params[:seek] erb :ajax else erb :index end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tailog-0.1.3 | lib/tailog.rb |