Class: Fluent::Supervisor::LoggerInitializer

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/supervisor.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, level, chuser, chgroup, opts) ⇒ LoggerInitializer

Returns a new instance of LoggerInitializer.



53
54
55
56
57
58
59
# File 'lib/fluent/supervisor.rb', line 53

def initialize(path, level, chuser, chgroup, opts)
  @path = path
  @level = level
  @chuser = chuser
  @chgroup = chgroup
  @opts = opts
end

Instance Method Details

#initObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fluent/supervisor.rb', line 61

def init
  if @path && @path != "-"
    @io = File.open(@path, "a")
    if @chuser || @chgroup
      chuid = @chuser ? Supervisor.get_etc_passwd(@chuser).uid : nil
      chgid = @chgroup ? Supervisor.get_etc_group(@chgroup).gid : nil
      File.chown(chuid, chgid, @path)
    end
  else
    @io = STDOUT
  end

  $log = Fluent::Log.new(@io, @level, @opts)
  $log.enable_color(false) if @path
  $log.enable_debug if @level <= Fluent::Log::LEVEL_DEBUG
end

#level=(level) ⇒ Object



89
90
91
92
# File 'lib/fluent/supervisor.rb', line 89

def level=(level)
  @level = level
  $log.level = level
end

#reopen!Object



82
83
84
85
86
87
# File 'lib/fluent/supervisor.rb', line 82

def reopen!
  if @path && @path != "-"
    @io.reopen(@path, "a")
  end
  self
end

#stdout?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/fluent/supervisor.rb', line 78

def stdout?
  @io == STDOUT
end