manageiq-loggers 1.2.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd4bab057f20ec23828b6022014a09287dfa36cc6e949a4a08e9d9b2aaa44fcf
4
- data.tar.gz: 678048c7efc29635002762d7d8e7f6cb0d5705dafbb4eac2d996dcf65fdb22e6
3
+ metadata.gz: 62e1317e69617340944c4b101d38210b7b0c0f5338a27575cb8cc46a74c286ac
4
+ data.tar.gz: 9075da53591b01d2a5cebc39c2096b7969132d4b6a0462ed2a3fae7f26ed8101
5
5
  SHA512:
6
- metadata.gz: 2cc7c13f6f5b5b05f5acff45a9929fb5ae3029537b8270dbad33a40212b56de54e4484b3420c2ff03a9d8def9285698cd53aad592365e7fac2709a09c4f6beeb
7
- data.tar.gz: adee41825340cc2d8138414f86e129f9d33b893d124a290508cea01ea3fce22bbd478fdfeb249ba281c172983733df26f59069bb795ce63ffc2a8831e46f9388
6
+ metadata.gz: 79bb2f54cc014ef31a121f530b0d0115cb9388288d8a75dd1703d3ae0d9338b69dde905ec6ce6b1a523ad6ffdf9a4e51ad9aa6786fb3217d9b4ee001dba49b52
7
+ data.tar.gz: 2bdae67116b57656be0d049c546da40391825311b6f42346820a464ab7d9d945b767716ff5e9e8a4c81e403dc8d0fe641011530c7f5c5aed1529bd500106f399
@@ -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@v4
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,6 +5,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
6
  ## [Unreleased]
7
7
 
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
+
16
+ ### Fixed
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)
19
+
8
20
  ## [1.2.0] - 2024-09-30
9
21
  ### Added
10
22
  - Test with ruby 3.1 and 3.0 [(#65)](https://github.com/ManageIQ/manageiq-loggers/pull/65)
@@ -98,7 +110,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
98
110
 
99
111
  ## [0.1.0] - 2019-01-08
100
112
 
101
- [Unreleased]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.2.0...master
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
102
115
  [1.2.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.1.1...v1.2.0
103
116
  [1.1.1]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.1.0...v1.1.1
104
117
  [1.1.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.0.1...v1.1.0
data/Gemfile CHANGED
@@ -5,12 +5,10 @@ gemspec
5
5
 
6
6
  minimum_version =
7
7
  case ENV['TEST_RAILS_VERSION']
8
- when "6.1"
9
- "~>6.1.7"
10
- when "7.0"
11
- "~>7.0.8"
8
+ when "7.2"
9
+ "~>7.2.2"
12
10
  else
13
- "~>7.1.4"
11
+ "~>7.1.5"
14
12
  end
15
13
 
16
14
  gem "activesupport", minimum_version
data/README.md CHANGED
@@ -1,8 +1,6 @@
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
- [![Maintainability](https://api.codeclimate.com/v1/badges/8d3c9bf77c45a024166b/maintainability)](https://codeclimate.com/github/ManageIQ/manageiq-loggers/maintainability)
5
- [![Test Coverage](https://api.codeclimate.com/v1/badges/8d3c9bf77c45a024166b/test_coverage)](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,19 +45,43 @@ 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
- callstack_start = ActiveSupport.gem_version >= Gem::Version.new("7.1.0") ? 7 : 3
49
- caller_object = caller_locations(callstack_start, 1).first
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,
53
56
  :priority => log_level_map[severity],
54
57
  :syslog_identifier => progname,
55
- :code_line => caller_object.lineno,
56
- :code_file => caller_object.absolute_path,
57
- :code_func => caller_object.label
58
+ :code_line => caller_object&.lineno,
59
+ :code_file => caller_object&.absolute_path,
60
+ :code_func => caller_object&.label
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] || 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
66
+ Thread.current[:request_id]
73
67
  end
74
68
  end
75
69
  end
@@ -1,5 +1,5 @@
1
1
  module ManageIQ
2
2
  module Loggers
3
- VERSION = "1.2.0".freeze
3
+ VERSION = "2.0.0".freeze
4
4
  end
5
5
  end
@@ -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"
@@ -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 "cloudwatchlogger"
29
- spec.add_development_dependency "manageiq-style", ">= 1.5.2"
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
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "inheritConfig": true,
4
+ "inheritConfigRepoName": "manageiq/renovate-config"
5
+ }
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manageiq-loggers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Authors
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-09-30 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -53,7 +52,7 @@ dependencies:
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
54
  - !ruby/object:Gem::Dependency
56
- name: cloudwatchlogger
55
+ name: manageiq-style
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ">="
@@ -66,20 +65,6 @@ dependencies:
66
65
  - - ">="
67
66
  - !ruby/object:Gem::Version
68
67
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: manageiq-style
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: 1.5.2
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 1.5.2
83
68
  - !ruby/object:Gem::Dependency
84
69
  name: rake
85
70
  requirement: !ruby/object:Gem::Requirement
@@ -136,18 +121,14 @@ dependencies:
136
121
  - - ">="
137
122
  - !ruby/object:Gem::Version
138
123
  version: '0'
139
- description:
140
- email:
141
124
  executables: []
142
125
  extensions: []
143
126
  extra_rdoc_files: []
144
127
  files:
145
- - ".codeclimate.yml"
146
128
  - ".github/workflows/ci.yaml"
147
129
  - ".gitignore"
148
130
  - ".rspec"
149
131
  - ".rubocop.yml"
150
- - ".rubocop_cc.yml"
151
132
  - ".rubocop_local.yml"
152
133
  - ".whitesource"
153
134
  - CHANGELOG.md
@@ -160,17 +141,17 @@ files:
160
141
  - lib/manageiq-loggers.rb
161
142
  - lib/manageiq/loggers.rb
162
143
  - lib/manageiq/loggers/base.rb
163
- - lib/manageiq/loggers/cloud_watch.rb
164
144
  - lib/manageiq/loggers/container.rb
145
+ - lib/manageiq/loggers/file.rb
165
146
  - lib/manageiq/loggers/journald.rb
166
147
  - lib/manageiq/loggers/json_logger.rb
167
148
  - lib/manageiq/loggers/version.rb
168
149
  - manageiq-loggers.gemspec
150
+ - renovate.json
169
151
  homepage: https://github.com/ManageIQ/manageiq-loggers
170
152
  licenses:
171
153
  - Apache-2.0
172
154
  metadata: {}
173
- post_install_message:
174
155
  rdoc_options: []
175
156
  require_paths:
176
157
  - lib
@@ -185,8 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
166
  - !ruby/object:Gem::Version
186
167
  version: '0'
187
168
  requirements: []
188
- rubygems_version: 3.4.20
189
- signing_key:
169
+ rubygems_version: 3.6.7
190
170
  specification_version: 4
191
171
  summary: Loggers for ManageIQ projects
192
172
  test_files: []
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,4 +0,0 @@
1
- inherit_from:
2
- - ".rubocop_base.yml"
3
- - ".rubocop_cc_base.yml"
4
- - ".rubocop_local.yml"
@@ -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