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 +4 -4
- data/Gemfile.lock +1 -1
- data/bmc-daemon-lib.gemspec +1 -1
- data/lib/bmc-daemon-lib/conf.rb +34 -18
- data/lib/bmc-daemon-lib/logger.rb +17 -7
- data/lib/bmc-daemon-lib/logger_helper.rb +4 -6
- data/lib/bmc-daemon-lib/logger_pool.rb +1 -1
- data/lib/bmc-daemon-lib/mq_endpoint.rb +0 -5
- data/lib/bmc-daemon-lib/worker_base.rb +0 -1
- metadata +1 -2
- data/lib/bmc-daemon-lib/logger_formatter.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1771d9c5fcae4ddbf8779639cd94f3155144b309
|
4
|
+
data.tar.gz: 2040e4242235669e72057e2a4da917d6c2918d4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 355980e1711281c1be04016f59e838b655b720da1c7261b123403debad4a7803c7bf9bf4ccef2770b52da90b15eae10cd42dfb1fbbe96f9a05501bc14b1fcc41
|
7
|
+
data.tar.gz: f9c6d1af6e0a152668b5b7c43b9094932f148f0783f8c40f6df72f3734e116bc0ebe57594321bce8548fb7209142173e0a813e5c841136fc176e60629d3ee0e2
|
data/Gemfile.lock
CHANGED
data/bmc-daemon-lib.gemspec
CHANGED
data/lib/bmc-daemon-lib/conf.rb
CHANGED
@@ -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
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
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
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
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 =
|
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
|
80
|
-
def build_context
|
89
|
+
# Builds prefix from @format[:context] and context
|
90
|
+
def build_context context
|
81
91
|
# Skip if no format defined
|
82
|
-
return
|
92
|
+
return unless @format[:context].is_a? Hash
|
83
93
|
|
84
|
-
# Call the instance's method to get hash
|
85
|
-
return
|
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,
|
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
|
-
{}
|
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
|
-
|
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
|
37
|
+
def full_context
|
40
38
|
# Grab the classe's context
|
41
39
|
context = log_context()
|
42
40
|
|
43
|
-
# Initialize an empty context,
|
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 =
|
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
|
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.
|
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
|