manageiq-loggers 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +30 -0
- data/.gitignore +13 -0
- data/.rspec +4 -0
- data/.rubocop.yml +3 -0
- data/.rubocop_cc.yml +4 -0
- data/.rubocop_local.yml +0 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +202 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/manageiq-loggers.rb +1 -0
- data/lib/manageiq/loggers.rb +3 -0
- data/lib/manageiq/loggers/base.rb +144 -0
- data/lib/manageiq/loggers/container.rb +65 -0
- data/lib/manageiq/loggers/version.rb +5 -0
- data/manageiq-loggers.gemspec +31 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cf9102c7cd34f1b075d6ae1bbdb08e5eaf26f622
|
4
|
+
data.tar.gz: 50a3e00b0e3b299e015458948bb2c73d7a41c28e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f742b9bce4252b148a851ee75847e0dd2bc8cbc1d9acfafe72921c3da01da1e194cdd7a5ccf046dd1eb2581bdb4b7dd1500af364d52873e274335866e81cebf7
|
7
|
+
data.tar.gz: f6cc05586fd0e08021507e0436588dbb19f82c13e33e0fd03f699e79069844df2163685504c141ac37748fc545eba340a0014a91868ecb60e78c458a4d2f1cb6
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
version: '2'
|
3
|
+
prepare:
|
4
|
+
fetch:
|
5
|
+
- url: https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_base.yml
|
6
|
+
path: ".rubocop_base.yml"
|
7
|
+
- url: https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_cc_base.yml
|
8
|
+
path: ".rubocop_cc_base.yml"
|
9
|
+
checks:
|
10
|
+
argument-count:
|
11
|
+
enabled: false
|
12
|
+
complex-logic:
|
13
|
+
enabled: false
|
14
|
+
file-lines:
|
15
|
+
enabled: false
|
16
|
+
method-complexity:
|
17
|
+
config:
|
18
|
+
threshold: 11
|
19
|
+
method-count:
|
20
|
+
enabled: false
|
21
|
+
method-lines:
|
22
|
+
enabled: false
|
23
|
+
nested-control-flow:
|
24
|
+
enabled: false
|
25
|
+
return-statements:
|
26
|
+
enabled: false
|
27
|
+
plugins:
|
28
|
+
rubocop:
|
29
|
+
enabled: true
|
30
|
+
config: ".rubocop_cc.yml"
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_cc.yml
ADDED
data/.rubocop_local.yml
ADDED
File without changes
|
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
language: ruby
|
3
|
+
sudo: false
|
4
|
+
cache: bundler
|
5
|
+
rvm:
|
6
|
+
- 2.4.5
|
7
|
+
- 2.5.3
|
8
|
+
before_script:
|
9
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
10
|
+
- chmod +x ./cc-test-reporter
|
11
|
+
- "./cc-test-reporter before-build"
|
12
|
+
after_script:
|
13
|
+
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
|
+
|
6
|
+
## [Unreleased]
|
7
|
+
|
8
|
+
## [0.1.0] - 2019-01-08
|
9
|
+
|
10
|
+
[Unreleased]: https://github.com/ManageIQ/manageiq-loggers/compare/v0.1.0...master
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# ManageIQ::Loggers
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/ManageIQ/manageiq-loggers.svg)](https://travis-ci.org/ManageIQ/manageiq-loggers)
|
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
|
+
[![Security](https://hakiri.io/github/ManageIQ/manageiq-loggers/master.svg)](https://hakiri.io/github/ManageIQ/manageiq-loggers/master)
|
7
|
+
|
8
|
+
Loggers for ManageIQ projects
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'manageiq-loggers'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install manageiq-loggers
|
25
|
+
|
26
|
+
## Development
|
27
|
+
|
28
|
+
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.
|
29
|
+
|
30
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/manageiq-loggers.
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
This project is available as open source under the terms of the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "manageiq/loggers"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "manageiq/loggers"
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'active_support/core_ext/object/try'
|
3
|
+
require 'active_support/core_ext/numeric/bytes'
|
4
|
+
require 'active_support/core_ext/string'
|
5
|
+
require 'English'
|
6
|
+
|
7
|
+
module ManageIQ
|
8
|
+
module Loggers
|
9
|
+
class Base < Logger
|
10
|
+
MAX_LOG_LINE_LENGTH = 1.megabyte
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super
|
14
|
+
self.level = INFO
|
15
|
+
|
16
|
+
# HACK: ActiveSupport monkey patches the standard Ruby Logger#initialize
|
17
|
+
# method to set @formatter to a SimpleFormatter.
|
18
|
+
#
|
19
|
+
# The ActiveSupport Logger patches are deprecated in Rails 3.1.1 in favor of
|
20
|
+
# ActiveSupport::BufferedLogger, so this hack may not be needed in future
|
21
|
+
# version of Rails.
|
22
|
+
self.formatter = Formatter.new
|
23
|
+
|
24
|
+
# Allow for thread safe Logger level changes, similar to functionalities
|
25
|
+
# provided by ActiveSupport::LoggerThreadSafeLevel
|
26
|
+
@write_lock = Mutex.new
|
27
|
+
@local_levels = {}
|
28
|
+
end
|
29
|
+
|
30
|
+
# Silences the logger for the duration of the block.
|
31
|
+
#
|
32
|
+
# Taken from activesupport/logger_silence
|
33
|
+
def silence(temporary_level = Logger::ERROR)
|
34
|
+
old_local_level = local_level
|
35
|
+
self.local_level = temporary_level
|
36
|
+
|
37
|
+
yield self
|
38
|
+
ensure
|
39
|
+
self.local_level = old_local_level
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_reader :logdev # Expose logdev
|
43
|
+
|
44
|
+
def logdev=(logdev)
|
45
|
+
if @logdev
|
46
|
+
shift_age = @logdev.instance_variable_get(:@shift_age)
|
47
|
+
shift_size = @logdev.instance_variable_get(:@shift_size)
|
48
|
+
@logdev.close
|
49
|
+
else
|
50
|
+
shift_age = 0
|
51
|
+
shift_size = 1048576
|
52
|
+
end
|
53
|
+
|
54
|
+
@logdev = LogDevice.new(logdev, :shift_age => shift_age, :shift_size => shift_size)
|
55
|
+
end
|
56
|
+
|
57
|
+
def log_backtrace(err, level = :error)
|
58
|
+
# Get the name of the method that called us unless it is a wrapped log_backtrace
|
59
|
+
method_name = nil
|
60
|
+
caller.each do |c|
|
61
|
+
method_name = c[/`([^']*)'/, 1]
|
62
|
+
break unless method_name == 'log_backtrace'
|
63
|
+
end
|
64
|
+
|
65
|
+
# Log the error text
|
66
|
+
send(level, "[#{err.class.name}]: #{err.message} Method:[#{method_name}]")
|
67
|
+
|
68
|
+
# Log the stack trace except for some specific exceptions
|
69
|
+
unless (Object.const_defined?(:MiqException) && err.kind_of?(MiqException::Error)) ||
|
70
|
+
(Object.const_defined?(:MiqAeException) && err.kind_of?(MiqAeException::Error))
|
71
|
+
send(level, err.backtrace.nil? || err.backtrace.empty? ? "Backtrace is not available" : err.backtrace.join("\n"))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.log_hashes(logger, h, options = {})
|
76
|
+
require 'yaml'
|
77
|
+
require 'manageiq/password'
|
78
|
+
|
79
|
+
level = options[:log_level] || :info
|
80
|
+
filter = Array(options[:filter]).flatten.compact.map(&:to_s) << "password"
|
81
|
+
filter.uniq!
|
82
|
+
|
83
|
+
values = YAML.dump(h.to_hash).gsub(ManageIQ::Password::REGEXP, "[FILTERED]")
|
84
|
+
values = values.split("\n").map do |l|
|
85
|
+
if (key = filter.detect { |f| l.include?(f) })
|
86
|
+
l.gsub!(/#{key}.*: (.+)/) { |m| m.gsub!($1, "[FILTERED]") }
|
87
|
+
end
|
88
|
+
l
|
89
|
+
end.join("\n")
|
90
|
+
|
91
|
+
logger.send(level, "\n#{values}")
|
92
|
+
end
|
93
|
+
|
94
|
+
def log_hashes(h, options = {})
|
95
|
+
self.class.log_hashes(self, h, options)
|
96
|
+
end
|
97
|
+
|
98
|
+
def level
|
99
|
+
local_level || super
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def local_log_id
|
105
|
+
Thread.current.object_id
|
106
|
+
end
|
107
|
+
|
108
|
+
def local_level
|
109
|
+
@local_levels[local_log_id]
|
110
|
+
end
|
111
|
+
|
112
|
+
def local_level=(level)
|
113
|
+
@write_lock.synchronize do
|
114
|
+
if level
|
115
|
+
@local_levels[local_log_id] = level
|
116
|
+
else
|
117
|
+
@local_levels.delete(local_log_id)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class Formatter < Logger::Formatter
|
123
|
+
FORMAT = "[----] %s, [%s#%d:%x] %5s -- %s: %s\n"
|
124
|
+
|
125
|
+
def call(severity, time, progname, msg)
|
126
|
+
msg = prefix_task_id(msg2str(msg)).truncate(MAX_LOG_LINE_LENGTH)
|
127
|
+
FORMAT % [severity[0..0], format_datetime(time), $PROCESS_ID, Thread.current.object_id, severity, progname, msg]
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def prefix_task_id(msg)
|
133
|
+
# Add task id to the message if a task is currently being worked on.
|
134
|
+
if (task_id = (Thread.current["tracking_label"] || $_miq_worker_current_msg.try(:task_id)))
|
135
|
+
prefix = "Q-task_id([#{task_id}])"
|
136
|
+
msg = "#{prefix} #{msg}" unless msg.include?(prefix)
|
137
|
+
end
|
138
|
+
|
139
|
+
msg
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module ManageIQ
|
2
|
+
module Loggers
|
3
|
+
class Container < Base
|
4
|
+
def initialize(logdev = STDOUT, *args)
|
5
|
+
super
|
6
|
+
self.level = DEBUG
|
7
|
+
self.formatter = Formatter.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def level=(_new_level)
|
11
|
+
super(DEBUG) # We want everything written to the ContainerLogger written to STDOUT
|
12
|
+
end
|
13
|
+
|
14
|
+
def filename
|
15
|
+
"STDOUT"
|
16
|
+
end
|
17
|
+
|
18
|
+
class Formatter < Base::Formatter
|
19
|
+
SEVERITY_MAP = {
|
20
|
+
"DEBUG" => "debug",
|
21
|
+
"INFO" => "info",
|
22
|
+
"WARN" => "warning",
|
23
|
+
"ERROR" => "err",
|
24
|
+
"FATAL" => "crit",
|
25
|
+
"UNKNOWN" => "unknown"
|
26
|
+
# Others that don't match up: alert emerg notice trace
|
27
|
+
}.freeze
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
super
|
31
|
+
require 'json'
|
32
|
+
end
|
33
|
+
|
34
|
+
def call(severity, time, progname, msg)
|
35
|
+
# From https://github.com/ViaQ/elasticsearch-templates/releases -> Downloads -> *.asciidoc
|
36
|
+
# NOTE: These values are in a specific order for easier human readbility via STDOUT
|
37
|
+
{
|
38
|
+
:@timestamp => format_datetime(time),
|
39
|
+
:hostname => hostname,
|
40
|
+
:pid => $PROCESS_ID,
|
41
|
+
:tid => thread_id,
|
42
|
+
:service => progname,
|
43
|
+
:level => translate_error(severity),
|
44
|
+
:message => prefix_task_id(msg2str(msg)),
|
45
|
+
# :tags => "tags string",
|
46
|
+
}.compact.to_json << "\n"
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def hostname
|
52
|
+
@hostname ||= ENV["HOSTNAME"]
|
53
|
+
end
|
54
|
+
|
55
|
+
def thread_id
|
56
|
+
Thread.current.object_id.to_s(16)
|
57
|
+
end
|
58
|
+
|
59
|
+
def translate_error(level)
|
60
|
+
SEVERITY_MAP[level] || "unknown"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "manageiq/loggers/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "manageiq-loggers"
|
8
|
+
spec.version = Manageiq::Loggers::VERSION
|
9
|
+
spec.authors = ["ManageIQ Authors"]
|
10
|
+
|
11
|
+
spec.summary = %q{Loggers for ManageIQ projects}
|
12
|
+
spec.homepage = "https://github.com/ManageIQ/manageiq-loggers"
|
13
|
+
spec.licenses = ["Apache-2.0"]
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "activesupport", ">= 5.0"
|
25
|
+
spec.add_runtime_dependency "manageiq-password", "~> 0.1"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "simplecov"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: manageiq-loggers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ManageIQ Authors
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: manageiq-password
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- ".codeclimate.yml"
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".rubocop_cc.yml"
|
108
|
+
- ".rubocop_local.yml"
|
109
|
+
- ".travis.yml"
|
110
|
+
- CHANGELOG.md
|
111
|
+
- Gemfile
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- bin/console
|
116
|
+
- bin/setup
|
117
|
+
- lib/manageiq-loggers.rb
|
118
|
+
- lib/manageiq/loggers.rb
|
119
|
+
- lib/manageiq/loggers/base.rb
|
120
|
+
- lib/manageiq/loggers/container.rb
|
121
|
+
- lib/manageiq/loggers/version.rb
|
122
|
+
- manageiq-loggers.gemspec
|
123
|
+
homepage: https://github.com/ManageIQ/manageiq-loggers
|
124
|
+
licenses:
|
125
|
+
- Apache-2.0
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.6.14
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Loggers for ManageIQ projects
|
147
|
+
test_files: []
|