logstruct 0.1.2 → 0.1.4
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 +16 -1
- data/README.md +4 -6
- data/lib/log_struct/concerns/configuration.rb +2 -2
- data/lib/log_struct/config_struct/integrations.rb +5 -0
- data/lib/log_struct/enums/log_field.rb +12 -1
- data/lib/log_struct/integrations/action_mailer/error_handling.rb +121 -27
- data/lib/log_struct/integrations/action_mailer/event_logging.rb +30 -14
- data/lib/log_struct/integrations/action_mailer/metadata_collection.rb +18 -24
- data/lib/log_struct/integrations/action_mailer.rb +13 -6
- data/lib/log_struct/integrations/active_job/log_subscriber.rb +2 -2
- data/lib/log_struct/integrations/active_storage.rb +8 -8
- data/lib/log_struct/integrations/ahoy.rb +2 -3
- data/lib/log_struct/integrations/carrierwave.rb +8 -10
- data/lib/log_struct/integrations/good_job/log_subscriber.rb +5 -5
- data/lib/log_struct/integrations/good_job/logger.rb +2 -6
- data/lib/log_struct/integrations/good_job.rb +1 -1
- data/lib/log_struct/integrations/host_authorization.rb +27 -36
- data/lib/log_struct/integrations/lograge.rb +1 -1
- data/lib/log_struct/integrations/rack_error_handler/middleware.rb +54 -16
- data/lib/log_struct/integrations/rack_error_handler.rb +3 -3
- data/lib/log_struct/integrations/shrine.rb +21 -24
- data/lib/log_struct/integrations/sidekiq/logger.rb +8 -1
- data/lib/log_struct/integrations.rb +25 -5
- data/lib/log_struct/log/action_mailer/delivered.rb +14 -49
- data/lib/log_struct/log/action_mailer/delivery.rb +14 -49
- data/lib/log_struct/log/action_mailer/error.rb +72 -0
- data/lib/log_struct/log/action_mailer.rb +15 -2
- data/lib/log_struct/log/active_job/enqueue.rb +9 -73
- data/lib/log_struct/log/active_job/finish.rb +9 -76
- data/lib/log_struct/log/active_job/schedule.rb +9 -73
- data/lib/log_struct/log/active_job/start.rb +9 -76
- data/lib/log_struct/log/active_job.rb +2 -2
- data/lib/log_struct/log/active_model_serializers.rb +5 -45
- data/lib/log_struct/log/active_storage/delete.rb +8 -46
- data/lib/log_struct/log/active_storage/download.rb +9 -55
- data/lib/log_struct/log/active_storage/exist.rb +9 -49
- data/lib/log_struct/log/active_storage/metadata.rb +9 -49
- data/lib/log_struct/log/active_storage/stream.rb +9 -49
- data/lib/log_struct/log/active_storage/upload.rb +9 -64
- data/lib/log_struct/log/active_storage/url.rb +9 -49
- data/lib/log_struct/log/active_storage.rb +2 -2
- data/lib/log_struct/log/ahoy.rb +5 -43
- data/lib/log_struct/log/carrierwave/delete.rb +15 -69
- data/lib/log_struct/log/carrierwave/download.rb +15 -77
- data/lib/log_struct/log/carrierwave/upload.rb +15 -83
- data/lib/log_struct/log/carrierwave.rb +13 -4
- data/lib/log_struct/log/dotenv/load.rb +5 -33
- data/lib/log_struct/log/dotenv/restore.rb +5 -33
- data/lib/log_struct/log/dotenv/save.rb +5 -33
- data/lib/log_struct/log/dotenv/update.rb +5 -33
- data/lib/log_struct/log/error.rb +7 -40
- data/lib/log_struct/log/good_job/enqueue.rb +9 -72
- data/lib/log_struct/log/good_job/error.rb +9 -89
- data/lib/log_struct/log/good_job/finish.rb +9 -78
- data/lib/log_struct/log/good_job/log.rb +11 -75
- data/lib/log_struct/log/good_job/schedule.rb +7 -78
- data/lib/log_struct/log/good_job/start.rb +7 -78
- data/lib/log_struct/log/good_job.rb +2 -2
- data/lib/log_struct/log/plain.rb +5 -32
- data/lib/log_struct/log/puma/shutdown.rb +5 -32
- data/lib/log_struct/log/puma/start.rb +5 -56
- data/lib/log_struct/log/request.rb +7 -90
- data/lib/log_struct/log/security/blocked_host.rb +12 -73
- data/lib/log_struct/log/security/csrf_violation.rb +6 -67
- data/lib/log_struct/log/security/ip_spoof.rb +6 -73
- data/lib/log_struct/log/shrine/delete.rb +6 -41
- data/lib/log_struct/log/shrine/download.rb +6 -44
- data/lib/log_struct/log/shrine/exist.rb +6 -44
- data/lib/log_struct/log/shrine/metadata.rb +8 -46
- data/lib/log_struct/log/shrine/upload.rb +6 -53
- data/lib/log_struct/log/sidekiq.rb +5 -42
- data/lib/log_struct/log/sql.rb +5 -65
- data/lib/log_struct/log.rb +2 -2
- data/lib/log_struct/monkey_patches/active_support/tagged_logging/formatter.rb +12 -1
- data/lib/log_struct/railtie.rb +11 -24
- data/lib/log_struct/semantic_logger/concerns/log_methods.rb +100 -0
- data/lib/log_struct/semantic_logger/logger.rb +46 -15
- data/lib/log_struct/semantic_logger/setup.rb +11 -7
- data/lib/log_struct/shared/{shared/add_request_fields.rb → add_request_fields.rb} +2 -2
- data/lib/log_struct/shared/{shared/merge_additional_data_fields.rb → merge_additional_data_fields.rb} +1 -1
- data/lib/log_struct/shared/{shared/serialize_common.rb → serialize_common.rb} +9 -3
- data/lib/log_struct/{log/shared → shared}/serialize_common_public.rb +2 -2
- data/lib/log_struct/version.rb +1 -1
- data/lib/log_struct.rb +4 -1
- data/logstruct.gemspec +1 -1
- metadata +9 -11
- data/lib/log_struct/integrations/action_mailer/callbacks.rb +0 -100
- data/lib/log_struct/log/shared/add_request_fields.rb +0 -4
- data/lib/log_struct/log/shared/merge_additional_data_fields.rb +0 -4
- data/lib/log_struct/log/shared/serialize_common.rb +0 -4
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
require "log_struct/shared/interfaces/common_fields"
|
|
10
10
|
require "log_struct/shared/interfaces/additional_data_field"
|
|
11
11
|
require "log_struct/shared/interfaces/request_fields"
|
|
12
|
-
require "log_struct/shared/
|
|
13
|
-
require "log_struct/shared/
|
|
14
|
-
require "log_struct/shared/
|
|
12
|
+
require "log_struct/shared/serialize_common"
|
|
13
|
+
require "log_struct/shared/merge_additional_data_fields"
|
|
14
|
+
require "log_struct/shared/add_request_fields"
|
|
15
15
|
require_relative "../../enums/source"
|
|
16
16
|
require_relative "../../enums/event"
|
|
17
17
|
require_relative "../../enums/level"
|
|
@@ -21,11 +21,6 @@ module LogStruct
|
|
|
21
21
|
module Log
|
|
22
22
|
class Shrine
|
|
23
23
|
class Download < T::Struct
|
|
24
|
-
# typed: strict
|
|
25
|
-
# frozen_string_literal: true
|
|
26
|
-
|
|
27
|
-
extend T::Sig
|
|
28
|
-
|
|
29
24
|
extend T::Sig
|
|
30
25
|
|
|
31
26
|
# Shared/common fields
|
|
@@ -35,55 +30,22 @@ module LogStruct
|
|
|
35
30
|
const :level, Level, default: Level::Info
|
|
36
31
|
|
|
37
32
|
# Event-specific fields
|
|
38
|
-
const :storage,
|
|
33
|
+
const :storage, Symbol
|
|
39
34
|
const :location, String
|
|
40
35
|
const :download_options, T.nilable(T::Hash[Symbol, T.untyped]), default: nil
|
|
41
36
|
|
|
42
|
-
# Additional data
|
|
43
|
-
include LogStruct::Log::Interfaces::AdditionalDataField
|
|
44
|
-
const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil
|
|
45
|
-
include LogStruct::Log::Shared::MergeAdditionalDataFields
|
|
46
|
-
|
|
47
|
-
# Request fields (optional)
|
|
48
|
-
|
|
49
37
|
# Serialize shared fields
|
|
50
38
|
include LogStruct::Log::Interfaces::CommonFields
|
|
51
39
|
include LogStruct::Log::Shared::SerializeCommon
|
|
52
40
|
|
|
53
41
|
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
|
54
|
-
def
|
|
55
|
-
{}
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
sig {
|
|
59
|
-
params(storage: T.untyped,
|
|
60
|
-
location: T.untyped,
|
|
61
|
-
download_options: T.untyped,
|
|
62
|
-
additional_data: T.untyped,
|
|
63
|
-
timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
|
64
|
-
}
|
|
65
|
-
def self.build(storage:,
|
|
66
|
-
location:,
|
|
67
|
-
download_options: nil,
|
|
68
|
-
additional_data: nil,
|
|
69
|
-
timestamp: Time.now)
|
|
70
|
-
h = base_hash
|
|
42
|
+
def to_h
|
|
43
|
+
h = T.let({}, T::Hash[LogStruct::LogField, T.untyped])
|
|
71
44
|
h[LogField::Storage] = storage
|
|
72
45
|
h[LogField::Location] = location
|
|
73
46
|
h[LogField::DownloadOptions] = download_options unless download_options.nil?
|
|
74
47
|
h
|
|
75
48
|
end
|
|
76
|
-
|
|
77
|
-
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
|
78
|
-
def to_h
|
|
79
|
-
self.class.build(
|
|
80
|
-
storage: storage,
|
|
81
|
-
location: location,
|
|
82
|
-
download_options: download_options,
|
|
83
|
-
additional_data: additional_data,
|
|
84
|
-
timestamp: timestamp
|
|
85
|
-
)
|
|
86
|
-
end
|
|
87
49
|
end
|
|
88
50
|
end
|
|
89
51
|
end
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
require "log_struct/shared/interfaces/common_fields"
|
|
10
10
|
require "log_struct/shared/interfaces/additional_data_field"
|
|
11
11
|
require "log_struct/shared/interfaces/request_fields"
|
|
12
|
-
require "log_struct/shared/
|
|
13
|
-
require "log_struct/shared/
|
|
14
|
-
require "log_struct/shared/
|
|
12
|
+
require "log_struct/shared/serialize_common"
|
|
13
|
+
require "log_struct/shared/merge_additional_data_fields"
|
|
14
|
+
require "log_struct/shared/add_request_fields"
|
|
15
15
|
require_relative "../../enums/source"
|
|
16
16
|
require_relative "../../enums/event"
|
|
17
17
|
require_relative "../../enums/level"
|
|
@@ -21,11 +21,6 @@ module LogStruct
|
|
|
21
21
|
module Log
|
|
22
22
|
class Shrine
|
|
23
23
|
class Exist < T::Struct
|
|
24
|
-
# typed: strict
|
|
25
|
-
# frozen_string_literal: true
|
|
26
|
-
|
|
27
|
-
extend T::Sig
|
|
28
|
-
|
|
29
24
|
extend T::Sig
|
|
30
25
|
|
|
31
26
|
# Shared/common fields
|
|
@@ -35,55 +30,22 @@ module LogStruct
|
|
|
35
30
|
const :level, Level, default: Level::Info
|
|
36
31
|
|
|
37
32
|
# Event-specific fields
|
|
38
|
-
const :storage,
|
|
33
|
+
const :storage, Symbol
|
|
39
34
|
const :location, String
|
|
40
35
|
const :exist, T.nilable(T::Boolean), default: nil
|
|
41
36
|
|
|
42
|
-
# Additional data
|
|
43
|
-
include LogStruct::Log::Interfaces::AdditionalDataField
|
|
44
|
-
const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil
|
|
45
|
-
include LogStruct::Log::Shared::MergeAdditionalDataFields
|
|
46
|
-
|
|
47
|
-
# Request fields (optional)
|
|
48
|
-
|
|
49
37
|
# Serialize shared fields
|
|
50
38
|
include LogStruct::Log::Interfaces::CommonFields
|
|
51
39
|
include LogStruct::Log::Shared::SerializeCommon
|
|
52
40
|
|
|
53
41
|
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
|
54
|
-
def
|
|
55
|
-
{}
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
sig {
|
|
59
|
-
params(storage: T.untyped,
|
|
60
|
-
location: T.untyped,
|
|
61
|
-
exist: T.untyped,
|
|
62
|
-
additional_data: T.untyped,
|
|
63
|
-
timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
|
64
|
-
}
|
|
65
|
-
def self.build(storage:,
|
|
66
|
-
location:,
|
|
67
|
-
exist: nil,
|
|
68
|
-
additional_data: nil,
|
|
69
|
-
timestamp: Time.now)
|
|
70
|
-
h = base_hash
|
|
42
|
+
def to_h
|
|
43
|
+
h = T.let({}, T::Hash[LogStruct::LogField, T.untyped])
|
|
71
44
|
h[LogField::Storage] = storage
|
|
72
45
|
h[LogField::Location] = location
|
|
73
46
|
h[LogField::Exist] = exist unless exist.nil?
|
|
74
47
|
h
|
|
75
48
|
end
|
|
76
|
-
|
|
77
|
-
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
|
78
|
-
def to_h
|
|
79
|
-
self.class.build(
|
|
80
|
-
storage: storage,
|
|
81
|
-
location: location,
|
|
82
|
-
exist: exist,
|
|
83
|
-
additional_data: additional_data,
|
|
84
|
-
timestamp: timestamp
|
|
85
|
-
)
|
|
86
|
-
end
|
|
87
49
|
end
|
|
88
50
|
end
|
|
89
51
|
end
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
require "log_struct/shared/interfaces/common_fields"
|
|
10
10
|
require "log_struct/shared/interfaces/additional_data_field"
|
|
11
11
|
require "log_struct/shared/interfaces/request_fields"
|
|
12
|
-
require "log_struct/shared/
|
|
13
|
-
require "log_struct/shared/
|
|
14
|
-
require "log_struct/shared/
|
|
12
|
+
require "log_struct/shared/serialize_common"
|
|
13
|
+
require "log_struct/shared/merge_additional_data_fields"
|
|
14
|
+
require "log_struct/shared/add_request_fields"
|
|
15
15
|
require_relative "../../enums/source"
|
|
16
16
|
require_relative "../../enums/event"
|
|
17
17
|
require_relative "../../enums/level"
|
|
@@ -21,11 +21,6 @@ module LogStruct
|
|
|
21
21
|
module Log
|
|
22
22
|
class Shrine
|
|
23
23
|
class Metadata < T::Struct
|
|
24
|
-
# typed: strict
|
|
25
|
-
# frozen_string_literal: true
|
|
26
|
-
|
|
27
|
-
extend T::Sig
|
|
28
|
-
|
|
29
24
|
extend T::Sig
|
|
30
25
|
|
|
31
26
|
# Shared/common fields
|
|
@@ -35,55 +30,22 @@ module LogStruct
|
|
|
35
30
|
const :level, Level, default: Level::Info
|
|
36
31
|
|
|
37
32
|
# Event-specific fields
|
|
38
|
-
const :storage,
|
|
39
|
-
const :location, String
|
|
33
|
+
const :storage, Symbol
|
|
34
|
+
const :location, T.nilable(String), default: nil
|
|
40
35
|
const :metadata, T.nilable(T::Hash[String, T.untyped]), default: nil
|
|
41
36
|
|
|
42
|
-
# Additional data
|
|
43
|
-
include LogStruct::Log::Interfaces::AdditionalDataField
|
|
44
|
-
const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil
|
|
45
|
-
include LogStruct::Log::Shared::MergeAdditionalDataFields
|
|
46
|
-
|
|
47
|
-
# Request fields (optional)
|
|
48
|
-
|
|
49
37
|
# Serialize shared fields
|
|
50
38
|
include LogStruct::Log::Interfaces::CommonFields
|
|
51
39
|
include LogStruct::Log::Shared::SerializeCommon
|
|
52
40
|
|
|
53
41
|
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
|
54
|
-
def
|
|
55
|
-
{}
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
sig {
|
|
59
|
-
params(storage: T.untyped,
|
|
60
|
-
location: T.untyped,
|
|
61
|
-
metadata: T.untyped,
|
|
62
|
-
additional_data: T.untyped,
|
|
63
|
-
timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
|
64
|
-
}
|
|
65
|
-
def self.build(storage:,
|
|
66
|
-
location:,
|
|
67
|
-
metadata: nil,
|
|
68
|
-
additional_data: nil,
|
|
69
|
-
timestamp: Time.now)
|
|
70
|
-
h = base_hash
|
|
42
|
+
def to_h
|
|
43
|
+
h = T.let({}, T::Hash[LogStruct::LogField, T.untyped])
|
|
71
44
|
h[LogField::Storage] = storage
|
|
72
|
-
h[LogField::Location] = location
|
|
45
|
+
h[LogField::Location] = location unless location.nil?
|
|
73
46
|
h[LogField::Metadata] = metadata unless metadata.nil?
|
|
74
47
|
h
|
|
75
48
|
end
|
|
76
|
-
|
|
77
|
-
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
|
78
|
-
def to_h
|
|
79
|
-
self.class.build(
|
|
80
|
-
storage: storage,
|
|
81
|
-
location: location,
|
|
82
|
-
metadata: metadata,
|
|
83
|
-
additional_data: additional_data,
|
|
84
|
-
timestamp: timestamp
|
|
85
|
-
)
|
|
86
|
-
end
|
|
87
49
|
end
|
|
88
50
|
end
|
|
89
51
|
end
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
require "log_struct/shared/interfaces/common_fields"
|
|
10
10
|
require "log_struct/shared/interfaces/additional_data_field"
|
|
11
11
|
require "log_struct/shared/interfaces/request_fields"
|
|
12
|
-
require "log_struct/shared/
|
|
13
|
-
require "log_struct/shared/
|
|
14
|
-
require "log_struct/shared/
|
|
12
|
+
require "log_struct/shared/serialize_common"
|
|
13
|
+
require "log_struct/shared/merge_additional_data_fields"
|
|
14
|
+
require "log_struct/shared/add_request_fields"
|
|
15
15
|
require_relative "../../enums/source"
|
|
16
16
|
require_relative "../../enums/event"
|
|
17
17
|
require_relative "../../enums/level"
|
|
@@ -21,11 +21,6 @@ module LogStruct
|
|
|
21
21
|
module Log
|
|
22
22
|
class Shrine
|
|
23
23
|
class Upload < T::Struct
|
|
24
|
-
# typed: strict
|
|
25
|
-
# frozen_string_literal: true
|
|
26
|
-
|
|
27
|
-
extend T::Sig
|
|
28
|
-
|
|
29
24
|
extend T::Sig
|
|
30
25
|
|
|
31
26
|
# Shared/common fields
|
|
@@ -35,48 +30,20 @@ module LogStruct
|
|
|
35
30
|
const :level, Level, default: Level::Info
|
|
36
31
|
|
|
37
32
|
# Event-specific fields
|
|
38
|
-
const :storage,
|
|
33
|
+
const :storage, Symbol
|
|
39
34
|
const :location, String
|
|
40
35
|
const :upload_options, T.nilable(T::Hash[Symbol, T.untyped]), default: nil
|
|
41
36
|
const :options, T.nilable(T::Hash[Symbol, T.untyped]), default: nil
|
|
42
37
|
const :uploader, T.nilable(String), default: nil
|
|
43
38
|
const :duration_ms, T.nilable(Float), default: nil
|
|
44
39
|
|
|
45
|
-
# Additional data
|
|
46
|
-
include LogStruct::Log::Interfaces::AdditionalDataField
|
|
47
|
-
const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil
|
|
48
|
-
include LogStruct::Log::Shared::MergeAdditionalDataFields
|
|
49
|
-
|
|
50
|
-
# Request fields (optional)
|
|
51
|
-
|
|
52
40
|
# Serialize shared fields
|
|
53
41
|
include LogStruct::Log::Interfaces::CommonFields
|
|
54
42
|
include LogStruct::Log::Shared::SerializeCommon
|
|
55
43
|
|
|
56
44
|
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
|
57
|
-
def
|
|
58
|
-
{}
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
sig {
|
|
62
|
-
params(storage: T.untyped,
|
|
63
|
-
location: T.untyped,
|
|
64
|
-
upload_options: T.untyped,
|
|
65
|
-
options: T.untyped,
|
|
66
|
-
uploader: T.untyped,
|
|
67
|
-
duration_ms: T.untyped,
|
|
68
|
-
additional_data: T.untyped,
|
|
69
|
-
timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
|
70
|
-
}
|
|
71
|
-
def self.build(storage:,
|
|
72
|
-
location:,
|
|
73
|
-
upload_options: nil,
|
|
74
|
-
options: nil,
|
|
75
|
-
uploader: nil,
|
|
76
|
-
duration_ms: nil,
|
|
77
|
-
additional_data: nil,
|
|
78
|
-
timestamp: Time.now)
|
|
79
|
-
h = base_hash
|
|
45
|
+
def to_h
|
|
46
|
+
h = T.let({}, T::Hash[LogStruct::LogField, T.untyped])
|
|
80
47
|
h[LogField::Storage] = storage
|
|
81
48
|
h[LogField::Location] = location
|
|
82
49
|
h[LogField::UploadOptions] = upload_options unless upload_options.nil?
|
|
@@ -85,20 +52,6 @@ module LogStruct
|
|
|
85
52
|
h[LogField::DurationMs] = duration_ms unless duration_ms.nil?
|
|
86
53
|
h
|
|
87
54
|
end
|
|
88
|
-
|
|
89
|
-
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
|
90
|
-
def to_h
|
|
91
|
-
self.class.build(
|
|
92
|
-
storage: storage,
|
|
93
|
-
location: location,
|
|
94
|
-
upload_options: upload_options,
|
|
95
|
-
options: options,
|
|
96
|
-
uploader: uploader,
|
|
97
|
-
duration_ms: duration_ms,
|
|
98
|
-
additional_data: additional_data,
|
|
99
|
-
timestamp: timestamp
|
|
100
|
-
)
|
|
101
|
-
end
|
|
102
55
|
end
|
|
103
56
|
end
|
|
104
57
|
end
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
require "log_struct/shared/interfaces/common_fields"
|
|
10
10
|
require "log_struct/shared/interfaces/additional_data_field"
|
|
11
11
|
require "log_struct/shared/interfaces/request_fields"
|
|
12
|
-
require "log_struct/shared/
|
|
13
|
-
require "log_struct/shared/
|
|
14
|
-
require "log_struct/shared/
|
|
12
|
+
require "log_struct/shared/serialize_common"
|
|
13
|
+
require "log_struct/shared/merge_additional_data_fields"
|
|
14
|
+
require "log_struct/shared/add_request_fields"
|
|
15
15
|
require_relative "../enums/source"
|
|
16
16
|
require_relative "../enums/event"
|
|
17
17
|
require_relative "../enums/level"
|
|
@@ -20,11 +20,6 @@ require_relative "../enums/log_field"
|
|
|
20
20
|
module LogStruct
|
|
21
21
|
module Log
|
|
22
22
|
class Sidekiq < T::Struct
|
|
23
|
-
# typed: strict
|
|
24
|
-
# frozen_string_literal: true
|
|
25
|
-
|
|
26
|
-
extend T::Sig
|
|
27
|
-
|
|
28
23
|
extend T::Sig
|
|
29
24
|
|
|
30
25
|
# Shared/common fields
|
|
@@ -39,51 +34,19 @@ module LogStruct
|
|
|
39
34
|
const :process_id, T.nilable(Integer), default: nil
|
|
40
35
|
const :thread_id, T.nilable(T.any(Integer, String)), default: nil
|
|
41
36
|
|
|
42
|
-
# Additional data
|
|
43
|
-
|
|
44
|
-
# Request fields (optional)
|
|
45
|
-
|
|
46
37
|
# Serialize shared fields
|
|
47
38
|
include LogStruct::Log::Interfaces::CommonFields
|
|
48
39
|
include LogStruct::Log::Shared::SerializeCommon
|
|
49
40
|
|
|
50
41
|
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
|
51
|
-
def
|
|
52
|
-
{}
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
sig {
|
|
56
|
-
params(message: T.untyped,
|
|
57
|
-
context: T.untyped,
|
|
58
|
-
process_id: T.untyped,
|
|
59
|
-
thread_id: T.untyped,
|
|
60
|
-
additional_data: T.untyped,
|
|
61
|
-
timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
|
62
|
-
}
|
|
63
|
-
def self.build(message: nil,
|
|
64
|
-
context: nil,
|
|
65
|
-
process_id: nil,
|
|
66
|
-
thread_id: nil,
|
|
67
|
-
additional_data: nil,
|
|
68
|
-
timestamp: Time.now)
|
|
69
|
-
h = base_hash
|
|
42
|
+
def to_h
|
|
43
|
+
h = T.let({}, T::Hash[LogStruct::LogField, T.untyped])
|
|
70
44
|
h[LogField::Message] = message unless message.nil?
|
|
71
45
|
h[LogField::Context] = context unless context.nil?
|
|
72
46
|
h[LogField::ProcessId] = process_id unless process_id.nil?
|
|
73
47
|
h[LogField::ThreadId] = thread_id unless thread_id.nil?
|
|
74
48
|
h
|
|
75
49
|
end
|
|
76
|
-
|
|
77
|
-
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
|
78
|
-
def to_h
|
|
79
|
-
self.class.build(
|
|
80
|
-
message: message,
|
|
81
|
-
context: context,
|
|
82
|
-
process_id: process_id,
|
|
83
|
-
thread_id: thread_id,
|
|
84
|
-
timestamp: timestamp
|
|
85
|
-
)
|
|
86
|
-
end
|
|
87
50
|
end
|
|
88
51
|
end
|
|
89
52
|
end
|
data/lib/log_struct/log/sql.rb
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
require "log_struct/shared/interfaces/common_fields"
|
|
10
10
|
require "log_struct/shared/interfaces/additional_data_field"
|
|
11
11
|
require "log_struct/shared/interfaces/request_fields"
|
|
12
|
-
require "log_struct/shared/
|
|
13
|
-
require "log_struct/shared/
|
|
14
|
-
require "log_struct/shared/
|
|
12
|
+
require "log_struct/shared/serialize_common"
|
|
13
|
+
require "log_struct/shared/merge_additional_data_fields"
|
|
14
|
+
require "log_struct/shared/add_request_fields"
|
|
15
15
|
require_relative "../enums/source"
|
|
16
16
|
require_relative "../enums/event"
|
|
17
17
|
require_relative "../enums/level"
|
|
@@ -20,11 +20,6 @@ require_relative "../enums/log_field"
|
|
|
20
20
|
module LogStruct
|
|
21
21
|
module Log
|
|
22
22
|
class SQL < T::Struct
|
|
23
|
-
# typed: strict
|
|
24
|
-
# frozen_string_literal: true
|
|
25
|
-
|
|
26
|
-
extend T::Sig
|
|
27
|
-
|
|
28
23
|
extend T::Sig
|
|
29
24
|
|
|
30
25
|
# Shared/common fields
|
|
@@ -52,48 +47,13 @@ module LogStruct
|
|
|
52
47
|
const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil
|
|
53
48
|
include LogStruct::Log::Shared::MergeAdditionalDataFields
|
|
54
49
|
|
|
55
|
-
# Request fields (optional)
|
|
56
|
-
|
|
57
50
|
# Serialize shared fields
|
|
58
51
|
include LogStruct::Log::Interfaces::CommonFields
|
|
59
52
|
include LogStruct::Log::Shared::SerializeCommon
|
|
60
53
|
|
|
61
54
|
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
|
62
|
-
def
|
|
63
|
-
{}
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
sig {
|
|
67
|
-
params(message: T.untyped,
|
|
68
|
-
sql: T.untyped,
|
|
69
|
-
name: T.untyped,
|
|
70
|
-
duration_ms: T.untyped,
|
|
71
|
-
row_count: T.untyped,
|
|
72
|
-
adapter: T.untyped,
|
|
73
|
-
bind_params: T.untyped,
|
|
74
|
-
database_name: T.untyped,
|
|
75
|
-
connection_pool_size: T.untyped,
|
|
76
|
-
active_connections: T.untyped,
|
|
77
|
-
operation_type: T.untyped,
|
|
78
|
-
table_names: T.untyped,
|
|
79
|
-
additional_data: T.untyped,
|
|
80
|
-
timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
|
81
|
-
}
|
|
82
|
-
def self.build(message:,
|
|
83
|
-
sql:,
|
|
84
|
-
name:,
|
|
85
|
-
duration_ms:,
|
|
86
|
-
row_count: nil,
|
|
87
|
-
adapter: nil,
|
|
88
|
-
bind_params: nil,
|
|
89
|
-
database_name: nil,
|
|
90
|
-
connection_pool_size: nil,
|
|
91
|
-
active_connections: nil,
|
|
92
|
-
operation_type: nil,
|
|
93
|
-
table_names: nil,
|
|
94
|
-
additional_data: nil,
|
|
95
|
-
timestamp: Time.now)
|
|
96
|
-
h = base_hash
|
|
55
|
+
def to_h
|
|
56
|
+
h = T.let({}, T::Hash[LogStruct::LogField, T.untyped])
|
|
97
57
|
h[LogField::Message] = message
|
|
98
58
|
h[LogField::Sql] = sql
|
|
99
59
|
h[LogField::Name] = name
|
|
@@ -108,26 +68,6 @@ module LogStruct
|
|
|
108
68
|
h[LogField::TableNames] = table_names unless table_names.nil?
|
|
109
69
|
h
|
|
110
70
|
end
|
|
111
|
-
|
|
112
|
-
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
|
113
|
-
def to_h
|
|
114
|
-
self.class.build(
|
|
115
|
-
message: message,
|
|
116
|
-
sql: sql,
|
|
117
|
-
name: name,
|
|
118
|
-
duration_ms: duration_ms,
|
|
119
|
-
row_count: row_count,
|
|
120
|
-
adapter: adapter,
|
|
121
|
-
bind_params: bind_params,
|
|
122
|
-
database_name: database_name,
|
|
123
|
-
connection_pool_size: connection_pool_size,
|
|
124
|
-
active_connections: active_connections,
|
|
125
|
-
operation_type: operation_type,
|
|
126
|
-
table_names: table_names,
|
|
127
|
-
additional_data: additional_data,
|
|
128
|
-
timestamp: timestamp
|
|
129
|
-
)
|
|
130
|
-
end
|
|
131
71
|
end
|
|
132
72
|
end
|
|
133
73
|
end
|
data/lib/log_struct/log.rb
CHANGED
|
@@ -7,7 +7,7 @@ require_relative "enums/event"
|
|
|
7
7
|
require_relative "enums/level"
|
|
8
8
|
require_relative "enums/log_field"
|
|
9
9
|
require_relative "log/interfaces/public_common_fields"
|
|
10
|
-
require_relative "
|
|
10
|
+
require_relative "shared/serialize_common_public"
|
|
11
11
|
|
|
12
12
|
# Dynamically require all top-level log structs under log/*
|
|
13
13
|
# Nested per-event files are required by their parent files.
|
|
@@ -31,7 +31,7 @@ module LogStruct
|
|
|
31
31
|
def self.from_exception(source, ex, additional_data = {}, timestamp = Time.now)
|
|
32
32
|
LogStruct::Log::Error.new(
|
|
33
33
|
source: source,
|
|
34
|
-
|
|
34
|
+
error_class: ex.class,
|
|
35
35
|
message: ex.message,
|
|
36
36
|
backtrace: ex.backtrace,
|
|
37
37
|
additional_data: additional_data,
|
|
@@ -8,6 +8,16 @@ require "active_support/tagged_logging"
|
|
|
8
8
|
# directly into the hash instead of being prepended as strings
|
|
9
9
|
module ActiveSupport
|
|
10
10
|
module TaggedLogging
|
|
11
|
+
extend T::Sig
|
|
12
|
+
|
|
13
|
+
# Add class-level current_tags method for compatibility with Rails code
|
|
14
|
+
# that expects to call ActiveSupport::TaggedLogging.current_tags
|
|
15
|
+
# Use thread-local storage directly like Rails does internally
|
|
16
|
+
sig { returns(T::Array[T.any(String, Symbol)]) }
|
|
17
|
+
def self.current_tags
|
|
18
|
+
Thread.current[:activesupport_tagged_logging_tags] || []
|
|
19
|
+
end
|
|
20
|
+
|
|
11
21
|
module FormatterExtension
|
|
12
22
|
extend T::Sig
|
|
13
23
|
extend T::Helpers
|
|
@@ -23,7 +33,8 @@ module ActiveSupport
|
|
|
23
33
|
data = {message: data.to_s} unless data.is_a?(Hash)
|
|
24
34
|
|
|
25
35
|
# Add current tags to the hash if present
|
|
26
|
-
|
|
36
|
+
# Use thread-local storage directly as fallback if current_tags method doesn't exist
|
|
37
|
+
tags = T.unsafe(self).respond_to?(:current_tags) ? current_tags : (Thread.current[:activesupport_tagged_logging_tags] || [])
|
|
27
38
|
data[:tags] = tags if tags.present?
|
|
28
39
|
|
|
29
40
|
# Call the original formatter with our enhanced data
|
data/lib/log_struct/railtie.rb
CHANGED
|
@@ -10,32 +10,10 @@ require_relative "integrations"
|
|
|
10
10
|
module LogStruct
|
|
11
11
|
# Railtie to integrate with Rails
|
|
12
12
|
class Railtie < ::Rails::Railtie
|
|
13
|
-
# Ensure test hosts are allowed early enough for middleware build
|
|
14
|
-
initializer "logstruct.allow_test_hosts", before: :build_middleware_stack do |app|
|
|
15
|
-
if ::Rails.env.test? && app.config.respond_to?(:hosts)
|
|
16
|
-
begin
|
|
17
|
-
app.config.hosts << /.*\z/
|
|
18
|
-
rescue
|
|
19
|
-
# best-effort
|
|
20
|
-
end
|
|
21
|
-
begin
|
|
22
|
-
app.config.middleware.delete(::ActionDispatch::HostAuthorization)
|
|
23
|
-
rescue
|
|
24
|
-
# best-effort
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# After ActionDispatch is configured, remove HostAuthorization in test to prevent 403s
|
|
30
|
-
# (No late deletion needed; handled above before middleware stack is built)
|
|
31
|
-
|
|
32
13
|
# Configure early, right after logger initialization
|
|
33
14
|
initializer "logstruct.configure_logger", after: :initialize_logger do |app|
|
|
34
15
|
next unless LogStruct.enabled?
|
|
35
16
|
|
|
36
|
-
# Apply TaggedLogging monkey patch only when enabled
|
|
37
|
-
require_relative "monkey_patches/active_support/tagged_logging/formatter"
|
|
38
|
-
|
|
39
17
|
# Use SemanticLogger for powerful logging features
|
|
40
18
|
LogStruct::SemanticLogger::Setup.configure_semantic_logger(app)
|
|
41
19
|
end
|
|
@@ -47,12 +25,21 @@ module LogStruct
|
|
|
47
25
|
# Merge Rails filter parameters into our filters
|
|
48
26
|
LogStruct.merge_rails_filter_parameters!
|
|
49
27
|
|
|
50
|
-
# Set up
|
|
51
|
-
Integrations.setup_integrations
|
|
28
|
+
# Set up non-middleware integrations first
|
|
29
|
+
Integrations.setup_integrations(stage: :non_middleware)
|
|
52
30
|
|
|
53
31
|
# Note: Host allowances are managed by the test app itself.
|
|
54
32
|
end
|
|
55
33
|
|
|
34
|
+
# Setup middleware integrations during Rails configuration (before middleware stack is built)
|
|
35
|
+
# Must be done in the Railtie class body, not in an initializer
|
|
36
|
+
initializer "logstruct.configure_middleware", before: :build_middleware_stack do |app|
|
|
37
|
+
# This runs before middleware stack is frozen, so we can configure it
|
|
38
|
+
next unless LogStruct.enabled?
|
|
39
|
+
|
|
40
|
+
Integrations.setup_integrations(stage: :middleware)
|
|
41
|
+
end
|
|
42
|
+
|
|
56
43
|
# Emit Puma lifecycle logs when running `rails server`
|
|
57
44
|
initializer "logstruct.puma_lifecycle", after: "logstruct.configure_logger" do
|
|
58
45
|
is_server = ::LogStruct.server_mode?
|