Class: ActiveWrapper::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/active_wrapper/log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Log

Returns a new instance of Log.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_wrapper/log.rb', line 6

def initialize(options)
  @base = options[:base]
  @log = options[:log]
  @stdout = options[:stdout]
  
  return if @log == false
  
  FileUtils.mkdir_p("#{base}/log")
  file = File.open("#{base}/log/#{log}.log", 'a')
  file.sync = true
  
  if stdout
    @logger = Logger.new($stdout)
    $stdout.reopen(file)
    $stderr.reopen(file)
  else
    @logger = Logger.new(file)
  end
  
  ActiveRecord::Base.logger = @logger
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



35
36
37
# File 'lib/active_wrapper/log.rb', line 35

def method_missing(method, *args)
  logger.send(method, *args)
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



4
5
6
# File 'lib/active_wrapper/log.rb', line 4

def base
  @base
end

#logObject (readonly)

Returns the value of attribute log.



4
5
6
# File 'lib/active_wrapper/log.rb', line 4

def log
  @log
end

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/active_wrapper/log.rb', line 4

def logger
  @logger
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



4
5
6
# File 'lib/active_wrapper/log.rb', line 4

def stdout
  @stdout
end

Instance Method Details

#clearObject



28
29
30
31
32
33
# File 'lib/active_wrapper/log.rb', line 28

def clear
  Dir["#{base}/log/*.log"].each do |file|
    f = File.open(file, "w")
    f.close
  end
end