manageiq-loggers 1.2.1 → 2.0.0
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/.github/workflows/ci.yaml +14 -13
- data/CHANGELOG.md +11 -3
- data/Gemfile +3 -5
- data/README.md +0 -4
- data/lib/manageiq/loggers/file.rb +60 -0
- data/lib/manageiq/loggers/journald.rb +26 -2
- data/lib/manageiq/loggers/json_logger.rb +1 -7
- data/lib/manageiq/loggers/version.rb +1 -1
- data/lib/manageiq/loggers.rb +1 -1
- data/manageiq-loggers.gemspec +2 -2
- data/renovate.json +5 -0
- metadata +4 -19
- data/.codeclimate.yml +0 -34
- data/.rubocop_cc.yml +0 -4
- data/lib/manageiq/loggers/cloud_watch.rb +0 -33
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 62e1317e69617340944c4b101d38210b7b0c0f5338a27575cb8cc46a74c286ac
|
|
4
|
+
data.tar.gz: 9075da53591b01d2a5cebc39c2096b7969132d4b6a0462ed2a3fae7f26ed8101
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 79bb2f54cc014ef31a121f530b0d0115cb9388288d8a75dd1703d3ae0d9338b69dde905ec6ce6b1a523ad6ffdf9a4e51ad9aa6786fb3217d9b4ee001dba49b52
|
|
7
|
+
data.tar.gz: 2bdae67116b57656be0d049c546da40391825311b6f42346820a464ab7d9d945b767716ff5e9e8a4c81e403dc8d0fe641011530c7f5c5aed1529bd500106f399
|
data/.github/workflows/ci.yaml
CHANGED
|
@@ -1,30 +1,35 @@
|
|
|
1
|
-
---
|
|
2
1
|
name: CI
|
|
3
2
|
on:
|
|
4
|
-
push:
|
|
5
3
|
pull_request:
|
|
4
|
+
push:
|
|
5
|
+
branches-ignore:
|
|
6
|
+
- dependabot/*
|
|
7
|
+
- renovate/*
|
|
6
8
|
schedule:
|
|
7
9
|
- cron: 0 0 * * 0
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
concurrency:
|
|
12
|
+
group: "${{ github.workflow }}-${{ github.ref }}"
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
8
16
|
jobs:
|
|
9
17
|
ci:
|
|
10
18
|
runs-on: ubuntu-latest
|
|
11
19
|
strategy:
|
|
12
20
|
matrix:
|
|
13
21
|
ruby-version:
|
|
14
|
-
- '2.7'
|
|
15
|
-
- '3.0'
|
|
16
22
|
- '3.1'
|
|
17
23
|
- '3.2'
|
|
18
24
|
- '3.3'
|
|
25
|
+
- '3.4'
|
|
19
26
|
rails-version:
|
|
20
|
-
- '6.1'
|
|
21
|
-
- '7.0'
|
|
22
27
|
- '7.1'
|
|
28
|
+
- '7.2'
|
|
23
29
|
env:
|
|
24
|
-
TEST_RAILS_VERSION: ${{ matrix.rails-version }}
|
|
25
|
-
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
|
30
|
+
TEST_RAILS_VERSION: "${{ matrix.rails-version }}"
|
|
26
31
|
steps:
|
|
27
|
-
- uses: actions/checkout@
|
|
32
|
+
- uses: actions/checkout@v6
|
|
28
33
|
- name: Set up Ruby
|
|
29
34
|
uses: ruby/setup-ruby@v1
|
|
30
35
|
with:
|
|
@@ -33,7 +38,3 @@ jobs:
|
|
|
33
38
|
timeout-minutes: 30
|
|
34
39
|
- name: Run tests
|
|
35
40
|
run: bundle exec rake
|
|
36
|
-
- name: Report code coverage
|
|
37
|
-
if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '3.1' }}
|
|
38
|
-
continue-on-error: true
|
|
39
|
-
uses: paambaati/codeclimate-action@v5
|
data/CHANGELOG.md
CHANGED
|
@@ -5,9 +5,17 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
-
## [
|
|
8
|
+
## [2.0.0] - 2026-05-19
|
|
9
|
+
### Removed
|
|
10
|
+
- **BREAKING** Remove the deprecated `current_request.request_id` [(#80)](https://github.com/ManageIQ/manageiq-loggers/pull/80)
|
|
11
|
+
- **BREAKING** Remove the Cloudwatch Logger [(#81)](https://github.com/ManageIQ/manageiq-loggers/pull/81)
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- Add `#contents` method to Journald and File loggers [(#126)](https://github.com/ManageIQ/manageiq-loggers/pull/126)
|
|
15
|
+
|
|
9
16
|
### Fixed
|
|
10
17
|
- Handle nil caller_object in Journald logger [(#91)](https://github.com/ManageIQ/manageiq-loggers/pull/91)
|
|
18
|
+
- Determine caller location dynamically [(#92)](https://github.com/ManageIQ/manageiq-loggers/pull/92)
|
|
11
19
|
|
|
12
20
|
## [1.2.0] - 2024-09-30
|
|
13
21
|
### Added
|
|
@@ -102,8 +110,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
102
110
|
|
|
103
111
|
## [0.1.0] - 2019-01-08
|
|
104
112
|
|
|
105
|
-
[Unreleased]: https://github.com/ManageIQ/manageiq-loggers/compare/
|
|
106
|
-
[
|
|
113
|
+
[Unreleased]: https://github.com/ManageIQ/manageiq-loggers/compare/v2.0.0...master
|
|
114
|
+
[2.0.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.2.0...v2.0.0
|
|
107
115
|
[1.2.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.1.1...v1.2.0
|
|
108
116
|
[1.1.1]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.1.0...v1.1.1
|
|
109
117
|
[1.1.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.0.1...v1.1.0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# ManageIQ::Loggers
|
|
2
2
|
|
|
3
3
|
[](https://github.com/ManageIQ/manageiq-loggers/actions/workflows/ci.yaml)
|
|
4
|
-
[](https://codeclimate.com/github/ManageIQ/manageiq-loggers/maintainability)
|
|
5
|
-
[](https://codeclimate.com/github/ManageIQ/manageiq-loggers/test_coverage)
|
|
6
4
|
|
|
7
5
|
Loggers for ManageIQ projects
|
|
8
6
|
|
|
@@ -28,8 +26,6 @@ Some loggers require additional gems to function correctly. These gems are not s
|
|
|
28
26
|
|
|
29
27
|
To use the `Journald` logger, users must specify the `systemd-journal` gem as a dependency
|
|
30
28
|
|
|
31
|
-
To use the `CloudWatch` logger, users must specify the `cloudwatchlogger` gem as a dependency
|
|
32
|
-
|
|
33
29
|
## Development
|
|
34
30
|
|
|
35
31
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module ManageIQ
|
|
2
|
+
module Loggers
|
|
3
|
+
class File < Base
|
|
4
|
+
def contents(line_count = 1_000, buffer_size = 8_192)
|
|
5
|
+
return [] unless logdev&.filename && ::File.exist?(logdev.filename)
|
|
6
|
+
|
|
7
|
+
tail(line_count, buffer_size)
|
|
8
|
+
.select { |line| line&.unpack("U*") rescue nil }
|
|
9
|
+
.map { |line| line.force_encoding("utf-8") }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def tail(line_count, buffer_size)
|
|
15
|
+
lines = []
|
|
16
|
+
|
|
17
|
+
::File.open(logdev.filename, 'r') do |file|
|
|
18
|
+
# Start from the end of the file
|
|
19
|
+
file.seek(0, IO::SEEK_END)
|
|
20
|
+
file_size = file.pos
|
|
21
|
+
|
|
22
|
+
# If file is empty, return empty array
|
|
23
|
+
return [] if file_size.zero?
|
|
24
|
+
|
|
25
|
+
partial_line = ""
|
|
26
|
+
position = file_size
|
|
27
|
+
|
|
28
|
+
# Read backwards in chunks until we have enough lines
|
|
29
|
+
while position > 0 && lines.size < line_count
|
|
30
|
+
# Calculate how much to read
|
|
31
|
+
chunk_size = [buffer_size, position].min
|
|
32
|
+
position -= chunk_size
|
|
33
|
+
|
|
34
|
+
# Seek to position and read chunk
|
|
35
|
+
file.seek(position, IO::SEEK_SET)
|
|
36
|
+
chunk = file.read(chunk_size)
|
|
37
|
+
|
|
38
|
+
# Split into lines
|
|
39
|
+
chunk_lines = chunk.split("\n")
|
|
40
|
+
|
|
41
|
+
# Handle the last line in chunk (partial line continuing to next chunk)
|
|
42
|
+
# by appending the saved partial line to the last line of this chunk
|
|
43
|
+
chunk_lines[-1] = chunk_lines[-1] + partial_line unless partial_line.empty?
|
|
44
|
+
|
|
45
|
+
# If we're not at the start of the file, the first line is partial
|
|
46
|
+
partial_line = position > 0 ? chunk_lines.shift : ""
|
|
47
|
+
|
|
48
|
+
# Prepend complete lines to our result
|
|
49
|
+
lines.prepend(*chunk_lines)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Add the remaining partial line at the beginning
|
|
53
|
+
lines.unshift(partial_line) unless partial_line.empty?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
lines.last(line_count)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -45,8 +45,11 @@ module ManageIQ
|
|
|
45
45
|
# ActiveSupport::BroadcastLogger or the older ActiveSupport::Logger.broadcast
|
|
46
46
|
# so we have to account for that difference when walking up the caller_locations
|
|
47
47
|
# to get the "real" logging location.
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
caller_object = caller_locations.detect do |caller_loc|
|
|
49
|
+
next if caller_loc.path.end_with?("lib/active_support/broadcast_logger.rb", "lib/active_support/logger.rb", "/logger.rb")
|
|
50
|
+
|
|
51
|
+
caller_loc
|
|
52
|
+
end
|
|
50
53
|
|
|
51
54
|
Systemd::Journal.message(
|
|
52
55
|
:message => message,
|
|
@@ -58,6 +61,27 @@ module ManageIQ
|
|
|
58
61
|
)
|
|
59
62
|
end
|
|
60
63
|
|
|
64
|
+
def contents(max_count = 1_000)
|
|
65
|
+
Systemd::Journal.open do |journal|
|
|
66
|
+
journal.filter(:syslog_identifier => progname)
|
|
67
|
+
journal.seek(:tail)
|
|
68
|
+
|
|
69
|
+
results = []
|
|
70
|
+
max_count.times do
|
|
71
|
+
break unless journal.move_previous
|
|
72
|
+
|
|
73
|
+
entry = journal.current_entry
|
|
74
|
+
# This is the time in microseconds since the epoch UTC, formatted as a decimal string.
|
|
75
|
+
seconds_since_epoch = entry._source_realtime_timestamp.to_f / 1_000_000.0
|
|
76
|
+
timestamp = Time.at(seconds_since_epoch).strftime("%Y-%m-%dT%H:%M:%S.%6N")
|
|
77
|
+
|
|
78
|
+
results << "[#{timestamp} ##{entry._pid}] #{entry.message}"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
results.reverse
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
61
85
|
private
|
|
62
86
|
|
|
63
87
|
# Map the Systemd::Journal error levels to the Logger error levels. For
|
|
@@ -63,13 +63,7 @@ module ManageIQ
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def request_id
|
|
66
|
-
Thread.current[: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
|
|
66
|
+
Thread.current[:request_id]
|
|
73
67
|
end
|
|
74
68
|
end
|
|
75
69
|
end
|
data/lib/manageiq/loggers.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
require "manageiq/loggers/base"
|
|
2
2
|
require "manageiq/loggers/json_logger"
|
|
3
3
|
|
|
4
|
-
require "manageiq/loggers/cloud_watch"
|
|
5
4
|
require "manageiq/loggers/container"
|
|
5
|
+
require "manageiq/loggers/file"
|
|
6
6
|
require "manageiq/loggers/journald"
|
|
7
7
|
|
|
8
8
|
require "manageiq/loggers/version"
|
data/manageiq-loggers.gemspec
CHANGED
|
@@ -25,8 +25,8 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
spec.add_runtime_dependency "manageiq-password", "< 2"
|
|
26
26
|
|
|
27
27
|
spec.add_development_dependency "bundler"
|
|
28
|
-
spec.add_development_dependency "
|
|
29
|
-
|
|
28
|
+
spec.add_development_dependency "manageiq-style"
|
|
29
|
+
|
|
30
30
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
32
32
|
spec.add_development_dependency "simplecov", ">= 0.21.2"
|
data/renovate.json
ADDED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: manageiq-loggers
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ManageIQ Authors
|
|
@@ -52,7 +52,7 @@ dependencies:
|
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
53
|
version: '0'
|
|
54
54
|
- !ruby/object:Gem::Dependency
|
|
55
|
-
name:
|
|
55
|
+
name: manageiq-style
|
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
|
57
57
|
requirements:
|
|
58
58
|
- - ">="
|
|
@@ -65,20 +65,6 @@ dependencies:
|
|
|
65
65
|
- - ">="
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '0'
|
|
68
|
-
- !ruby/object:Gem::Dependency
|
|
69
|
-
name: manageiq-style
|
|
70
|
-
requirement: !ruby/object:Gem::Requirement
|
|
71
|
-
requirements:
|
|
72
|
-
- - ">="
|
|
73
|
-
- !ruby/object:Gem::Version
|
|
74
|
-
version: 1.5.2
|
|
75
|
-
type: :development
|
|
76
|
-
prerelease: false
|
|
77
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
-
requirements:
|
|
79
|
-
- - ">="
|
|
80
|
-
- !ruby/object:Gem::Version
|
|
81
|
-
version: 1.5.2
|
|
82
68
|
- !ruby/object:Gem::Dependency
|
|
83
69
|
name: rake
|
|
84
70
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -139,12 +125,10 @@ executables: []
|
|
|
139
125
|
extensions: []
|
|
140
126
|
extra_rdoc_files: []
|
|
141
127
|
files:
|
|
142
|
-
- ".codeclimate.yml"
|
|
143
128
|
- ".github/workflows/ci.yaml"
|
|
144
129
|
- ".gitignore"
|
|
145
130
|
- ".rspec"
|
|
146
131
|
- ".rubocop.yml"
|
|
147
|
-
- ".rubocop_cc.yml"
|
|
148
132
|
- ".rubocop_local.yml"
|
|
149
133
|
- ".whitesource"
|
|
150
134
|
- CHANGELOG.md
|
|
@@ -157,12 +141,13 @@ files:
|
|
|
157
141
|
- lib/manageiq-loggers.rb
|
|
158
142
|
- lib/manageiq/loggers.rb
|
|
159
143
|
- lib/manageiq/loggers/base.rb
|
|
160
|
-
- lib/manageiq/loggers/cloud_watch.rb
|
|
161
144
|
- lib/manageiq/loggers/container.rb
|
|
145
|
+
- lib/manageiq/loggers/file.rb
|
|
162
146
|
- lib/manageiq/loggers/journald.rb
|
|
163
147
|
- lib/manageiq/loggers/json_logger.rb
|
|
164
148
|
- lib/manageiq/loggers/version.rb
|
|
165
149
|
- manageiq-loggers.gemspec
|
|
150
|
+
- renovate.json
|
|
166
151
|
homepage: https://github.com/ManageIQ/manageiq-loggers
|
|
167
152
|
licenses:
|
|
168
153
|
- Apache-2.0
|
data/.codeclimate.yml
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
version: '2'
|
|
2
|
-
prepare:
|
|
3
|
-
fetch:
|
|
4
|
-
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_base.yml
|
|
5
|
-
path: ".rubocop_base.yml"
|
|
6
|
-
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_cc_base.yml
|
|
7
|
-
path: ".rubocop_cc_base.yml"
|
|
8
|
-
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/base.yml
|
|
9
|
-
path: styles/base.yml
|
|
10
|
-
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/cc_base.yml
|
|
11
|
-
path: styles/cc_base.yml
|
|
12
|
-
checks:
|
|
13
|
-
argument-count:
|
|
14
|
-
enabled: false
|
|
15
|
-
complex-logic:
|
|
16
|
-
enabled: false
|
|
17
|
-
file-lines:
|
|
18
|
-
enabled: false
|
|
19
|
-
method-complexity:
|
|
20
|
-
config:
|
|
21
|
-
threshold: 11
|
|
22
|
-
method-count:
|
|
23
|
-
enabled: false
|
|
24
|
-
method-lines:
|
|
25
|
-
enabled: false
|
|
26
|
-
nested-control-flow:
|
|
27
|
-
enabled: false
|
|
28
|
-
return-statements:
|
|
29
|
-
enabled: false
|
|
30
|
-
plugins:
|
|
31
|
-
rubocop:
|
|
32
|
-
enabled: true
|
|
33
|
-
config: ".rubocop_cc.yml"
|
|
34
|
-
channel: rubocop-1-56-3
|
data/.rubocop_cc.yml
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
require 'active_support'
|
|
2
|
-
require 'active_support/core_ext/object'
|
|
3
|
-
require 'active_support/logger'
|
|
4
|
-
|
|
5
|
-
module ManageIQ
|
|
6
|
-
module Loggers
|
|
7
|
-
class CloudWatch < Base
|
|
8
|
-
NAMESPACE_FILE = "/var/run/secrets/kubernetes.io/serviceaccount/namespace".freeze
|
|
9
|
-
|
|
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
|
-
|
|
16
|
-
container_logger = ManageIQ::Loggers::Container.new
|
|
17
|
-
return container_logger unless access_key_id && secret_access_key && log_group && log_stream
|
|
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, log_stream)
|
|
23
|
-
cloud_watch_logger = super(cloud_watch_logdev)
|
|
24
|
-
cloud_watch_logger.wrap(container_logger)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def initialize(logdev, *args)
|
|
28
|
-
super
|
|
29
|
-
self.formatter = ManageIQ::Loggers::Container::Formatter.new
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|