Class: Baykit::BayServer::Docker::BuiltIn::BuiltInLogDocker

Inherits:
Baykit::BayServer::Docker::Base::DockerBase show all
Includes:
Agent, Agent::Transporter, Bcf, Log, Util
Defined in:
lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb

Defined Under Namespace

Classes: AgentListener

Constant Summary collapse

LOG_WRITE_METHOD_SELECT =
1
LOG_WRITE_METHOD_SPIN =
2
LOG_WRITE_METHOD_TAXI =
3
DEFAULT_LOG_WRITE_METHOD =
LOG_WRITE_METHOD_TAXI

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from Baykit::BayServer::Docker::Base::DockerBase

#type

Instance Method Summary collapse

Methods inherited from Baykit::BayServer::Docker::Base::DockerBase

#init_docker, #to_s

Constructor Details

#initializeBuiltInLogDocker

Returns a new instance of BuiltInLogDocker.



96
97
98
99
100
101
# File 'lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb', line 96

def initialize
  @loggers = {}
  @format = nil
  @log_items = []
  @log_write_method = DEFAULT_LOG_WRITE_METHOD
end

Class Attribute Details

.log_item_mapObject (readonly)

Mapping table for format



76
77
78
# File 'lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb', line 76

def log_item_map
  @log_item_map
end

Instance Attribute Details

#file_extObject (readonly)

Returns the value of attribute file_ext.



81
82
83
# File 'lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb', line 81

def file_ext
  @file_ext
end

#file_prefixObject (readonly)

Log send_file name parts



80
81
82
# File 'lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb', line 80

def file_prefix
  @file_prefix
end

#formatObject (readonly)

Log format



88
89
90
# File 'lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb', line 88

def format
  @format
end

#log_itemsObject (readonly)

Log items



91
92
93
# File 'lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb', line 91

def log_items
  @log_items
end

#log_write_methodObject (readonly)

Log write method



94
95
96
# File 'lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb', line 94

def log_write_method
  @log_write_method
end

#loggersObject (readonly)

Logger for each agent.

Map of Agent ID => LogBoat


85
86
87
# File 'lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb', line 85

def loggers
  @loggers
end

Instance Method Details

#init(elm, parent) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb', line 103

def init(elm, parent)
  super
  p = elm.arg.rindex('.')
  if p == nil
    @file_prefix = elm.arg
    @file_ext = ""
  else
    @file_prefix = elm.arg[0, p]
    @file_ext = elm.arg[p+1 .. -1]
  end

  if @format == nil
    raise ConfigException.new(elm.file_name, elm.line_no, BayMessage.get(:CFG_INVALID_LOG_FORMAT, ""))
  end

  if !File.absolute_path?(@file_prefix)
    @file_prefix = BayServer.get_location @file_prefix
  end

  @loggers = Array.new(BayServer.harbor.grand_agents)

  log_dir = File.dirname(@file_prefix)
  if !File.directory?(log_dir)
    Dir.mkdir(log_dir)
  end

  # Parse format
  compile(@format, @log_items, elm.file_name, elm.line_no)

  # Check log write method
  if @log_write_method == LOG_WRITE_METHOD_SELECT and !SysUtil.support_select_file()
    BayLog.warn(BayMessage.get(:CFG_LOG_WRITE_METHOD_SELECT_NOT_SUPPORTED))
    @log_write_method = LOG_WRITE_METHOD_TAXI
  end

  if @log_write_method == LOG_WRITE_METHOD_SPIN and !SysUtil.support_nonblock_file_write()
    BayLog.warn(BayMessage.get(:CFG_LOG_WRITE_METHOD_SPIN_NOT_SUPPORTED))
    @log_write_method = LOG_WRITE_METHOD_TAXI
  end

  GrandAgent.add_lifecycle_listener(AgentListener.new(self));
end

#init_key_val(kv) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb', line 146

def init_key_val(kv)
  case kv.key.downcase
  when "format"
    @format = kv.value
  when "logwritemethod"
    case kv.value.downcase()
    when "select"
      @log_write_method = LOG_WRITE_METHOD_SELECT
    when "spin"
      @log_write_method = LOG_WRITE_METHOD_SPIN
    when "taxi"
      @log_write_method = LOG_WRITE_METHOD_TAXI
    else
      raise ConfigException.new(kv.file_name, kv.line_no, BayMessage.get(:CFG_INVALID_PARAMETER_VALUE, kv.value))
    end
  else
    return false
  end
  true
end

#log(tour) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb', line 167

def log(tour)
  sb = StringUtil.alloc(0)
  @log_items.each do |item|
    item = item.get_item(tour).to_s
    if item == nil
      sb << "-"
    else
      sb << item
    end
  end

  # If threre are message to write, write it
  if sb.length > 0
    get_logger(tour.ship.agent).log(sb)
  end
end