bmc-daemon-lib 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 717e62be1cf40cba5d185e3b874bf118ad484f16
4
- data.tar.gz: 8e7009af53b97eccda6ad9a6b9b4908d97a571a9
3
+ metadata.gz: 1771d9c5fcae4ddbf8779639cd94f3155144b309
4
+ data.tar.gz: 2040e4242235669e72057e2a4da917d6c2918d4a
5
5
  SHA512:
6
- metadata.gz: e8298d97416782976d686687db0ecb799a86a7541ce3c69e88b8e4248e96556c1c3d2980a50d72e0638b4487c8ff2c996734e071bbad40a138dae08bb7121e80
7
- data.tar.gz: 902afa597271e91c5debdbf87a86e7cede27c5b1d13adbcd079cda992734746be61edf47041401321ac66d3792e52e82f41ff838e49d012eb61b788b40da3c33
6
+ metadata.gz: 355980e1711281c1be04016f59e838b655b720da1c7261b123403debad4a7803c7bf9bf4ccef2770b52da90b15eae10cd42dfb1fbbe96f9a05501bc14b1fcc41
7
+ data.tar.gz: f9c6d1af6e0a152668b5b7c43b9094932f148f0783f8c40f6df72f3734e116bc0ebe57594321bce8548fb7209142173e0a813e5c841136fc176e60629d3ee0e2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bmc-daemon-lib (0.4.1)
4
+ bmc-daemon-lib (0.4.2)
5
5
  chamber (~> 2.9.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  # Project version
4
- spec.version = "0.4.1"
4
+ spec.version = "0.4.2"
5
5
 
6
6
  # Project description
7
7
  spec.name = "bmc-daemon-lib"
@@ -185,30 +185,31 @@ module BmcDaemonLib
185
185
  return unless self.feature?(:newrelic)
186
186
 
187
187
  # Ok, let's start
188
- section = self[:newrelic]
189
188
  log :conf, "prepare NewRelic"
189
+ conf = self[:newrelic]
190
190
 
191
191
  # Enable GC profiler
192
192
  GC::Profiler.enable
193
193
 
194
194
  # Build NewRelic app_name if not provided as-is
195
- if !section[:app_name]
196
- stack = []
197
- stack << (section[:prefix] || @app_name)
198
- stack << section[:platform] if section[:platform]
199
- stack << @app_env
200
- text = stack.join('-')
201
- section[:app_name] = "#{text}; #{text}-#{host}"
202
- end
195
+ self.newrelic_init_app_name(conf)
196
+
197
+ # Set env variables
198
+ ENV["NEW_RELIC_AGENT_ENABLED"] = "true"
199
+ ENV["NEW_RELIC_LOG"] = logfile_path(:newrelic)
200
+ ENV["NEW_RELIC_LICENSE_KEY"] = conf[:license].to_s
201
+ ENV["NEW_RELIC_APP_NAME"] = conf[:app_name].to_s
203
202
 
203
+ # logger_newrelic = Logger.new('/tmp/newrelic.log')
204
+ # logger_newrelic.debug Time.now()
204
205
  # Start the agent
205
- NewRelic::Agent.manual_start({
206
- agent_enabled: true,
207
- log: LoggerPool.instance.get(:newrelic),
208
- env: @app_env,
209
- license_key: section[:license].to_s,
210
- app_name: section[:app_name].to_s,
211
- })
206
+ # NewRelic::Agent.manual_start({
207
+ # agent_enabled: true,
208
+ # log: logger_newrelic,
209
+ # env: @app_env,
210
+ # license_key: conf[:license].to_s,
211
+ # app_name: conf[:app_name].to_s,
212
+ # })
212
213
  end
213
214
 
214
215
  def self.prepare_rollbar
@@ -221,13 +222,13 @@ module BmcDaemonLib
221
222
  end
222
223
 
223
224
  # Ok, let's start
224
- section = self[:rollbar]
225
225
  log :conf, "prepare Rollbar"
226
+ conf = self[:rollbar]
226
227
 
227
228
  # Configure
228
229
  Rollbar.configure do |config|
229
230
  config.enabled = true
230
- config.access_token = section[:token].to_s
231
+ config.access_token = conf[:token].to_s
231
232
  config.code_version = @app_version
232
233
  config.environment = @app_env
233
234
  config.logger = LoggerPool.instance.get(:rollbar)
@@ -249,6 +250,21 @@ module BmcDaemonLib
249
250
 
250
251
  protected
251
252
 
253
+ def self.newrelic_init_app_name conf
254
+ # Ignore if already set
255
+ return if conf[:app_name]
256
+
257
+ # Stack all those parts
258
+ stack = []
259
+ stack << (conf[:prefix] || @app_name)
260
+ stack << conf[:platform] if conf[:platform]
261
+ stack << @app_env
262
+ text = stack.join('-')
263
+
264
+ # Return a composite appname
265
+ conf[:app_name] = "#{text}; #{text}-#{@host}"
266
+ end
267
+
252
268
  def self.load_files
253
269
  load files: @files, namespaces: { environment: @app_env }
254
270
  end
@@ -14,7 +14,7 @@ module BmcDaemonLib
14
14
  trim: 400,
15
15
  }
16
16
 
17
- def initialize filename, rotation
17
+ def initialize filename, rotation = nil
18
18
  # Initialize
19
19
  super
20
20
  @format = DEFAULT_FORMAT
@@ -30,6 +30,16 @@ module BmcDaemonLib
30
30
  end
31
31
  end
32
32
 
33
+ # def info message
34
+ # add Logger::INFO, "INFO:#{message}"
35
+ # end
36
+ # def debug message
37
+ # add Logger::DEBUG, "DEBUG:#{message}"
38
+ # end
39
+ # def error message
40
+ # add Logger::ERROR, "ERROR:#{message}"
41
+ # end
42
+
33
43
  def add severity, message, context = nil, details = nil
34
44
  # Start from an empty messages list with the main message
35
45
  messages = []
@@ -76,17 +86,17 @@ module BmcDaemonLib
76
86
 
77
87
  private
78
88
 
79
- # Builds prefix from @format[:context] and values
80
- def build_context values
89
+ # Builds prefix from @format[:context] and context
90
+ def build_context context
81
91
  # Skip if no format defined
82
- return "[context is not a hash]" unless @format[:context].is_a? Hash
92
+ return unless @format[:context].is_a? Hash
83
93
 
84
- # Call the instance's method to get hash values
85
- return "[log_context is not a hash]" unless values.is_a? Hash
94
+ # Call the instance's method to get hash context
95
+ return unless context.is_a? Hash
86
96
 
87
97
  # Build each context part
88
98
  return @format[:context].collect do |key, format|
89
- sprintf(format, values[key])
99
+ sprintf(format, context[key])
90
100
  end.join
91
101
 
92
102
  rescue KeyError, ArgumentError => ex
@@ -14,7 +14,7 @@ module BmcDaemonLib
14
14
  end
15
15
 
16
16
  def log_context
17
- {} # ['DEFAULT', self.class.name.split('::').last]
17
+ {}
18
18
  end
19
19
 
20
20
  def log_info message, details = nil
@@ -31,16 +31,14 @@ module BmcDaemonLib
31
31
 
32
32
  def log severity, message, details
33
33
  return puts "LoggerHelper.log: missing logger (#{get_class_name})" unless logger
34
- # puts "LoggerHelper.log > #{message}"
35
- # puts "LoggerHelper.log > #{get_full_context.inspect}"
36
- logger.add severity, message, get_full_context, details
34
+ logger.add severity, message, full_context, details
37
35
  end
38
36
 
39
- def get_full_context
37
+ def full_context
40
38
  # Grab the classe's context
41
39
  context = log_context()
42
40
 
43
- # Initialize an empty context, if log_context returned something else, or it the method was not exposed
41
+ # Initialize an empty context, (log_context returned something bad, or method was not exposed)
44
42
  context = {} unless context.is_a? Hash
45
43
 
46
44
  # Who is the caller? Guess it from caller's class name if not provided
@@ -21,7 +21,7 @@ module BmcDaemonLib
21
21
  filename = Conf.logfile(pipe)
22
22
 
23
23
  # Create the logger and return it
24
- logger = BmcDaemonLib::Logger.new(filename, LOG_ROTATION) #, 10, 1024000)
24
+ logger = Logger.new(filename, LOG_ROTATION) #, 10, 1024000)
25
25
  logger.progname = pipe.to_s.downcase
26
26
 
27
27
  # Finally return this logger
@@ -1,9 +1,4 @@
1
1
  module BmcDaemonLib
2
- # class ShouterResponseError < StandardError; end
3
- # class ShouterChannelClosed < StandardError; end
4
- # class ShouterPreconditionFailed < StandardError; end
5
- # class ShouterInterrupted < StandardError; end
6
- # class EndpointTopicContext < StandardError; end
7
2
  class EndpointConnexionContext < StandardError; end
8
3
  class EndpointConnectionError < StandardError; end
9
4
  class EndpointSubscribeContext < StandardError; end
@@ -8,7 +8,6 @@ module BmcDaemonLib
8
8
 
9
9
  def initialize wid, pool = nil
10
10
  # Logger
11
- # FIXME log_pipe
12
11
  log_pipe :workers
13
12
  @log_worker_status_changes = true
14
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmc-daemon-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno MEDICI
@@ -83,7 +83,6 @@ files:
83
83
  - lib/bmc-daemon-lib.rb
84
84
  - lib/bmc-daemon-lib/conf.rb
85
85
  - lib/bmc-daemon-lib/logger.rb
86
- - lib/bmc-daemon-lib/logger_formatter.rb
87
86
  - lib/bmc-daemon-lib/logger_helper.rb
88
87
  - lib/bmc-daemon-lib/logger_pool.rb
89
88
  - lib/bmc-daemon-lib/mq_consumer.rb
@@ -1,27 +0,0 @@
1
- module BmcDaemonLib
2
- class LoggerFormatter
3
-
4
- def self.call severity, datetime, progname, payload
5
- # Build common values
6
- timestamp = datetime.strftime(LOG_HEADER_TIME)
7
-
8
- # Build header
9
- header = sprintf LOG_HEADER_FORMAT,
10
- timestamp,
11
- Process.pid,
12
- severity,
13
- progname
14
-
15
- # If we have a bunch of lines, prefix them and send them together
16
- return payload.map do |line|
17
- "#{header}#{trimmed(line)}\n"
18
- end.join if payload.is_a?(Array)
19
-
20
- # Otherwise, just prefix the only line
21
- return "#{header}#{trimmed(payload)}\n"
22
- end
23
-
24
- protected
25
-
26
- end
27
- end