Class: SmartProxyDynflowCore::Log

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

Defined Under Namespace

Classes: ProxyAdapter, ProxyStructuredFormater

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, *rest) ⇒ Log



42
43
44
45
46
47
# File 'lib/smart_proxy_dynflow_core/log.rb', line 42

def initialize(file, *rest)
  @file = file
  @fd = @file.is_a?(IO) ? @file : File.open(@file, 'a')
  @fd.sync = true
  super(@fd, rest)
end

Class Method Details

.instanceObject



8
9
10
11
12
13
14
# File 'lib/smart_proxy_dynflow_core/log.rb', line 8

def instance
  if @logger.nil?
    @logger = self.new log_file
    @logger.level = log_level
  end
  @logger
end

.instance=(logger) ⇒ Object



16
17
18
# File 'lib/smart_proxy_dynflow_core/log.rb', line 16

def instance=(logger)
  @logger = logger
end

.log_fileObject



33
34
35
36
37
38
39
# File 'lib/smart_proxy_dynflow_core/log.rb', line 33

def log_file
  if Settings.instance.loaded && Settings.instance.log_file
    Settings.instance.log_file
  else
    $stdout
  end
end

.log_levelObject



25
26
27
28
29
30
31
# File 'lib/smart_proxy_dynflow_core/log.rb', line 25

def log_level
  if Settings.instance.loaded && Settings.instance.log_level
    ::Logger.const_get(Settings.instance.log_level.upcase)
  else
    Logger::WARN
  end
end

.reload!Object



20
21
22
23
# File 'lib/smart_proxy_dynflow_core/log.rb', line 20

def reload!
  @logger = nil
  instance
end

Instance Method Details

#roll_logObject



49
50
51
52
53
54
# File 'lib/smart_proxy_dynflow_core/log.rb', line 49

def roll_log
  unless @file.is_a? IO
    @fd.reopen @file, 'a'
    @fd.sync = true
  end
end