manageiq-loggers 1.0.1 → 1.1.0
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 +10 -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/json_logger.rb +77 -0
- data/lib/manageiq/loggers/version.rb +1 -1
- data/lib/manageiq/loggers.rb +3 -0
- data/manageiq-loggers.gemspec +1 -2
- metadata +8 -6
- 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: b3074101daa2ad9391018a2bd3d9eb9c14588ec5872ffdf8fb6a3a88b119baaa
|
4
|
+
data.tar.gz: 045bc78b9f4c4b97d2c3d7e2e45351025607100dff861397b42dba135a495334
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b3675dd8cb799c3b830bb2683303b153e0d01b1a4ebd6b32e6d8b056d8df5bc76e9fd643fac317fcf0090f22ea7ea19935acd5ec90246e7e03b8e69597d063b
|
7
|
+
data.tar.gz: defb9aa94eb27dfd54bb3dab055a7801daf3e282ca2a62f5706008788d3d54c6fc290ac382c2bcd54ac80667b05d6e44d2e1f5b4401523ff5e6e5b9af06e956b
|
@@ -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@v2
|
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@v3.0.0
|
data/.rspec
CHANGED
data/.whitesource
ADDED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## [1.1.0] - 2022-11-14
|
9
|
+
### Changed
|
10
|
+
- Split out JSON logger from Container logger [(#49)](https://github.com/ManageIQ/manageiq-loggers/pull/49)
|
11
|
+
- Allow passing the CloudWatch logger's configuration as kwargs [(#50)](https://github.com/ManageIQ/manageiq-loggers/pull/50)
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
- Remove timestamp whitespace in container logger formatter [(#47)](https://github.com/ManageIQ/manageiq-loggers/pull/47)
|
15
|
+
|
8
16
|
## [1.0.1] - 2021-01-05
|
9
17
|
### Fixed
|
10
18
|
- Fix require issue when used with Rails 7 [(#42)](https://github.com/ManageIQ/manageiq-loggers/pull/42)
|
@@ -75,7 +83,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
75
83
|
|
76
84
|
## [0.1.0] - 2019-01-08
|
77
85
|
|
78
|
-
[Unreleased]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.0
|
86
|
+
[Unreleased]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.1.0...master
|
87
|
+
[1.1.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.0.1...v1.1.0
|
79
88
|
[1.0.1]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.0.0...v1.0.1
|
80
89
|
[1.0.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.8.0...v1.0.0
|
81
90
|
[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
|
@@ -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"
|
@@ -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.0
|
4
|
+
version: 1.1.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: 2022-
|
11
|
+
date: 2022-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 0.21.2
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 0.21.2
|
125
125
|
description:
|
126
126
|
email:
|
127
127
|
executables: []
|
@@ -129,12 +129,13 @@ extensions: []
|
|
129
129
|
extra_rdoc_files: []
|
130
130
|
files:
|
131
131
|
- ".codeclimate.yml"
|
132
|
+
- ".github/workflows/ci.yaml"
|
132
133
|
- ".gitignore"
|
133
134
|
- ".rspec"
|
134
135
|
- ".rubocop.yml"
|
135
136
|
- ".rubocop_cc.yml"
|
136
137
|
- ".rubocop_local.yml"
|
137
|
-
- ".
|
138
|
+
- ".whitesource"
|
138
139
|
- CHANGELOG.md
|
139
140
|
- Gemfile
|
140
141
|
- LICENSE.txt
|
@@ -148,6 +149,7 @@ files:
|
|
148
149
|
- lib/manageiq/loggers/cloud_watch.rb
|
149
150
|
- lib/manageiq/loggers/container.rb
|
150
151
|
- lib/manageiq/loggers/journald.rb
|
152
|
+
- lib/manageiq/loggers/json_logger.rb
|
151
153
|
- lib/manageiq/loggers/version.rb
|
152
154
|
- manageiq-loggers.gemspec
|
153
155
|
homepage: https://github.com/ManageIQ/manageiq-loggers
|
@@ -169,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
171
|
- !ruby/object:Gem::Version
|
170
172
|
version: '0'
|
171
173
|
requirements: []
|
172
|
-
rubygems_version: 3.
|
174
|
+
rubygems_version: 3.3.18
|
173
175
|
signing_key:
|
174
176
|
specification_version: 4
|
175
177
|
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"
|