pushyd 0.9.2 → 0.9.4
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 +5 -3
- data/bin/pushyd +2 -2
- data/defaults.yml +1 -1
- data/lib/pushyd/endpoint.rb +3 -38
- data/lib/pushyd/proxy.rb +4 -6
- data/lib/pushyd/shouter.rb +4 -5
- data/lib/pushyd.rb +1 -6
- data/pushyd.gemspec +3 -3
- metadata +14 -17
- data/lib/shared/conf.rb +0 -201
- data/lib/shared/logger_formatter.rb +0 -31
- data/lib/shared/logger_helper.rb +0 -93
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f6680e8b9c8639d2230c50187affeda2816b658
|
4
|
+
data.tar.gz: c896cb6178136eb5293a8cf0922b06364bb82f27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d9a4132921a47b2f909bd915213c9bf48606769ba8bd0d854da8c6936fc982e9bb5fb6c9e072be7ad63a0a3fc4172e0eeffc1fbc65cff8e61ecc9f53716d673
|
7
|
+
data.tar.gz: 9ecfa2313ed02c2df6c8285b4da4b9adc5905ef10200aad5bb62ec30272fdb71a9b3808c59308de94178848a33e3fe4041897c0556fecbfa32310c56675a3805
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pushyd (0.9.
|
4
|
+
pushyd (0.9.4)
|
5
5
|
api-auth
|
6
|
+
bmc-daemon-lib (~> 0.2)
|
6
7
|
bunny (~> 2.3)
|
7
|
-
chamber (~> 2.9)
|
8
8
|
daemons
|
9
9
|
json
|
10
10
|
newrelic_rpm
|
@@ -18,7 +18,9 @@ GEM
|
|
18
18
|
amq-protocol (2.0.1)
|
19
19
|
api-auth (2.0.0)
|
20
20
|
ast (2.3.0)
|
21
|
-
|
21
|
+
bmc-daemon-lib (0.2.0)
|
22
|
+
chamber (~> 2.9)
|
23
|
+
bunny (2.5.0)
|
22
24
|
amq-protocol (>= 2.0.1)
|
23
25
|
chamber (2.9.0)
|
24
26
|
hashie (~> 3.3)
|
data/bin/pushyd
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
# Try to load external libs, helpers and constants
|
4
4
|
begin
|
5
5
|
require "rubygems"
|
6
|
+
require 'bmc-daemon-lib'
|
6
7
|
require "optparse"
|
7
8
|
require 'daemons'
|
8
|
-
require_relative "../lib/shared/conf"
|
9
9
|
rescue LoadError => e
|
10
10
|
raise "EXITING: some basic libs were not found (#{e.message})"
|
11
11
|
end
|
12
|
-
include
|
12
|
+
include BmcDaemonLib
|
13
13
|
|
14
14
|
|
15
15
|
# Handle configuration
|
data/defaults.yml
CHANGED
data/lib/pushyd/endpoint.rb
CHANGED
@@ -2,18 +2,19 @@ require 'bunny'
|
|
2
2
|
require "securerandom"
|
3
3
|
|
4
4
|
module PushyDaemon
|
5
|
+
# Class exceptions
|
5
6
|
class EndpointConnexionContext < StandardError; end
|
6
7
|
class EndpointConnectionError < StandardError; end
|
7
8
|
class EndpointSubscribeContext < StandardError; end
|
8
9
|
class EndpointSubscribeError < StandardError; end
|
9
10
|
|
10
11
|
class Endpoint
|
11
|
-
include
|
12
|
+
include BmcDaemonLib::LoggerHelper
|
12
13
|
attr_reader :logger
|
13
14
|
|
14
15
|
def initialize
|
15
16
|
# Prepare logger
|
16
|
-
|
17
|
+
@logger = BmcDaemonLib::LoggerPool.instance.get :file
|
17
18
|
|
18
19
|
# Done
|
19
20
|
log_info "endpoint initialized"
|
@@ -21,42 +22,6 @@ module PushyDaemon
|
|
21
22
|
|
22
23
|
protected
|
23
24
|
|
24
|
-
def init_logger logconf
|
25
|
-
# Check structure conformity or set it to an empty hash
|
26
|
-
logconf = {} unless logconf.is_a? Hash
|
27
|
-
loglevel = logconf[:level]
|
28
|
-
me = self.class.name
|
29
|
-
|
30
|
-
# Compute logfile
|
31
|
-
logfile = logfile(logconf, :file)
|
32
|
-
|
33
|
-
# Prepare logger (may be NIL > won't output anything)
|
34
|
-
@logger = Logger.new(logfile, LOG_ROTATION)
|
35
|
-
@logger.formatter = Shared::LoggerFormatter
|
36
|
-
|
37
|
-
# Set progname
|
38
|
-
@logger.progname = me.split('::').last
|
39
|
-
|
40
|
-
# Set expected level
|
41
|
-
@logger.level = case loglevel
|
42
|
-
when "debug"
|
43
|
-
Logger::DEBUG
|
44
|
-
when "info"
|
45
|
-
Logger::INFO
|
46
|
-
when "warn"
|
47
|
-
Logger::WARN
|
48
|
-
else
|
49
|
-
Logger::INFO
|
50
|
-
end
|
51
|
-
|
52
|
-
# Announce on STDOUT we're now logging to file
|
53
|
-
if logfile
|
54
|
-
puts "#{self.class} logging loglevel [#{loglevel} > #{@logger.level}] to [#{logfile}]"
|
55
|
-
else
|
56
|
-
puts "#{self.class} logging disabled"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
25
|
def log_message msg_way, msg_exchange, msg_key, msg_body = [], msg_attrs = {}
|
61
26
|
# Message header
|
62
27
|
info sprintf("%3s %-15s %s", msg_way, msg_exchange, msg_key)
|
data/lib/pushyd/proxy.rb
CHANGED
@@ -5,7 +5,9 @@ require 'terminal-table'
|
|
5
5
|
module PushyDaemon
|
6
6
|
class Proxy < Endpoint
|
7
7
|
include Shared::HmacSignature
|
8
|
+
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
8
9
|
|
10
|
+
# Class options
|
9
11
|
attr_accessor :table
|
10
12
|
|
11
13
|
def initialize
|
@@ -166,12 +168,8 @@ module PushyDaemon
|
|
166
168
|
end
|
167
169
|
|
168
170
|
# NewRelic instrumentation
|
169
|
-
|
170
|
-
|
171
|
-
add_transaction_tracer :handle_message, category: :task
|
172
|
-
add_transaction_tracer :propagate, category: :task
|
173
|
-
end
|
171
|
+
add_transaction_tracer :handle_message, category: :task
|
172
|
+
add_transaction_tracer :propagate, category: :task
|
174
173
|
|
175
174
|
end
|
176
175
|
end
|
177
|
-
|
data/lib/pushyd/shouter.rb
CHANGED
@@ -6,7 +6,9 @@ module PushyDaemon
|
|
6
6
|
class EndpointTopicContext < StandardError; end
|
7
7
|
|
8
8
|
class Shouter < Endpoint
|
9
|
+
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
9
10
|
|
11
|
+
# Class options
|
10
12
|
attr_accessor :table
|
11
13
|
|
12
14
|
def initialize
|
@@ -101,11 +103,8 @@ module PushyDaemon
|
|
101
103
|
end
|
102
104
|
|
103
105
|
# NewRelic instrumentation
|
104
|
-
|
105
|
-
|
106
|
-
add_transaction_tracer :channel_shout, category: :task
|
107
|
-
add_transaction_tracer :shout, category: :task
|
108
|
-
end
|
106
|
+
add_transaction_tracer :channel_shout, category: :task
|
107
|
+
add_transaction_tracer :shout, category: :task
|
109
108
|
|
110
109
|
end
|
111
110
|
end
|
data/lib/pushyd.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
# Global libs
|
2
2
|
require "rubygems"
|
3
|
+
require 'bmc-daemon-lib'
|
3
4
|
require "yaml"
|
4
5
|
require "json"
|
5
|
-
#require "thread"
|
6
|
-
#require "singleton"
|
7
6
|
require "newrelic_rpm"
|
8
7
|
|
9
|
-
|
10
8
|
# Shared libs
|
11
|
-
require_relative "shared/logger_formatter"
|
12
|
-
require_relative "shared/logger_helper"
|
13
9
|
require_relative "shared/hmac_signature"
|
14
|
-
require_relative "shared/conf"
|
15
10
|
|
16
11
|
# Project libs
|
17
12
|
require_relative "pushyd/constants"
|
data/pushyd.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
# Project version
|
4
|
-
spec.version = "0.9.
|
4
|
+
spec.version = "0.9.4"
|
5
5
|
|
6
6
|
# Project description
|
7
7
|
spec.name = "pushyd"
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0")
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
|
-
spec.required_ruby_version = ">= 2.2
|
20
|
+
spec.required_ruby_version = ">= 2.2"
|
21
21
|
|
22
22
|
# Development dependencies
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
@@ -28,8 +28,8 @@ Gem::Specification.new do |spec|
|
|
28
28
|
# spec.add_development_dependency "pry"
|
29
29
|
|
30
30
|
# Runtime dependencies
|
31
|
+
spec.add_runtime_dependency "bmc-daemon-lib", "~> 0.2"
|
31
32
|
spec.add_runtime_dependency "daemons"
|
32
|
-
spec.add_runtime_dependency "chamber", "~> 2.9"
|
33
33
|
spec.add_runtime_dependency "json"
|
34
34
|
spec.add_runtime_dependency "bunny", "~> 2.3"
|
35
35
|
spec.add_runtime_dependency "rest-client", "~> 1.8"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pushyd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno MEDICI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,33 +81,33 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: bmc-daemon-lib
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
89
|
+
version: '0.2'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
96
|
+
version: '0.2'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: daemons
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '0'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: json
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -214,10 +214,7 @@ files:
|
|
214
214
|
- lib/pushyd/endpoint.rb
|
215
215
|
- lib/pushyd/proxy.rb
|
216
216
|
- lib/pushyd/shouter.rb
|
217
|
-
- lib/shared/conf.rb
|
218
217
|
- lib/shared/hmac_signature.rb
|
219
|
-
- lib/shared/logger_formatter.rb
|
220
|
-
- lib/shared/logger_helper.rb
|
221
218
|
- pushyd.gemspec
|
222
219
|
homepage: http://github.com/bmedici/pushyd
|
223
220
|
licenses:
|
@@ -231,7 +228,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
231
228
|
requirements:
|
232
229
|
- - ">="
|
233
230
|
- !ruby/object:Gem::Version
|
234
|
-
version: 2.2
|
231
|
+
version: '2.2'
|
235
232
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
233
|
requirements:
|
237
234
|
- - ">="
|
@@ -239,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
236
|
version: '0'
|
240
237
|
requirements: []
|
241
238
|
rubyforge_project:
|
242
|
-
rubygems_version: 2.
|
239
|
+
rubygems_version: 2.6.6
|
243
240
|
signing_key:
|
244
241
|
specification_version: 4
|
245
242
|
summary: A nice proxy listenning to a RabbitMQ bus, repeating selected messages in
|
data/lib/shared/conf.rb
DELETED
@@ -1,201 +0,0 @@
|
|
1
|
-
# FIXME: files named with hyphens will not be found by Chamber for now
|
2
|
-
require "chamber"
|
3
|
-
|
4
|
-
module Shared
|
5
|
-
class ConfigMissingParameter < StandardError; end
|
6
|
-
class ConfigOtherError < StandardError; end
|
7
|
-
class ConfigParseError < StandardError; end
|
8
|
-
class ConfigMultipleGemspec < StandardError; end
|
9
|
-
class ConfigMissingGemspec < StandardError; end
|
10
|
-
|
11
|
-
class Conf
|
12
|
-
extend Chamber
|
13
|
-
PIDFILE_DIR = "/tmp/"
|
14
|
-
|
15
|
-
class << self
|
16
|
-
attr_accessor :app_env
|
17
|
-
attr_reader :app_root
|
18
|
-
attr_reader :app_libs
|
19
|
-
attr_reader :app_name
|
20
|
-
attr_reader :app_ver
|
21
|
-
attr_reader :app_started
|
22
|
-
attr_reader :app_spec
|
23
|
-
attr_reader :files
|
24
|
-
attr_reader :host
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.init app_root
|
28
|
-
# Permanent flags
|
29
|
-
@initialized = true
|
30
|
-
@app_started = Time.now
|
31
|
-
|
32
|
-
# Default values
|
33
|
-
@files ||= []
|
34
|
-
@app_name ||= "app_name"
|
35
|
-
@app_env ||= "production"
|
36
|
-
@host ||= `hostname`.to_s.chomp.split(".").first
|
37
|
-
|
38
|
-
# Store and clean app_root
|
39
|
-
@app_root = File.expand_path(app_root)
|
40
|
-
|
41
|
-
# Try to find any gemspec file
|
42
|
-
matches = Dir["#{@app_root}/*.gemspec"]
|
43
|
-
fail ConfigMissingGemspec, "gemspec file not found: #{gemspec_path}" if matches.size < 1
|
44
|
-
fail ConfigMultipleGemspec, "gemspec file not found: #{gemspec_path}" if matches.size > 1
|
45
|
-
|
46
|
-
# Load Gemspec (just the only match)
|
47
|
-
@spec = Gem::Specification::load(matches.first)
|
48
|
-
@app_name = @spec.name
|
49
|
-
@app_ver = @spec.version
|
50
|
-
fail ConfigMissingParameter, "gemspec: missing name" unless @app_name
|
51
|
-
fail ConfigMissingParameter, "gemspec: missing version" unless @app_ver
|
52
|
-
|
53
|
-
# Now we know app_name, initalize app_libs
|
54
|
-
@app_libs = File.expand_path("lib/#{@app_name}/", @app_root)
|
55
|
-
|
56
|
-
# Add other config files
|
57
|
-
#add_default_config
|
58
|
-
add_config generate(:config_defaults)
|
59
|
-
add_config generate(:config_etc)
|
60
|
-
|
61
|
-
# Return something
|
62
|
-
return @app_name
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.prepare args = {}
|
66
|
-
ensure_init
|
67
|
-
|
68
|
-
# Add extra config file and load them all
|
69
|
-
add_config args[:config]
|
70
|
-
reload!
|
71
|
-
|
72
|
-
# Set Rack env
|
73
|
-
ENV["RACK_ENV"] = @app_env.to_s
|
74
|
-
|
75
|
-
# Set up encodings
|
76
|
-
Encoding.default_internal = "utf-8"
|
77
|
-
Encoding.default_external = "utf-8"
|
78
|
-
|
79
|
-
# Init New Relic
|
80
|
-
newrelic_logfile = File.expand_path(Conf[:logs][:newrelic].to_s, Conf[:logs][:path].to_s)
|
81
|
-
prepare_newrelic self[:newrelic], newrelic_logfile
|
82
|
-
|
83
|
-
# Try to access any key to force parsing of the files
|
84
|
-
self[:dummy]
|
85
|
-
|
86
|
-
rescue Psych::SyntaxError => e
|
87
|
-
fail ConfigParseError, e.message
|
88
|
-
rescue StandardError => e
|
89
|
-
fail ConfigOtherError, "#{e.message} \n #{e.backtrace.to_yaml}"
|
90
|
-
end
|
91
|
-
|
92
|
-
# Reload files
|
93
|
-
def self.reload!
|
94
|
-
ensure_init
|
95
|
-
load_files
|
96
|
-
end
|
97
|
-
|
98
|
-
def self.dump
|
99
|
-
ensure_init
|
100
|
-
to_hash.to_yaml(indent: 4, useheader: true, useversion: false )
|
101
|
-
end
|
102
|
-
|
103
|
-
# Direct access to any depth
|
104
|
-
def self.at *path
|
105
|
-
ensure_init
|
106
|
-
path.reduce(Conf) { |m, key| m && m[key.to_s] }
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.newrelic_enabled?
|
110
|
-
ensure_init
|
111
|
-
self[:newrelic] && self[:newrelic][:licence]
|
112
|
-
end
|
113
|
-
|
114
|
-
# Defaults generators
|
115
|
-
def self.generate what
|
116
|
-
ensure_init
|
117
|
-
return case what
|
118
|
-
|
119
|
-
when :user_agent
|
120
|
-
"#{@app_name}/#{@app_ver}" if @app_name && @app_ver
|
121
|
-
|
122
|
-
when :config_defaults
|
123
|
-
"#{@app_root}/defaults.yml" if @app_root
|
124
|
-
|
125
|
-
when :config_etc
|
126
|
-
"/etc/#{@app_name}.yml" if @app_name
|
127
|
-
|
128
|
-
when :process_name
|
129
|
-
parts = [@app_name, @app_env]
|
130
|
-
parts << self[:port] if self[:port]
|
131
|
-
parts.join('-')
|
132
|
-
|
133
|
-
when :pidfile
|
134
|
-
process_name = self.generate(:process_name)
|
135
|
-
File.expand_path "#{process_name}.pid", PIDFILE_DIR
|
136
|
-
|
137
|
-
when :config_message
|
138
|
-
config_defaults = self.generate(:config_defaults)
|
139
|
-
config_etc = self.generate(:config_etc)
|
140
|
-
|
141
|
-
"A default configuration is available (#{config_defaults}) and can be copied to the default location (#{config_etc}): \n sudo cp #{config_defaults} #{config_etc}"
|
142
|
-
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
|
147
|
-
protected
|
148
|
-
|
149
|
-
def self.load_files
|
150
|
-
load files: @files, namespaces: { environment: @app_env }
|
151
|
-
end
|
152
|
-
|
153
|
-
def self.add_config path
|
154
|
-
@files << File.expand_path(path) if path && File.readable?(path)
|
155
|
-
end
|
156
|
-
|
157
|
-
def self.prepare_newrelic section, logfile
|
158
|
-
# Disable NewRelic if no config present
|
159
|
-
unless self.newrelic_enabled?
|
160
|
-
ENV["NEWRELIC_AGENT_ENABLED"] = "false"
|
161
|
-
return
|
162
|
-
end
|
163
|
-
|
164
|
-
# Enable GC profiler
|
165
|
-
GC::Profiler.enable
|
166
|
-
|
167
|
-
# Enable module
|
168
|
-
ENV["NEWRELIC_AGENT_ENABLED"] = "true"
|
169
|
-
ENV["NEW_RELIC_MONITOR_MODE"] = "true"
|
170
|
-
|
171
|
-
# License
|
172
|
-
ENV["NEW_RELIC_LICENSE_KEY"] = section[:licence].to_s
|
173
|
-
|
174
|
-
# Build NewRelic app_name if not provided as-is
|
175
|
-
if section[:app_name]
|
176
|
-
ENV["NEW_RELIC_APP_NAME"] = section[:app_name].to_s
|
177
|
-
else
|
178
|
-
stack = []
|
179
|
-
stack << (section[:prefix] || @app_name)
|
180
|
-
stack << section[:platform] if section[:platform]
|
181
|
-
stack << @app_env
|
182
|
-
text = stack.join('-')
|
183
|
-
ENV["NEW_RELIC_APP_NAME"] = "#{text}-#{host};#{text}"
|
184
|
-
end
|
185
|
-
|
186
|
-
# Logfile
|
187
|
-
ENV["NEW_RELIC_LOG"] = logfile.to_s if logfile
|
188
|
-
end
|
189
|
-
|
190
|
-
private
|
191
|
-
|
192
|
-
def self.ensure_init
|
193
|
-
# Skip is already done
|
194
|
-
return if @initialized
|
195
|
-
|
196
|
-
# Go through init if not already done
|
197
|
-
self.init
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
201
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Shared
|
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
|
-
def self.trimmed line
|
27
|
-
line.to_s.rstrip[0..LOG_MESSAGE_TRIM].force_encoding(Encoding::UTF_8)
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
data/lib/shared/logger_helper.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
require "logger"
|
2
|
-
|
3
|
-
module Shared
|
4
|
-
module LoggerHelper
|
5
|
-
CONFIG_PATH = :path
|
6
|
-
|
7
|
-
def logfile config, pipe
|
8
|
-
# Disabled if no valid config
|
9
|
-
return nil unless config.is_a?(Hash)
|
10
|
-
|
11
|
-
# Compute logfile and check if we can write there
|
12
|
-
logfile = File.expand_path(config[pipe].to_s, config[CONFIG_PATH].to_s)
|
13
|
-
|
14
|
-
# Check that we'll be able to create logfiles
|
15
|
-
if File.exists?(logfile)
|
16
|
-
# File is there, is it writable ?
|
17
|
-
unless File.writable?(logfile)
|
18
|
-
puts "LoggerHelper [#{pipe}] disabled: file not writable [#{logfile}]"
|
19
|
-
return nil
|
20
|
-
end
|
21
|
-
else
|
22
|
-
# No file here, can we create it ?
|
23
|
-
logdir = File.dirname(logfile)
|
24
|
-
unless File.writable?(logdir)
|
25
|
-
puts "LoggerHelper [#{pipe}] disabled: directory not writable [#{logdir}]"
|
26
|
-
return nil
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# OK, return a clean file path
|
31
|
-
puts "LoggerHelper [#{pipe}] logging to [#{logfile}]"
|
32
|
-
return logfile
|
33
|
-
end
|
34
|
-
|
35
|
-
protected
|
36
|
-
|
37
|
-
def log_info message, details = nil
|
38
|
-
build_messages Logger::INFO, message, details
|
39
|
-
end
|
40
|
-
|
41
|
-
def log_error message, details = nil
|
42
|
-
build_messages Logger::ERROR, message, details
|
43
|
-
end
|
44
|
-
|
45
|
-
def log_debug message, details = nil
|
46
|
-
build_messages Logger::DEBUG, message, details
|
47
|
-
end
|
48
|
-
|
49
|
-
alias info log_info
|
50
|
-
alias error log_error
|
51
|
-
alias debug log_debug
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
# Builds prefix if LOG_PREFIX_FORMAT defined and caller has log_prefix method to provide values
|
56
|
-
def build_prefix
|
57
|
-
# Skip if no values from user class
|
58
|
-
return unless respond_to?(:log_prefix, true)
|
59
|
-
values = log_prefix
|
60
|
-
|
61
|
-
# Skip if no format defined
|
62
|
-
return unless defined?('LOG_PREFIX_FORMAT')
|
63
|
-
return unless LOG_PREFIX_FORMAT.is_a? String
|
64
|
-
|
65
|
-
# Build prefix string
|
66
|
-
LOG_PREFIX_FORMAT % values.map(&:to_s)
|
67
|
-
end
|
68
|
-
|
69
|
-
def build_messages severity, message, details = nil
|
70
|
-
messages = []
|
71
|
-
|
72
|
-
prefix = build_prefix
|
73
|
-
|
74
|
-
# Add main message
|
75
|
-
messages << sprintf(LOG_MESSAGE_TEXT, prefix, message) if message
|
76
|
-
|
77
|
-
# Add details from array
|
78
|
-
details.each do |line|
|
79
|
-
messages << sprintf(LOG_MESSAGE_ARRAY, prefix, line)
|
80
|
-
end if details.is_a? Array
|
81
|
-
|
82
|
-
# Add details from hash
|
83
|
-
details.each do |key, value|
|
84
|
-
messages << sprintf(LOG_MESSAGE_HASH, prefix, key, value)
|
85
|
-
end if details.is_a? Hash
|
86
|
-
|
87
|
-
# Return all that stuff
|
88
|
-
# messages << "\\---------------------------------------"
|
89
|
-
logger.add severity, messages
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
end
|