manageiq-loggers 0.3.0 → 0.6.0

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
- SHA1:
3
- metadata.gz: 57e42ce8c9d94d968cd0f341fe4809ed825d7686
4
- data.tar.gz: accdb3174fb08b2c7f8c1f544a29df6af779901f
2
+ SHA256:
3
+ metadata.gz: 0b939ba32542c3e8a6c44e535465dacb5a276a86d17891dee3b31fd17afd29f6
4
+ data.tar.gz: b386c5453ce9d2895b5f90f37c618d387f081fd04ce2f60f8d012229aa51703e
5
5
  SHA512:
6
- metadata.gz: 1ce90c2eafe1bd650f5c987256614e3aafda8eb87e826b58fd1b1c1481168cb8f213699747f9742e3d161d2d7de3873670fe49a6ffe84f63c6a08fcabd237b2e
7
- data.tar.gz: 292d0d0cb8e632f2e833bd7809fdc158af53aa6f91e4cd6e48f45e8d72ce7421f9dfcdc154dab48d8188e5a5d23e90b075bd12dd3960f266dc2134d5df07b47b
6
+ metadata.gz: d48fdc4dc59288ea52a96bf9f0d7856e9c87365730f2cd2c752f7ae975176210eb8f96e581e462244a87a21dc5369f5178d6af0ce3ceeca8e86ccad4e63398d0
7
+ data.tar.gz: de3a7f0df5627f78ba5d9057299ff2f7c17d6be5642e90d704fbf077be1d02fde32394f90e264dd5356b5a3d1e8f99454e8981d70c995fdd39628bc2a84739b7
@@ -28,3 +28,4 @@ plugins:
28
28
  rubocop:
29
29
  enabled: true
30
30
  config: ".rubocop_cc.yml"
31
+ channel: 'rubocop-0-69'
@@ -1,6 +1,5 @@
1
1
  ---
2
2
  language: ruby
3
- sudo: false
4
3
  cache: bundler
5
4
  rvm:
6
5
  - 2.4.5
@@ -1,25 +1,60 @@
1
- # Change Log
1
+ # Changelog
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
- ## [0.3.0] - 2019-05-30
6
+ ## [Unreleased]
7
+
8
+ ## [0.6.0] - 2020-12-09
9
+ ### Changed
10
+ - Update rake dependency to address CVE-2020-8130 [(#19)](https://github.com/ManageIQ/manageiq-loggers/pull/19)
11
+
12
+ ### Fixed
13
+ - Fix escaping of < and > in Container logger (31 minutes ago) <Jason Frey> [(#29)](https://github.com/ManageIQ/manageiq-loggers/pull/29)
14
+ - Fix ActiveSupport::Deprecation call (35 minutes ago) <Jason Frey> [(#29)](https://github.com/ManageIQ/manageiq-loggers/pull/29)
15
+ - Fix the handling of journald code_file/code_line [(#21)](https://github.com/ManageIQ/manageiq-loggers/pull/21) [(#22)](https://github.com/ManageIQ/manageiq-loggers/pull/22)
16
+
17
+ ### Added
18
+ - Add code_func to the journald logger [(#23)](https://github.com/ManageIQ/manageiq-loggers/pull/23)
19
+
20
+ ## [0.5.0] - 2020-03-18
21
+ ### Changed
22
+ - Deprecate Thread.current[:current_request]&.request_id in favor of Thread.current[:request_id] [(#17)](https://github.com/ManageIQ/manageiq-loggers/pull/17)
23
+
24
+ ## [0.4.2] - 2020-01-14
25
+ ### Fixed
26
+ - Revert "Change CloudWatch log_group to be the namespace if it exists" [(#16)](https://github.com/ManageIQ/manageiq-loggers/pull/16)
7
27
 
8
- ## Added
28
+ ## [0.4.1] - 2020-01-06
29
+ ### Fixed
30
+ - Change CloudWatch logger log_group and log_stream values for easier debugging and unique identifiers [(#15)](https://github.com/ManageIQ/manageiq-loggers/pull/15)
31
+ - Enhancements to the journald logger to allow for easier debugging [(#11)](https://github.com/ManageIQ/manageiq-loggers/pull/11)
32
+
33
+ ## [0.4.0] - 2019-08-15
34
+ ### Changed
35
+ - The Cloud Watch logger will now also broadcast its log messages to the container logger [(#10)](https://github.com/ManageIQ/manageiq-loggers/pull/10)
36
+
37
+ ## [0.3.0] - 2019-05-30
38
+ ### Added
9
39
  - Add a Journald Logger [(#5)](https://github.com/ManageIQ/manageiq-loggers/pull/5)
10
40
  - Add a cloud watch logger [(#9)](https://github.com/ManageIQ/manageiq-loggers/pull/9)
11
41
 
12
42
  ## [0.2.0] - 2019-05-03
13
-
14
- ## Added
43
+ ### Added
15
44
  - Log the request id in the container logger if present [(#7)](https://github.com/ManageIQ/manageiq-loggers/pull/7)
16
45
 
17
46
  ## [0.1.1] - 2019-02-27
18
-
19
- ## Fixed
47
+ ### Fixed
20
48
  - Always sync container STDOUT logs [(#4)](https://github.com/ManageIQ/manageiq-loggers/pull/4)
21
49
 
22
50
  ## [0.1.0] - 2019-01-08
23
51
 
24
- [Unreleased]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.1.1...master
52
+ [Unreleased]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.6.0...master
53
+ [0.6.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.5.0...v0.6.0
54
+ [0.5.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.4.2...v0.5.0
55
+ [0.4.2]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.4.1...v0.4.2
56
+ [0.4.1]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.4.0...v0.4.1
57
+ [0.4.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.3.0...v0.4.0
58
+ [0.3.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.2.0...v0.3.0
59
+ [0.2.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.1.1...v0.2.0
25
60
  [0.1.1]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.1.0...v0.1.1
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/string'
2
+ require 'active_support/logger'
2
3
 
3
4
  module ManageIQ
4
5
  module Loggers
@@ -9,17 +10,16 @@ module ManageIQ
9
10
  access_key_id = ENV["CW_AWS_ACCESS_KEY_ID"].presence
10
11
  secret_access_key = ENV["CW_AWS_SECRET_ACCESS_KEY"].presence
11
12
  log_group_name = ENV["CLOUD_WATCH_LOG_GROUP"].presence
12
- log_stream_name = File.exist?(NAMESPACE_FILE) ? File.read(NAMESPACE_FILE) : nil
13
+ log_stream_name = ENV["HOSTNAME"].presence
13
14
 
14
- unless access_key_id && secret_access_key && log_group_name && log_stream_name
15
- return ManageIQ::Loggers::Container.new
16
- end
15
+ container_logger = ManageIQ::Loggers::Container.new
16
+ return container_logger unless access_key_id && secret_access_key && log_group_name && log_stream_name
17
17
 
18
18
  require 'cloudwatchlogger'
19
19
 
20
20
  creds = {:access_key_id => access_key_id, :secret_access_key => secret_access_key}
21
21
  cloud_watch_logdev = CloudWatchLogger::Client.new(creds, log_group_name, log_stream_name)
22
- super(cloud_watch_logdev)
22
+ super(cloud_watch_logdev).tap { |logger| logger.extend(ActiveSupport::Logger.broadcast(container_logger)) }
23
23
  end
24
24
 
25
25
  def initialize(logdev, *args)
@@ -36,7 +36,7 @@ module ManageIQ
36
36
  def call(severity, time, progname, msg)
37
37
  # From https://github.com/ViaQ/elasticsearch-templates/releases -> Downloads -> *.asciidoc
38
38
  # NOTE: These values are in a specific order for easier human readbility via STDOUT
39
- {
39
+ payload = {
40
40
  :@timestamp => format_datetime(time),
41
41
  :hostname => hostname,
42
42
  :pid => $PROCESS_ID,
@@ -46,7 +46,8 @@ module ManageIQ
46
46
  :message => prefix_task_id(msg2str(msg)),
47
47
  :request_id => request_id
48
48
  # :tags => "tags string",
49
- }.compact.to_json << "\n"
49
+ }.compact
50
+ JSON.generate(payload) << "\n"
50
51
  end
51
52
 
52
53
  private
@@ -64,7 +65,12 @@ module ManageIQ
64
65
  end
65
66
 
66
67
  def request_id
67
- Thread.current[:current_request]&.request_id
68
+ Thread.current[:request_id] || Thread.current[:current_request]&.request_id.tap do |request_id|
69
+ if request_id
70
+ require "active_support/deprecation"
71
+ ActiveSupport::Deprecation.warn("Usage of `Thread.current[:current_request]&.request_id` will be deprecated in version 0.5.0. Please switch to `Thread.current[:request_id]` to log request_id automatically.")
72
+ end
73
+ end
68
74
  end
69
75
  end
70
76
  end
@@ -1,17 +1,33 @@
1
1
  module ManageIQ
2
2
  module Loggers
3
3
  class Journald < Base
4
+ # An syslog identifier used when writing messages. The default is the progname.
5
+ attr_accessor :syslog_identifier
6
+
7
+ # Create and return a new ManageIQ::Loggers::Journald instance. The
8
+ # arguments to the initializer can be ignored unless you're multicasting.
9
+ #
10
+ # Internally we set our own formatter, and automatically set the
11
+ # progname option to 'manageiq' if not specified.
12
+ #
4
13
  def initialize(logdev = nil, *args)
5
14
  require "systemd-journal"
6
-
7
15
  super(logdev, *args)
8
- self.formatter = Formatter.new
16
+ @formatter = Formatter.new
17
+ @progname ||= 'manageiq'
18
+ @syslog_identifier ||= @progname
9
19
  end
10
20
 
21
+ # Comply with the VMDB::Logger interface. For a filename we simply use
22
+ # the string 'journald' since we're not using a backing file directly.
23
+ #
11
24
  def filename
12
25
  "journald"
13
26
  end
14
27
 
28
+ # Redefine this method from the core Logger class. Internally this is
29
+ # the method used when .info, .warn, etc are called.
30
+ #
15
31
  def add(severity, message = nil, progname = nil)
16
32
  severity ||= Logger::UNKNOWN
17
33
  return true if severity < @level
@@ -28,12 +44,23 @@ module ManageIQ
28
44
  end
29
45
 
30
46
  message = formatter.call(format_severity(severity), progname, message)
47
+ caller_object = caller_locations(3, 1).first
31
48
 
32
- Systemd::Journal.print(log_level_map[severity], message)
49
+ Systemd::Journal.message(
50
+ :message => message,
51
+ :priority => log_level_map[severity],
52
+ :syslog_identifier => syslog_identifier,
53
+ :code_line => caller_object.lineno,
54
+ :code_file => caller_object.absolute_path,
55
+ :code_func => caller_object.label
56
+ )
33
57
  end
34
58
 
35
59
  private
36
60
 
61
+ # Map the Systemd::Journal error levels to the Logger error levels. For
62
+ # unknown, we go with alert level.
63
+ #
37
64
  def log_level_map
38
65
  @log_level_map ||= {
39
66
  Logger::UNKNOWN => Systemd::Journal::LOG_ALERT,
@@ -1,5 +1,5 @@
1
- module Manageiq
1
+ module ManageIQ
2
2
  module Loggers
3
- VERSION = "0.3.0"
3
+ VERSION = "0.6.0".freeze
4
4
  end
5
5
  end
@@ -2,10 +2,11 @@
2
2
  lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require "manageiq/loggers/version"
5
+ require "rbconfig"
5
6
 
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = "manageiq-loggers"
8
- spec.version = Manageiq::Loggers::VERSION
9
+ spec.version = ManageIQ::Loggers::VERSION
9
10
  spec.authors = ["ManageIQ Authors"]
10
11
 
11
12
  spec.summary = %q{Loggers for ManageIQ projects}
@@ -25,7 +26,9 @@ Gem::Specification.new do |spec|
25
26
  spec.add_runtime_dependency "manageiq-password", "~> 0.1"
26
27
 
27
28
  spec.add_development_dependency "bundler"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "cloudwatchlogger"
30
+ spec.add_development_dependency "rake", ">= 12.3.3"
29
31
  spec.add_development_dependency "rspec", "~> 3.0"
30
32
  spec.add_development_dependency "simplecov"
33
+ spec.add_development_dependency "systemd-journal" if RbConfig::CONFIG['host_os'] =~ /linux/i
31
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manageiq-loggers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Authors
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-30 00:00:00.000000000 Z
11
+ date: 2020-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,20 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cloudwatchlogger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - "~>"
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: '10.0'
75
+ version: 12.3.3
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - "~>"
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: '10.0'
82
+ version: 12.3.3
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rspec
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,20 @@ dependencies:
94
108
  - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: systemd-journal
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  description:
98
126
  email:
99
127
  executables: []
@@ -141,8 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
169
  - !ruby/object:Gem::Version
142
170
  version: '0'
143
171
  requirements: []
144
- rubyforge_project:
145
- rubygems_version: 2.6.14
172
+ rubygems_version: 3.0.6
146
173
  signing_key:
147
174
  specification_version: 4
148
175
  summary: Loggers for ManageIQ projects