logstruct 0.2.2 → 0.4.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/CHANGELOG.md +34 -0
- data/lib/log_struct/bounded_input.rb +101 -0
- data/lib/log_struct/concerns/configuration.rb +9 -9
- data/lib/log_struct/concerns/error_handling.rb +10 -0
- data/lib/log_struct/config_struct/filters.rb +24 -13
- data/lib/log_struct/config_struct/limits.rb +1 -1
- data/lib/log_struct/enums/level.rb +1 -1
- data/lib/log_struct/enums/log_field.rb +0 -3
- data/lib/log_struct/formatter.rb +38 -23
- data/lib/log_struct/hash_utils.rb +11 -4
- data/lib/log_struct/integrations/action_mailer/event_logging.rb +1 -0
- data/lib/log_struct/integrations/action_mailer/metadata_collection.rb +1 -0
- data/lib/log_struct/integrations/active_record.rb +1 -1
- data/lib/log_struct/integrations/ahoy.rb +4 -3
- data/lib/log_struct/integrations/carrierwave.rb +4 -6
- data/lib/log_struct/integrations/dotenv.rb +2 -1
- data/lib/log_struct/integrations/good_job.rb +2 -1
- data/lib/log_struct/integrations/host_authorization.rb +3 -6
- data/lib/log_struct/integrations/lograge.rb +23 -32
- data/lib/log_struct/integrations/puma.rb +1 -1
- data/lib/log_struct/integrations/rack_error_handler/error_lines.rb +1 -4
- data/lib/log_struct/integrations/shrine.rb +1 -1
- data/lib/log_struct/log/action_mailer/delivered.rb +19 -7
- data/lib/log_struct/log/action_mailer/delivery.rb +19 -7
- data/lib/log_struct/log/action_mailer/error.rb +19 -7
- data/lib/log_struct/log/action_mailer.rb +1 -0
- data/lib/log_struct/log/active_job/discard.rb +7 -5
- data/lib/log_struct/log/active_job/enqueue.rb +7 -5
- data/lib/log_struct/log/active_job/error.rb +7 -5
- data/lib/log_struct/log/active_job/finish.rb +7 -5
- data/lib/log_struct/log/active_job/retry.rb +7 -5
- data/lib/log_struct/log/active_job/retry_stopped.rb +7 -5
- data/lib/log_struct/log/active_job/schedule.rb +7 -5
- data/lib/log_struct/log/active_job/start.rb +7 -5
- data/lib/log_struct/log/active_job.rb +1 -0
- data/lib/log_struct/log/active_model_serializers.rb +7 -5
- data/lib/log_struct/log/active_storage/delete.rb +7 -5
- data/lib/log_struct/log/active_storage/download.rb +7 -5
- data/lib/log_struct/log/active_storage/exist.rb +7 -5
- data/lib/log_struct/log/active_storage/metadata.rb +7 -5
- data/lib/log_struct/log/active_storage/upload.rb +7 -5
- data/lib/log_struct/log/active_storage/url.rb +7 -5
- data/lib/log_struct/log/active_storage.rb +1 -0
- data/lib/log_struct/log/ahoy.rb +7 -5
- data/lib/log_struct/log/carrierwave/delete.rb +7 -9
- data/lib/log_struct/log/carrierwave/download.rb +7 -11
- data/lib/log_struct/log/carrierwave/upload.rb +7 -11
- data/lib/log_struct/log/carrierwave.rb +3 -8
- data/lib/log_struct/log/dotenv/load.rb +7 -5
- data/lib/log_struct/log/dotenv/restore.rb +7 -5
- data/lib/log_struct/log/dotenv/save.rb +7 -5
- data/lib/log_struct/log/dotenv/update.rb +7 -5
- data/lib/log_struct/log/error.rb +24 -14
- data/lib/log_struct/log/good_job/error.rb +7 -5
- data/lib/log_struct/log/good_job/log.rb +7 -5
- data/lib/log_struct/log/good_job.rb +1 -0
- data/lib/log_struct/log/plain.rb +19 -7
- data/lib/log_struct/log/puma/error.rb +19 -7
- data/lib/log_struct/log/puma/shutdown.rb +19 -7
- data/lib/log_struct/log/puma/start.rb +19 -7
- data/lib/log_struct/log/request.rb +24 -14
- data/lib/log_struct/log/security/blocked_host.rb +24 -14
- data/lib/log_struct/log/security/csrf_violation.rb +24 -14
- data/lib/log_struct/log/security/ip_spoof.rb +24 -14
- data/lib/log_struct/log/security.rb +1 -0
- data/lib/log_struct/log/shrine/delete.rb +7 -5
- data/lib/log_struct/log/shrine/download.rb +7 -5
- data/lib/log_struct/log/shrine/exist.rb +7 -5
- data/lib/log_struct/log/shrine/metadata.rb +7 -5
- data/lib/log_struct/log/shrine/upload.rb +7 -5
- data/lib/log_struct/log/sidekiq/error.rb +19 -7
- data/lib/log_struct/log/sidekiq/log.rb +19 -7
- data/lib/log_struct/log/sql.rb +19 -7
- data/lib/log_struct/monkey_patches/active_support/tagged_logging/formatter.rb +1 -0
- data/lib/log_struct/multi_error_reporter.rb +1 -1
- data/lib/log_struct/param_filters.rb +7 -26
- data/lib/log_struct/params_errors.rb +7 -10
- data/lib/log_struct/rails_boot_banner_silencer.rb +1 -0
- data/lib/log_struct/semantic_logger/concerns/log_methods.rb +1 -0
- data/lib/log_struct/semantic_logger/formatter.rb +1 -1
- data/lib/log_struct/semantic_logger/logger.rb +1 -1
- data/lib/log_struct/semantic_logger/setup.rb +1 -4
- data/lib/log_struct/shared/merge_additional_data_fields.rb +21 -5
- data/lib/log_struct/string_scrubber.rb +1 -1
- data/lib/log_struct/version.rb +1 -1
- data/logstruct.gemspec +1 -1
- metadata +4 -3
|
@@ -10,16 +10,13 @@ module LogStruct
|
|
|
10
10
|
extend T::Sig
|
|
11
11
|
|
|
12
12
|
# Matched by name, so this works without ActionDispatch or Rack loaded
|
|
13
|
-
NAMES =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
].freeze,
|
|
21
|
-
T::Array[String]
|
|
22
|
-
)
|
|
13
|
+
NAMES = [
|
|
14
|
+
"ActionDispatch::Http::Parameters::ParseError",
|
|
15
|
+
"Rack::BadRequest",
|
|
16
|
+
"Rack::QueryParser::InvalidParameterError",
|
|
17
|
+
"Rack::QueryParser::ParameterTypeError",
|
|
18
|
+
"Rack::QueryParser::ParamsTooDeepError"
|
|
19
|
+
].freeze
|
|
23
20
|
# Rails' message for a ParseError
|
|
24
21
|
PARSE_ERROR_MESSAGE = "Error occurred while parsing request parameters"
|
|
25
22
|
PARAMS_ERROR_MESSAGE = "Invalid request parameters"
|
|
@@ -97,7 +97,7 @@ module LogStruct
|
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
# A logged Hash may set its own src and evt, but the line's timestamp and level come from the logger
|
|
100
|
-
HASH_RESERVED_KEYS =
|
|
100
|
+
HASH_RESERVED_KEYS = %w[ts lvl].freeze
|
|
101
101
|
|
|
102
102
|
sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T::Hash[T.untyped, T.untyped]) }
|
|
103
103
|
def without_reserved_keys(hash)
|
|
@@ -26,7 +26,7 @@ module LogStruct
|
|
|
26
26
|
class Logger < ::SemanticLogger::Logger
|
|
27
27
|
extend T::Sig
|
|
28
28
|
|
|
29
|
-
sig { params(name: T.any(String, Symbol,
|
|
29
|
+
sig { params(name: T.any(String, Symbol, T::Module[T.anything]), level: T.nilable(Symbol), filter: T.untyped).void }
|
|
30
30
|
def initialize(name = "Application", level: nil, filter: nil)
|
|
31
31
|
# SemanticLogger::Logger expects positional arguments, not named arguments
|
|
32
32
|
super(name, level, filter)
|
|
@@ -18,10 +18,7 @@ module LogStruct
|
|
|
18
18
|
extend T::Sig
|
|
19
19
|
|
|
20
20
|
# Load hooks for the framework components whose loggers LogStruct replaces
|
|
21
|
-
COMPONENT_LOAD_HOOKS =
|
|
22
|
-
%i[active_record action_controller action_mailer active_job action_view action_cable].freeze,
|
|
23
|
-
T::Array[Symbol]
|
|
24
|
-
)
|
|
21
|
+
COMPONENT_LOAD_HOOKS = %i[active_record action_controller action_mailer active_job action_view action_cable].freeze
|
|
25
22
|
|
|
26
23
|
# The logger LogStruct installed, and the loggers it replaced
|
|
27
24
|
@logger = T.let(nil, T.nilable(LogStruct::SemanticLogger::Logger))
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative "interfaces/additional_data_field"
|
|
5
5
|
require_relative "../enums/source"
|
|
6
|
+
require_relative "../enums/log_field"
|
|
6
7
|
|
|
7
8
|
module LogStruct
|
|
8
9
|
module Log
|
|
@@ -14,17 +15,32 @@ module LogStruct
|
|
|
14
15
|
requires_ancestor { T::Struct }
|
|
15
16
|
requires_ancestor { Interfaces::AdditionalDataField }
|
|
16
17
|
|
|
17
|
-
#
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
# Every line's own fields, and the request ID the formatter adds unless the line has one
|
|
19
|
+
RESERVED_KEYS = T.let(
|
|
20
|
+
[LogField::Source, LogField::Event, LogField::Level, LogField::Timestamp, LogField::RequestId].to_set(&:serialize).freeze,
|
|
21
|
+
T::Set[Symbol]
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
NO_FIELD_KEYS = T.let(Set.new.freeze, T::Set[Symbol])
|
|
25
|
+
|
|
26
|
+
# The keys of every field of the struct's type, set or not on this line, which additional_data can't
|
|
27
|
+
# set: it would replace the field, or stand in for one the type didn't write. LogStruct's log types list
|
|
28
|
+
# theirs. A custom type's serialize writes its own fields after merging additional_data, so they win.
|
|
29
|
+
sig { overridable.returns(T::Set[Symbol]) }
|
|
30
|
+
def field_keys
|
|
31
|
+
NO_FIELD_KEYS
|
|
32
|
+
end
|
|
20
33
|
|
|
21
34
|
sig { params(hash: T::Hash[Symbol, T.untyped]).void }
|
|
22
35
|
def merge_additional_data_fields(hash)
|
|
23
36
|
ad = additional_data
|
|
24
37
|
return unless ad
|
|
25
|
-
ad.
|
|
38
|
+
ad.each_pair.with_index do |(key, value), index|
|
|
39
|
+
break if index >= LogStruct.config.limits.max_hash_keys
|
|
40
|
+
next if key.to_s.bytesize > LogStruct.config.limits.max_string_bytes
|
|
41
|
+
|
|
26
42
|
sym_key = key.to_sym
|
|
27
|
-
if RESERVED_KEYS.include?(sym_key)
|
|
43
|
+
if RESERVED_KEYS.include?(sym_key) || field_keys.include?(sym_key)
|
|
28
44
|
LogStruct.handle_exception(
|
|
29
45
|
ArgumentError.new("additional_data attempted to overwrite reserved key: #{sym_key}"),
|
|
30
46
|
source: Source::Internal
|
|
@@ -36,7 +36,7 @@ module LogStruct
|
|
|
36
36
|
# A URL's query string, for the sensitive params in it
|
|
37
37
|
QUERY_STRING_REGEX = /\?([^\s#"'<>]+)/
|
|
38
38
|
# OAuth authorization codes, which no key pattern would filter
|
|
39
|
-
SENSITIVE_QUERY_PARAMS =
|
|
39
|
+
SENSITIVE_QUERY_PARAMS = ["code"].freeze
|
|
40
40
|
QUERY_PARAM_REPLACEMENT = "[FILTERED]"
|
|
41
41
|
|
|
42
42
|
# Letters and digits of any script (an accented name, a domain in another alphabet)
|
data/lib/log_struct/version.rb
CHANGED
data/logstruct.gemspec
CHANGED
|
@@ -45,7 +45,7 @@ Gem::Specification.new do |spec|
|
|
|
45
45
|
spec.add_dependency "lograge", ">= 0.11"
|
|
46
46
|
spec.add_dependency "railties", ">= 7.1"
|
|
47
47
|
spec.add_dependency "semantic_logger", "~> 4.15"
|
|
48
|
-
spec.add_dependency "sorbet-runtime", ">= 0.
|
|
48
|
+
spec.add_dependency "sorbet-runtime", ">= 0.6.12698"
|
|
49
49
|
|
|
50
50
|
# Optional integrations
|
|
51
51
|
spec.add_development_dependency "bugsnag", "~> 6.26"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: logstruct
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- DocSpring
|
|
@@ -99,14 +99,14 @@ dependencies:
|
|
|
99
99
|
requirements:
|
|
100
100
|
- - ">="
|
|
101
101
|
- !ruby/object:Gem::Version
|
|
102
|
-
version:
|
|
102
|
+
version: 0.6.12698
|
|
103
103
|
type: :runtime
|
|
104
104
|
prerelease: false
|
|
105
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
106
106
|
requirements:
|
|
107
107
|
- - ">="
|
|
108
108
|
- !ruby/object:Gem::Version
|
|
109
|
-
version:
|
|
109
|
+
version: 0.6.12698
|
|
110
110
|
- !ruby/object:Gem::Dependency
|
|
111
111
|
name: bugsnag
|
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -283,6 +283,7 @@ files:
|
|
|
283
283
|
- README.md
|
|
284
284
|
- lib/log_struct.rb
|
|
285
285
|
- lib/log_struct/boot_buffer.rb
|
|
286
|
+
- lib/log_struct/bounded_input.rb
|
|
286
287
|
- lib/log_struct/concerns/configuration.rb
|
|
287
288
|
- lib/log_struct/concerns/error_handling.rb
|
|
288
289
|
- lib/log_struct/concerns/logging.rb
|