class YJCocoa::Log
Usage
Constants
- LOG_FILE
Attributes
dir[RW]
match[RW]
Public Class Methods
new(argv)
click to toggle source
初始化
Calls superclass method
# File lib/yjcocoa/log/log.rb, line 35 def initialize(argv) super self.dir = argv.option('dir') self.match = argv.option('match') self.match = self.match.split(",").reject {|i| i.empty? } if self.match end
options()
click to toggle source
Calls superclass method
YJCocoa::Command::options
# File lib/yjcocoa/log/log.rb, line 25 def self.options [['--dir', '文件夹地址'], ['--match', '匹配的字符串']] + super end
Public Instance Methods
check(line)
click to toggle source
# File lib/yjcocoa/log/log.rb, line 75 def check (line) self.match.each { |m| if line.include?(m) return true end } return false end
run()
click to toggle source
# File lib/yjcocoa/log/log.rb, line 55 def run Dir.chdir(self.dir) { log = "" File.delete(LOG_FILE) if File.exist?(LOG_FILE) for path in Dir["**/*.log"].sort do puts "解析日志 #{path}".green File.open(path, "r") { |file| while line = file.gets if self.check(line) log << line end end } end puts "\n解析完毕,打开日志:#{dir}/#{LOG_FILE}".green File.write(LOG_FILE, log) `open #{LOG_FILE}` } end
validate!()
click to toggle source
businrss
Calls superclass method
# File lib/yjcocoa/log/log.rb, line 43 def validate! super unless self.dir && Dir.exist?(self.dir) puts "dir:#{self.dir} 文件夹不存在".red self.banner! end unless self.match && self.match.length > 0 puts "match 为空".red self.banner! end end