Sha256: 15caec408a92468a09806a8a0ce869d4ae1f3a172c48e76184756d7a72127fbc
Contents?: true
Size: 1.96 KB
Versions: 25
Compression:
Stored size: 1.96 KB
Contents
# # Copyright 2011 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by loglicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # module Backstage class Log include Resource attr_reader :file_path LOG_GLOB = "*log" class << self def to_hash_attributes super + [:name, :file_path, :size] end def all(log_dir = nil) log_dir ||= Backstage.jboss_log_dir Dir.glob("#{log_dir}/#{LOG_GLOB}").collect do |path| Log.new( File.expand_path( path ) ) end.sort_by(&:name) end alias_method :find, :new end def initialize(file_path) @file_path = file_path end alias_method :full_name, :file_path def name File.basename( file_path ) end def size File.size( file_path ) end def tail(options) offset = (options['offset'] || -1000).to_i File.open(@file_path, 'r') do |file| # Set offset to the beginning or end of the file if # the value passed in is less than or greather than # the min/max allowed if offset.abs > file.stat.size offset = offset < 0 ? 0 : file.stat.size end if offset < 0 file.seek(offset, IO::SEEK_END) file.readline # Advance to the next entire line else file.seek(offset) end lines = [] until file.eof? do lines << file.readline end offset = file.pos { :offset => offset, :lines => lines.compact } end end end end
Version data entries
25 entries across 25 versions & 1 rubygems