insights-loggers-ruby 0.1.7 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d20b60ac3a89c2e8e3391cce7a1eeb83ad0fdaacbd47248161dd32bc59d32ec
4
- data.tar.gz: ba228ea8e5ba35307ddf029dc1dd4d87b712c9c1532b817ea36ff5d94132170a
3
+ metadata.gz: 7d016bf7582f1afdd750fd53197c9d1fd945373b9065962513eef5c4c9f4da49
4
+ data.tar.gz: 5eb4e6e7a1531c1e1456a83d6decdef744e87644c8f18ead889df3e57ec568b3
5
5
  SHA512:
6
- metadata.gz: 8d1f19d745517bdb83ff594d0014719dcc6e054a7af7ae4c6f064171e69e08374905b40c6f7172c5af2ddc34d02381aa316fb0c97b7ba1c5d6302ce28336e350
7
- data.tar.gz: f05373b64e491f6560026b258e948f516937970415fb6c17aace394d5104e0f74ed3b3159d92042bedb656f310135853b1b502a57b71d1a75bb1cf12117ea965
6
+ metadata.gz: b34396d298134a68e35d7a923dff49df58a1dc7ffec7bcb779c30a39aa7439f078d8dc4d82686c6fe0bc8d654dcd17fa242e79e559fe04f5865440f301add273
7
+ data.tar.gz: 71e259af66bc7cb93298713bb174b032d11ec6743296b6ba5e131ec89163445971da615144668958bc36379cc3052aff3d7ac8a2396f30ad42ccac8374c4d09e
data/README.md CHANGED
@@ -45,6 +45,7 @@ ManageIQ::Loggers::Base
45
45
  ManageIQ::Loggers::Container
46
46
  ManageIQ::Loggers::CloudWatch
47
47
  ManageIQ::Loggers::Journald
48
+ Insights::Loggers::Container
48
49
  Insights::Loggers::StdErrorLogger
49
50
  TopologicalInventory::Providers::Common::Logger
50
51
  ```
@@ -80,7 +81,7 @@ Standard error logger produces formatted output:
80
81
  "pid":11561, # process id
81
82
  "tid":"3fd1d4c2ffd4", # thread id
82
83
  "service": "progname",
83
- "level":"warning", #info, warning, error, debug
84
+ "level":"warning", # info(default), warning, error, debug
84
85
  "message":"test",
85
86
  "request_id": "REQ_ID", # Thread.current[:request_id]
86
87
  "tags":["MyApp"],
@@ -23,10 +23,12 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ["lib"]
24
24
 
25
25
  spec.add_runtime_dependency "activesupport", "~> 5.2", ">= 5.2.4.3"
26
- spec.add_runtime_dependency "topological_inventory-providers-common", "~> 3.0.1"
26
+
27
27
  spec.add_runtime_dependency "manageiq-loggers", "~> 0.4", ">= 0.4.2"
28
28
 
29
29
  spec.add_runtime_dependency "cloudwatchlogger", "~> 0.2.1"
30
+
31
+ spec.add_development_dependency "topological_inventory-providers-common", "~> 3.0.1"
30
32
  spec.add_development_dependency "manageiq-style", "~> 1.3.0"
31
33
  spec.add_development_dependency "rake", "~> 12.3", ">= 12.3.3"
32
34
  spec.add_development_dependency "rspec", "~> 3.0"
@@ -0,0 +1,33 @@
1
+ # inspired by https://github.com/ManageIQ/manageiq-loggers/blob/master/lib/manageiq/loggers/cloud_watch.rb
2
+ require 'active_support/core_ext/string'
3
+ require 'active_support/logger'
4
+
5
+ module Insights
6
+ module Loggers
7
+ class CloudWatch < ManageIQ::Loggers::Base
8
+ NAMESPACE_FILE = "/var/run/secrets/kubernetes.io/serviceaccount/namespace".freeze
9
+
10
+ def self.new(*args)
11
+ access_key_id = ENV["CW_AWS_ACCESS_KEY_ID"].presence
12
+ secret_access_key = ENV["CW_AWS_SECRET_ACCESS_KEY"].presence
13
+ log_group_name = ENV["CLOUD_WATCH_LOG_GROUP"].presence
14
+ log_stream_name = ENV["HOSTNAME"].presence
15
+ container_logger = Insights::Loggers::Container.new
16
+
17
+ return container_logger unless access_key_id && secret_access_key && log_group_name && log_stream_name
18
+
19
+ require 'cloudwatchlogger'
20
+
21
+ creds = {:access_key_id => access_key_id, :secret_access_key => secret_access_key}
22
+ cloud_watch_logdev = CloudWatchLogger::Client.new(creds, log_group_name, log_stream_name)
23
+ super(cloud_watch_logdev).tap { |logger| logger.extend(ActiveSupport::Logger.broadcast(container_logger)) }
24
+ end
25
+
26
+ def initialize(logdev, *args)
27
+ super
28
+ self.formatter = ManageIQ::Loggers::Container::Formatter.new
29
+ self.level = ENV['LOG_LEVEL'] if ENV['LOG_LEVEL']
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ require 'active_support/core_ext/string'
2
+ require 'active_support/logger'
3
+
4
+ module Insights
5
+ module Loggers
6
+ class Container < ManageIQ::Loggers::Container
7
+ def initialize(logdev = STDOUT, *args)
8
+ super
9
+ self.level = ENV['CONTAINER_LOG_LEVEL'] || ENV['LOG_LEVEL'] || DEBUG
10
+ end
11
+
12
+ def level=(new_level)
13
+ # overwrite method ManageIQ::Loggers::Container#level=
14
+ method(__method__).super_method.super_method.call(new_level)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -2,7 +2,7 @@ module Insights
2
2
  module Loggers
3
3
  class Factory
4
4
  def self.create_logger(logger_class, args = nil)
5
- logger_library_loader(logger_class)
5
+ logger_library_loader(logger_class, args)
6
6
  klass = logger_class.safe_constantize
7
7
 
8
8
  if klass
@@ -23,10 +23,18 @@ module Insights
23
23
  logger.app_name_for_formatter(args[:app_name])
24
24
  end
25
25
 
26
+ if args && args[:extend_module]
27
+ logger.extend(args[:extend_module].safe_constantize)
28
+ end
29
+
26
30
  logger
27
31
  end
28
32
 
29
- private_class_method def self.logger_library_loader(logger_class)
33
+ EXTENDED_LIBRARY_FROM_MODULE = {
34
+ "TopologicalInventory::Providers::Common::LoggingFunctions" => "topological_inventory/providers/common/logging"
35
+ }.freeze
36
+
37
+ private_class_method def self.logger_library_loader(logger_class, args = nil)
30
38
  case logger_class
31
39
  when "ManageIQ::Loggers::Base"
32
40
  require "manageiq/loggers/base"
@@ -47,9 +55,25 @@ module Insights
47
55
  when "Insights::Loggers::StdErrorLogger"
48
56
  require "manageiq/loggers/base"
49
57
  require "manageiq/loggers/container"
58
+ require "insights/loggers/container"
50
59
  require "insights/loggers/std_error_logger"
60
+ if args && args[:extend_module]
61
+ library_path = EXTENDED_LIBRARY_FROM_MODULE[args[:extend_module]]
62
+ raise ArgumentError, "Unable to find library for #{args[:extend_module]}" unless library_path
63
+
64
+ require EXTENDED_LIBRARY_FROM_MODULE[args[:extend_module]]
65
+ end
66
+ when "Insights::Loggers::CloudWatch"
67
+ require "manageiq/loggers/base"
68
+ require "manageiq/loggers/container"
69
+ require "insights/loggers/container"
70
+ require "insights/loggers/cloud_watch"
51
71
  when "TopologicalInventory::Providers::Common::Logger"
52
72
  require "topological_inventory/providers/common/logging"
73
+ when "Insights::Loggers::Container"
74
+ require "manageiq/loggers/base"
75
+ require "manageiq/loggers/container"
76
+ require "insights/loggers/container"
53
77
  else
54
78
  raise ArgumentError, "Can't load libraries for #{logger_class}."
55
79
  end
@@ -1,10 +1,11 @@
1
1
  module Insights
2
2
  module Loggers
3
- class StdErrorLogger < ManageIQ::Loggers::Container
3
+ class StdErrorLogger < Container
4
4
  def initialize(*args)
5
5
  super
6
6
  self.reopen(STDERR)
7
7
  self.formatter = Formatter.new
8
+ self.level = INFO
8
9
  end
9
10
 
10
11
  def app_name_for_formatter(app_name)
@@ -1,5 +1,5 @@
1
1
  module Insights
2
2
  module Loggers
3
- VERSION = "0.1.7".freeze
3
+ VERSION = "0.1.11".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insights-loggers-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Insights Authors
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-07 00:00:00.000000000 Z
11
+ date: 2021-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,20 +30,6 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 5.2.4.3
33
- - !ruby/object:Gem::Dependency
34
- name: topological_inventory-providers-common
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: 3.0.1
40
- type: :runtime
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: 3.0.1
47
33
  - !ruby/object:Gem::Dependency
48
34
  name: manageiq-loggers
49
35
  requirement: !ruby/object:Gem::Requirement
@@ -78,6 +64,20 @@ dependencies:
78
64
  - - "~>"
79
65
  - !ruby/object:Gem::Version
80
66
  version: 0.2.1
67
+ - !ruby/object:Gem::Dependency
68
+ name: topological_inventory-providers-common
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: 3.0.1
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: 3.0.1
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: manageiq-style
83
83
  requirement: !ruby/object:Gem::Requirement
@@ -154,8 +154,8 @@ dependencies:
154
154
  - - "~>"
155
155
  - !ruby/object:Gem::Version
156
156
  version: 0.9.4
157
- description:
158
- email:
157
+ description:
158
+ email:
159
159
  executables: []
160
160
  extensions: []
161
161
  extra_rdoc_files: []
@@ -178,6 +178,8 @@ files:
178
178
  - insights-loggers-ruby.gemspec
179
179
  - lib/insights-loggers.rb
180
180
  - lib/insights/loggers.rb
181
+ - lib/insights/loggers/cloud_watch.rb
182
+ - lib/insights/loggers/container.rb
181
183
  - lib/insights/loggers/factory.rb
182
184
  - lib/insights/loggers/std_error_logger.rb
183
185
  - lib/insights/loggers/version.rb
@@ -185,7 +187,7 @@ homepage: https://github.com/ManageIQ/manageiq-loggers
185
187
  licenses:
186
188
  - Apache-2.0
187
189
  metadata: {}
188
- post_install_message:
190
+ post_install_message:
189
191
  rdoc_options: []
190
192
  require_paths:
191
193
  - lib
@@ -200,8 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
202
  - !ruby/object:Gem::Version
201
203
  version: '0'
202
204
  requirements: []
203
- rubygems_version: 3.2.15
204
- signing_key:
205
+ rubygems_version: 3.0.3.1
206
+ signing_key:
205
207
  specification_version: 4
206
208
  summary: Loggers for Insights ruby projects
207
209
  test_files: []