manageiq-loggers 1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yaml +33 -0
- data/.rspec +1 -2
- data/.whitesource +3 -0
- data/CHANGELOG.md +20 -1
- data/Gemfile +0 -2
- data/README.md +1 -2
- data/lib/manageiq/loggers/cloud_watch.rb +7 -7
- data/lib/manageiq/loggers/container.rb +2 -67
- data/lib/manageiq/loggers/journald.rb +2 -2
- data/lib/manageiq/loggers/json_logger.rb +77 -0
- data/lib/manageiq/loggers/version.rb +1 -1
- data/lib/manageiq/loggers.rb +3 -0
- data/manageiq-loggers.gemspec +2 -3
- metadata +26 -4
- data/.travis.yml +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a32bea06f89fab47efe8276e4a6bb8847a4bb319d5f720a0fefa8b8e4af84df
|
4
|
+
data.tar.gz: 9bb69c8569b7cd7c1f412ef61ee2b5b1c720ed8749b11bff4cb7d374c8db75ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bcc952f60b915db50ca50fb798d78ee80554849a6f36026550d235a4365f2ebba1908ec82a5035a529bdda56299a98196811e7bb29e815919a814f758bc39ad
|
7
|
+
data.tar.gz: aa68849ecdc51297a67e256e35b6cc894e0ed5d1a9a369997e28a2f5791ac8f4411aac8cf72a2fee3cd596ddcb38a1eda6a959b34e2b5c78a5cfb4a130221632
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
schedule:
|
7
|
+
- cron: '0 0 * * 0'
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
ci:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version:
|
15
|
+
- '2.6'
|
16
|
+
- '2.7'
|
17
|
+
- '3.0'
|
18
|
+
env:
|
19
|
+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v4
|
22
|
+
- name: Set up Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby-version }}
|
26
|
+
bundler-cache: true
|
27
|
+
timeout-minutes: 30
|
28
|
+
- name: Run tests
|
29
|
+
run: bundle exec rake
|
30
|
+
- name: Report code coverage
|
31
|
+
if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '3.0' }}
|
32
|
+
continue-on-error: true
|
33
|
+
uses: paambaati/codeclimate-action@v5
|
data/.rspec
CHANGED
data/.whitesource
ADDED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,23 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## [1.1.1] - 2023-12-13
|
9
|
+
### Fixed
|
10
|
+
- Fix Journald::Formatter's arguments list [(#61)](https://github.com/ManageIQ/manageiq-loggers/pull/61)
|
11
|
+
- Fix missing ActiveSupport::Logger.broadcast [(#62)](https://github.com/ManageIQ/manageiq-loggers/pull/62)
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
- Update actions/checkout version to v4 [(#60)](https://github.com/ManageIQ/manageiq-loggers/pull/60)
|
15
|
+
- Update GitHub Actions versions [(#59)](https://github.com/ManageIQ/manageiq-loggers/pull/59)
|
16
|
+
|
17
|
+
## [1.1.0] - 2022-11-14
|
18
|
+
### Changed
|
19
|
+
- Split out JSON logger from Container logger [(#49)](https://github.com/ManageIQ/manageiq-loggers/pull/49)
|
20
|
+
- Allow passing the CloudWatch logger's configuration as kwargs [(#50)](https://github.com/ManageIQ/manageiq-loggers/pull/50)
|
21
|
+
|
22
|
+
### Fixed
|
23
|
+
- Remove timestamp whitespace in container logger formatter [(#47)](https://github.com/ManageIQ/manageiq-loggers/pull/47)
|
24
|
+
|
8
25
|
## [1.0.1] - 2021-01-05
|
9
26
|
### Fixed
|
10
27
|
- Fix require issue when used with Rails 7 [(#42)](https://github.com/ManageIQ/manageiq-loggers/pull/42)
|
@@ -75,7 +92,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
75
92
|
|
76
93
|
## [0.1.0] - 2019-01-08
|
77
94
|
|
78
|
-
[Unreleased]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.
|
95
|
+
[Unreleased]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.1.1...master
|
96
|
+
[1.1.1]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.1.0...v1.1.1
|
97
|
+
[1.1.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.0.1...v1.1.0
|
79
98
|
[1.0.1]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.0.0...v1.0.1
|
80
99
|
[1.0.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.8.0...v1.0.0
|
81
100
|
[0.8.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.7.0...v0.8.0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# ManageIQ::Loggers
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![CI](https://github.com/ManageIQ/manageiq-loggers/actions/workflows/ci.yaml/badge.svg)](https://github.com/ManageIQ/manageiq-loggers/actions/workflows/ci.yaml)
|
4
4
|
[![Maintainability](https://api.codeclimate.com/v1/badges/8d3c9bf77c45a024166b/maintainability)](https://codeclimate.com/github/ManageIQ/manageiq-loggers/maintainability)
|
5
5
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/8d3c9bf77c45a024166b/test_coverage)](https://codeclimate.com/github/ManageIQ/manageiq-loggers/test_coverage)
|
6
|
-
[![Security](https://hakiri.io/github/ManageIQ/manageiq-loggers/master.svg)](https://hakiri.io/github/ManageIQ/manageiq-loggers/master)
|
7
6
|
|
8
7
|
Loggers for ManageIQ projects
|
9
8
|
|
@@ -7,19 +7,19 @@ module ManageIQ
|
|
7
7
|
class CloudWatch < Base
|
8
8
|
NAMESPACE_FILE = "/var/run/secrets/kubernetes.io/serviceaccount/namespace".freeze
|
9
9
|
|
10
|
-
def self.new(*args)
|
11
|
-
access_key_id
|
12
|
-
secret_access_key
|
13
|
-
|
14
|
-
|
10
|
+
def self.new(*args, access_key_id: nil, secret_access_key: nil, log_group: nil, log_stream: nil)
|
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 ||= ENV["CLOUD_WATCH_LOG_GROUP"].presence
|
14
|
+
log_stream ||= ENV["HOSTNAME"].presence
|
15
15
|
|
16
16
|
container_logger = ManageIQ::Loggers::Container.new
|
17
|
-
return container_logger unless access_key_id && secret_access_key &&
|
17
|
+
return container_logger unless access_key_id && secret_access_key && log_group && log_stream
|
18
18
|
|
19
19
|
require 'cloudwatchlogger'
|
20
20
|
|
21
21
|
creds = {:access_key_id => access_key_id, :secret_access_key => secret_access_key}
|
22
|
-
cloud_watch_logdev = CloudWatchLogger::Client.new(creds,
|
22
|
+
cloud_watch_logdev = CloudWatchLogger::Client.new(creds, log_group, log_stream)
|
23
23
|
super(cloud_watch_logdev).tap { |logger| logger.extend(ActiveSupport::Logger.broadcast(container_logger)) }
|
24
24
|
end
|
25
25
|
|
@@ -1,79 +1,14 @@
|
|
1
1
|
module ManageIQ
|
2
2
|
module Loggers
|
3
|
-
class Container <
|
4
|
-
def initialize(logdev =
|
3
|
+
class Container < JSONLogger
|
4
|
+
def initialize(logdev = $stdout, *_, **_)
|
5
5
|
logdev.sync = true # Don't buffer container log output
|
6
|
-
|
7
6
|
super
|
8
|
-
|
9
|
-
self.formatter = Formatter.new
|
10
7
|
end
|
11
8
|
|
12
9
|
def filename
|
13
10
|
"STDOUT"
|
14
11
|
end
|
15
|
-
|
16
|
-
class Formatter < Base::Formatter
|
17
|
-
SEVERITY_MAP = {
|
18
|
-
"DEBUG" => "debug",
|
19
|
-
"INFO" => "info",
|
20
|
-
"WARN" => "warning",
|
21
|
-
"ERROR" => "err",
|
22
|
-
"FATAL" => "crit",
|
23
|
-
"UNKNOWN" => "unknown"
|
24
|
-
# Others that don't match up: alert emerg notice trace
|
25
|
-
}.freeze
|
26
|
-
|
27
|
-
def initialize
|
28
|
-
super
|
29
|
-
require 'json'
|
30
|
-
end
|
31
|
-
|
32
|
-
def call(severity, time, progname, msg)
|
33
|
-
# From https://github.com/ViaQ/elasticsearch-templates/releases -> Downloads -> *.asciidoc
|
34
|
-
# NOTE: These values are in a specific order for easier human readbility via STDOUT
|
35
|
-
payload = {
|
36
|
-
:@timestamp => format_datetime(time),
|
37
|
-
:hostname => hostname,
|
38
|
-
:pid => $PROCESS_ID,
|
39
|
-
:tid => thread_id,
|
40
|
-
:service => progname,
|
41
|
-
:level => translate_error(severity),
|
42
|
-
:message => prefix_task_id(msg2str(msg)),
|
43
|
-
:request_id => request_id
|
44
|
-
# :tags => "tags string",
|
45
|
-
}.compact
|
46
|
-
JSON.generate(payload) << "\n"
|
47
|
-
rescue Encoding::UndefinedConversionError
|
48
|
-
raise unless msg.encoding == Encoding::ASCII_8BIT
|
49
|
-
|
50
|
-
msg.force_encoding("UTF-8")
|
51
|
-
retry
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def hostname
|
57
|
-
@hostname ||= ENV["HOSTNAME"]
|
58
|
-
end
|
59
|
-
|
60
|
-
def thread_id
|
61
|
-
Thread.current.object_id.to_s(16)
|
62
|
-
end
|
63
|
-
|
64
|
-
def translate_error(level)
|
65
|
-
SEVERITY_MAP[level] || "unknown"
|
66
|
-
end
|
67
|
-
|
68
|
-
def request_id
|
69
|
-
Thread.current[:request_id] || Thread.current[:current_request]&.request_id.tap do |request_id|
|
70
|
-
if request_id
|
71
|
-
require "active_support/deprecation"
|
72
|
-
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.")
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
12
|
end
|
78
13
|
end
|
79
14
|
end
|
@@ -39,7 +39,7 @@ module ManageIQ
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
message = formatter.call(format_severity(severity), progname, message)
|
42
|
+
message = formatter.call(format_severity(severity), nil, progname, message)
|
43
43
|
caller_object = caller_locations(3, 1).first
|
44
44
|
|
45
45
|
Systemd::Journal.message(
|
@@ -69,7 +69,7 @@ module ManageIQ
|
|
69
69
|
end
|
70
70
|
|
71
71
|
class Formatter < Base::Formatter
|
72
|
-
def call(severity, progname, msg)
|
72
|
+
def call(severity, _time, progname, msg)
|
73
73
|
msg = prefix_task_id(msg2str(msg)).truncate(Base::MAX_LOG_LINE_LENGTH)
|
74
74
|
"%5s -- %s: %s\n" % [severity, progname, msg]
|
75
75
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module ManageIQ
|
2
|
+
module Loggers
|
3
|
+
class JSONLogger < Base
|
4
|
+
def initialize(*_, **_)
|
5
|
+
super
|
6
|
+
self.formatter = Formatter.new
|
7
|
+
end
|
8
|
+
|
9
|
+
class Formatter < Base::Formatter
|
10
|
+
SEVERITY_MAP = {
|
11
|
+
"DEBUG" => "debug",
|
12
|
+
"INFO" => "info",
|
13
|
+
"WARN" => "warning",
|
14
|
+
"ERROR" => "err",
|
15
|
+
"FATAL" => "crit",
|
16
|
+
"UNKNOWN" => "unknown"
|
17
|
+
# Others that don't match up: alert emerg notice trace
|
18
|
+
}.freeze
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
super
|
22
|
+
require 'json'
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(severity, time, progname, msg)
|
26
|
+
# From https://github.com/ViaQ/elasticsearch-templates/releases -> Downloads -> *.asciidoc
|
27
|
+
# NOTE: These values are in a specific order for easier human readbility via STDOUT
|
28
|
+
payload = {
|
29
|
+
:@timestamp => format_datetime(time),
|
30
|
+
:hostname => hostname,
|
31
|
+
:pid => $PROCESS_ID,
|
32
|
+
:tid => thread_id,
|
33
|
+
:service => progname,
|
34
|
+
:level => translate_error(severity),
|
35
|
+
:message => prefix_task_id(msg2str(msg)),
|
36
|
+
:request_id => request_id
|
37
|
+
# :tags => "tags string",
|
38
|
+
}.compact
|
39
|
+
JSON.generate(payload) << "\n"
|
40
|
+
rescue Encoding::UndefinedConversionError
|
41
|
+
raise unless msg.encoding == Encoding::ASCII_8BIT
|
42
|
+
|
43
|
+
msg.force_encoding("UTF-8")
|
44
|
+
retry
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def format_datetime(*)
|
50
|
+
super.rstrip
|
51
|
+
end
|
52
|
+
|
53
|
+
def hostname
|
54
|
+
@hostname ||= ENV["HOSTNAME"]
|
55
|
+
end
|
56
|
+
|
57
|
+
def thread_id
|
58
|
+
Thread.current.object_id.to_s(16)
|
59
|
+
end
|
60
|
+
|
61
|
+
def translate_error(level)
|
62
|
+
SEVERITY_MAP[level] || "unknown"
|
63
|
+
end
|
64
|
+
|
65
|
+
def request_id
|
66
|
+
Thread.current[:request_id] || Thread.current[:current_request]&.request_id.tap do |request_id|
|
67
|
+
if request_id
|
68
|
+
require "active_support"
|
69
|
+
require "active_support/deprecation"
|
70
|
+
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.")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/manageiq/loggers.rb
CHANGED
data/manageiq-loggers.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require "manageiq/loggers/version"
|
@@ -22,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
22
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
22
|
spec.require_paths = ["lib"]
|
24
23
|
|
25
|
-
spec.add_runtime_dependency "activesupport", ">= 5.0"
|
24
|
+
spec.add_runtime_dependency "activesupport", ">= 5.0", "< 7.1"
|
26
25
|
spec.add_runtime_dependency "manageiq-password", "< 2"
|
27
26
|
|
28
27
|
spec.add_development_dependency "bundler"
|
@@ -30,6 +29,6 @@ Gem::Specification.new do |spec|
|
|
30
29
|
spec.add_development_dependency "manageiq-style"
|
31
30
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
32
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
-
spec.add_development_dependency "simplecov"
|
32
|
+
spec.add_development_dependency "simplecov", ">= 0.21.2"
|
34
33
|
spec.add_development_dependency "systemd-journal" if RbConfig::CONFIG['host_os'] =~ /linux/i
|
35
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: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ManageIQ Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.1'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '5.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7.1'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: manageiq-password
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,6 +116,20 @@ dependencies:
|
|
110
116
|
version: '3.0'
|
111
117
|
- !ruby/object:Gem::Dependency
|
112
118
|
name: simplecov
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 0.21.2
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.21.2
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: systemd-journal
|
113
133
|
requirement: !ruby/object:Gem::Requirement
|
114
134
|
requirements:
|
115
135
|
- - ">="
|
@@ -129,12 +149,13 @@ extensions: []
|
|
129
149
|
extra_rdoc_files: []
|
130
150
|
files:
|
131
151
|
- ".codeclimate.yml"
|
152
|
+
- ".github/workflows/ci.yaml"
|
132
153
|
- ".gitignore"
|
133
154
|
- ".rspec"
|
134
155
|
- ".rubocop.yml"
|
135
156
|
- ".rubocop_cc.yml"
|
136
157
|
- ".rubocop_local.yml"
|
137
|
-
- ".
|
158
|
+
- ".whitesource"
|
138
159
|
- CHANGELOG.md
|
139
160
|
- Gemfile
|
140
161
|
- LICENSE.txt
|
@@ -148,6 +169,7 @@ files:
|
|
148
169
|
- lib/manageiq/loggers/cloud_watch.rb
|
149
170
|
- lib/manageiq/loggers/container.rb
|
150
171
|
- lib/manageiq/loggers/journald.rb
|
172
|
+
- lib/manageiq/loggers/json_logger.rb
|
151
173
|
- lib/manageiq/loggers/version.rb
|
152
174
|
- manageiq-loggers.gemspec
|
153
175
|
homepage: https://github.com/ManageIQ/manageiq-loggers
|
@@ -169,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
191
|
- !ruby/object:Gem::Version
|
170
192
|
version: '0'
|
171
193
|
requirements: []
|
172
|
-
rubygems_version: 3.
|
194
|
+
rubygems_version: 3.4.20
|
173
195
|
signing_key:
|
174
196
|
specification_version: 4
|
175
197
|
summary: Loggers for ManageIQ projects
|
data/.travis.yml
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
dist: bionic
|
4
|
-
cache: bundler
|
5
|
-
rvm:
|
6
|
-
- 2.6.8
|
7
|
-
- 2.7.4
|
8
|
-
- 3.0.2
|
9
|
-
before_script:
|
10
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
11
|
-
- chmod +x ./cc-test-reporter
|
12
|
-
- "./cc-test-reporter before-build"
|
13
|
-
after_script:
|
14
|
-
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|