lib/tailog.rb in tailog-0.3.1 vs lib/tailog.rb in tailog-0.3.2

- old
+ new

@@ -3,25 +3,23 @@ require 'tailog/ext/file' require 'sinatra/base' require 'active_support/configurable' -require 'securerandom' +require 'socket' require 'open3' require 'json' module Tailog include ActiveSupport::Configurable extend Tailog::WatchMethods - config_accessor :log_path do - File.expand_path("log", Dir.pwd) - end + config_accessor :log_path + self.log_path = File.expand_path("log", Dir.pwd) - config_accessor :server_uuid do - SecureRandom.uuid - end + config_accessor :server_hostname + self.server_hostname = Socket.gethostname class App < Sinatra::Base set :root, File.expand_path("../../app", __FILE__) set :public_folder do "#{root}/assets" end set :views do "#{root}/views" end @@ -43,11 +41,11 @@ post '/logs' do begin file_path = File.join Tailog.log_path, params[:file] file = File.open file_path file_size = file.size - tail = if seek = params[:seek] && params[:seek][Tailog.server_uuid] + tail = if seek = params[:seek] && params[:seek][Tailog.server_hostname] file.seek seek.to_i file else file.tail(100).join("\n") end @@ -56,11 +54,11 @@ rescue => error content = erb :error, locals: { error: error }, layout: false end { - server_uuid: Tailog.server_uuid, + server_hostname: Tailog.server_hostname, file_size: file_size, content: content }.to_json end @@ -74,9 +72,10 @@ post '/script' do content = erb :"script/#{params[:type]}", locals: { script: params[:script] }, layout: false { + server_hostname: Tailog.server_hostname, content: content }.to_json end end end