Module: Scalyr
- Defined in:
- lib/fluent/plugin/scalyr_utils.rb,
lib/fluent/plugin/out_scalyr.rb,
lib/fluent/plugin/scalyr_exceptions.rb
Overview
Scalyr Output Plugin for Fluentd
Copyright © 2015 Scalyr, Inc.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Defined Under Namespace
Classes: Client4xxError, ClientError, ScalyrOut, ServerError
Instance Method Summary collapse
- #sanitize_and_reencode_array(array) ⇒ Object
- #sanitize_and_reencode_hash(hash) ⇒ Object
- #sanitize_and_reencode_string(value) ⇒ Object
- #sanitize_and_reencode_value(value) ⇒ Object
Instance Method Details
#sanitize_and_reencode_array(array) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/fluent/plugin/scalyr_utils.rb', line 39 def sanitize_and_reencode_array(array) array.each_with_index do |value, index| value = sanitize_and_reencode_value(value) array[index] = value end array end |
#sanitize_and_reencode_hash(hash) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/fluent/plugin/scalyr_utils.rb', line 48 def sanitize_and_reencode_hash(hash) hash.each do |key, value| hash[key] = sanitize_and_reencode_value(value) end hash end |
#sanitize_and_reencode_string(value) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/fluent/plugin/scalyr_utils.rb', line 56 def sanitize_and_reencode_string(value) # Function which sanitized the provided string value and tries to re-encode it as UTF-8 # ignoring any encoding error which could arise due to bad or partial unicode sequence begin # rubocop:disable Style/RedundantBegin value.encode("UTF-8", invalid: :replace, undef: :replace, replace: "<?>").force_encoding("UTF-8") # rubocop:disable Layout/LineLength, Lint/RedundantCopDisableDirective rescue # rubocop:disable Style/RescueStandardError "failed-to-reencode-as-utf8" end end |
#sanitize_and_reencode_value(value) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fluent/plugin/scalyr_utils.rb', line 21 def sanitize_and_reencode_value(value) # Method which recursively sanitizes the provided value and tries to re-encode all the strings as # UTF-8 ignoring any bad unicode sequences case value when Hash return sanitize_and_reencode_hash(value) when Array return sanitize_and_reencode_array(value) when String value = sanitize_and_reencode_string(value) return value end # We only need to re-encode strings, for other value types (ints, nils, # etc. no reencoding is needed) value end |