manageiq-loggers 1.2.1 → 2.1.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 -14
- data/CHANGELOG.md +24 -3
- data/Gemfile +3 -5
- data/README.md +0 -4
- data/lib/manageiq/loggers/file.rb +60 -0
- data/lib/manageiq/loggers/journald.rb +25 -2
- data/lib/manageiq/loggers/json_logger.rb +3 -9
- data/lib/manageiq/loggers/version.rb +1 -1
- data/lib/manageiq/loggers.rb +1 -1
- data/manageiq-loggers.gemspec +4 -3
- data/renovate.json +5 -0
- metadata +5 -20
- 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: 8436652271025cd7faabe99d78bd9d27b5690fd49909cf889c2b9fd352abbd86
|
|
4
|
+
data.tar.gz: 2f5d7c4107e054ef821ae283376b08f40dac7f8451848ad257f14a0e5d11b1b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: abce2d09ce6efb68d5a36154f19ebe21a1d2eea7b7b16d82e0d427f9e696fb51907ed44ea19f7075622357413646e4a105062e0824ebda27e143d88ae3d733d2
|
|
7
|
+
data.tar.gz: c7aa682bdc273c3e917e3e13f560a63ed3560a669f74befd471271cdaeaaa982482a6fb1058226277ec0edc517bd57726c0c03d24202672bb26e0e4b21f54d9a
|
data/.github/workflows/ci.yaml
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
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
|
-
- '3.1'
|
|
17
22
|
- '3.2'
|
|
18
23
|
- '3.3'
|
|
24
|
+
- '3.4'
|
|
19
25
|
rails-version:
|
|
20
|
-
- '6.1'
|
|
21
|
-
- '7.0'
|
|
22
26
|
- '7.1'
|
|
27
|
+
- '7.2'
|
|
23
28
|
env:
|
|
24
|
-
TEST_RAILS_VERSION: ${{ matrix.rails-version }}
|
|
25
|
-
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
|
29
|
+
TEST_RAILS_VERSION: "${{ matrix.rails-version }}"
|
|
26
30
|
steps:
|
|
27
|
-
- uses: actions/checkout@
|
|
31
|
+
- uses: actions/checkout@v7
|
|
28
32
|
- name: Set up Ruby
|
|
29
33
|
uses: ruby/setup-ruby@v1
|
|
30
34
|
with:
|
|
@@ -33,7 +37,3 @@ jobs:
|
|
|
33
37
|
timeout-minutes: 30
|
|
34
38
|
- name: Run tests
|
|
35
39
|
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,29 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
-
## [
|
|
8
|
+
## [2.1.0] - 2026-11-03
|
|
9
|
+
### Changed
|
|
10
|
+
- Update the minimum ruby version to 3.2 [(#142)](https://github.com/ManageIQ/manageiq-loggers/pull/142)
|
|
11
|
+
- Set timezone for journald specs [(#128)](https://github.com/ManageIQ/manageiq-loggers/pull/128)
|
|
12
|
+
- Replace TZ env var with Time.use_zone in tests [(#134)](https://github.com/ManageIQ/manageiq-loggers/pull/134)
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- Fix JSON v3 unicode conversion [(#143)](https://github.com/ManageIQ/manageiq-loggers/pull/143)
|
|
16
|
+
- Fix running tests on macOS [(#132)](https://github.com/ManageIQ/manageiq-loggers/pull/132)
|
|
17
|
+
- Fix Journald#contents timestamp by using entry.realtime_timestamp [(#144)](https://github.com/ManageIQ/manageiq-loggers/pull/144)
|
|
18
|
+
- Fix contents raising error when line_count/max_count is nil [(#141)](https://github.com/ManageIQ/manageiq-loggers/pull/141)
|
|
19
|
+
|
|
20
|
+
## [2.0.0] - 2026-05-19
|
|
21
|
+
### Removed
|
|
22
|
+
- **BREAKING** Remove the deprecated `current_request.request_id` [(#80)](https://github.com/ManageIQ/manageiq-loggers/pull/80)
|
|
23
|
+
- **BREAKING** Remove the Cloudwatch Logger [(#81)](https://github.com/ManageIQ/manageiq-loggers/pull/81)
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
- Add `#contents` method to Journald and File loggers [(#126)](https://github.com/ManageIQ/manageiq-loggers/pull/126)
|
|
27
|
+
|
|
9
28
|
### Fixed
|
|
10
29
|
- Handle nil caller_object in Journald logger [(#91)](https://github.com/ManageIQ/manageiq-loggers/pull/91)
|
|
30
|
+
- Determine caller location dynamically [(#92)](https://github.com/ManageIQ/manageiq-loggers/pull/92)
|
|
11
31
|
|
|
12
32
|
## [1.2.0] - 2024-09-30
|
|
13
33
|
### Added
|
|
@@ -102,8 +122,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
102
122
|
|
|
103
123
|
## [0.1.0] - 2019-01-08
|
|
104
124
|
|
|
105
|
-
[Unreleased]: https://github.com/ManageIQ/manageiq-loggers/compare/
|
|
106
|
-
[
|
|
125
|
+
[Unreleased]: https://github.com/ManageIQ/manageiq-loggers/compare/v2.1.0...master
|
|
126
|
+
[2.1.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v2.0.0...v2.1.0
|
|
127
|
+
[2.0.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.2.0...v2.0.0
|
|
107
128
|
[1.2.0]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.1.1...v1.2.0
|
|
108
129
|
[1.1.1]: https://github.com/ManageIQ/manageiq-loggers/compare/v1.1.0...v1.1.1
|
|
109
130
|
[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 && (line_count.nil? || 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
|
+
line_count ? lines.last(line_count) : lines
|
|
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,26 @@ 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
|
+
loop do
|
|
71
|
+
break if max_count && results.size >= max_count
|
|
72
|
+
break unless journal.move_previous
|
|
73
|
+
|
|
74
|
+
entry = journal.current_entry
|
|
75
|
+
timestamp = entry.realtime_timestamp.in_time_zone.iso8601(6)
|
|
76
|
+
|
|
77
|
+
results << "[#{timestamp} ##{entry._pid}] #{entry.message}"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
results.reverse
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
61
84
|
private
|
|
62
85
|
|
|
63
86
|
# Map the Systemd::Journal error levels to the Logger error levels. For
|
|
@@ -37,10 +37,10 @@ module ManageIQ
|
|
|
37
37
|
# :tags => "tags string",
|
|
38
38
|
}.compact
|
|
39
39
|
JSON.generate(payload) << "\n"
|
|
40
|
-
rescue Encoding::UndefinedConversionError
|
|
40
|
+
rescue Encoding::UndefinedConversionError, JSON::GeneratorError
|
|
41
41
|
raise unless msg.encoding == Encoding::ASCII_8BIT
|
|
42
42
|
|
|
43
|
-
msg.force_encoding("UTF-8")
|
|
43
|
+
msg = msg.dup.force_encoding("UTF-8")
|
|
44
44
|
retry
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -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
|
@@ -11,6 +11,7 @@ Gem::Specification.new do |spec|
|
|
|
11
11
|
spec.summary = %q{Loggers for ManageIQ projects}
|
|
12
12
|
spec.homepage = "https://github.com/ManageIQ/manageiq-loggers"
|
|
13
13
|
spec.licenses = ["Apache-2.0"]
|
|
14
|
+
spec.required_ruby_version = ">= 3.2.0"
|
|
14
15
|
|
|
15
16
|
# Specify which files should be added to the gem when it is released.
|
|
16
17
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
@@ -25,10 +26,10 @@ Gem::Specification.new do |spec|
|
|
|
25
26
|
spec.add_runtime_dependency "manageiq-password", "< 2"
|
|
26
27
|
|
|
27
28
|
spec.add_development_dependency "bundler"
|
|
28
|
-
spec.add_development_dependency "
|
|
29
|
-
|
|
29
|
+
spec.add_development_dependency "manageiq-style"
|
|
30
|
+
|
|
30
31
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
|
31
32
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
32
33
|
spec.add_development_dependency "simplecov", ">= 0.21.2"
|
|
33
|
-
spec.add_development_dependency "systemd-journal" if RbConfig::CONFIG['host_os']
|
|
34
|
+
spec.add_development_dependency "systemd-journal" if RbConfig::CONFIG['host_os'].match?(/linux/i)
|
|
34
35
|
end
|
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.1.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
|
|
@@ -174,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
174
159
|
requirements:
|
|
175
160
|
- - ">="
|
|
176
161
|
- !ruby/object:Gem::Version
|
|
177
|
-
version:
|
|
162
|
+
version: 3.2.0
|
|
178
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
164
|
requirements:
|
|
180
165
|
- - ">="
|
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
|