|
6 | 6 | module LogStruct |
7 | 7 | module CodeExamples |
8 | 8 | class ConfigurationTest < ActiveSupport::TestCase |
9 | | - class MockUser < T::Struct |
10 | | - const :id, Integer |
11 | | - const :email, String |
12 | | - end |
13 | | - |
14 | | - class MockRequest < T::Struct |
15 | | - const :remote_ip, String |
16 | | - end |
17 | | - |
18 | | - def test_basic_logging |
19 | | - user = MockUser.new(id: 123, email: "user@example.com") |
20 | | - # ---------------------------------------------------------- |
21 | | - # BEGIN CODE EXAMPLE: basic_logging |
22 | | - # ---------------------------------------------------------- |
23 | | - # Log a simple string |
24 | | - Rails.logger.info "User signed in" |
25 | | - |
26 | | - # Log a hash with custom fields |
27 | | - Rails.logger.info({ |
28 | | - event: "user_login", |
29 | | - user_id: user.id, |
30 | | - ip_address: "192.168.1.1", |
31 | | - custom_field: "any value you want" |
32 | | - }) |
33 | | - # ---------------------------------------------------------- |
34 | | - # END CODE EXAMPLE: basic_logging |
35 | | - # ---------------------------------------------------------- |
36 | | - assert_equal 123, user.id # Stop minitest complaining |
37 | | - end |
38 | | - |
39 | | - def test_getting_started_basic_logging |
40 | | - user = MockUser.new(id: 123, email: "user@example.com") |
41 | | - request = MockRequest.new(remote_ip: "192.168.1.1") |
42 | | - |
43 | | - # Set up tagged logger |
44 | | - Rails.logger = ActiveSupport::TaggedLogging.new(Rails.logger) |
45 | | - |
46 | | - # ---------------------------------------------------------- |
47 | | - # BEGIN CODE EXAMPLE: getting_started_basic_logging |
48 | | - # ---------------------------------------------------------- |
49 | | - # Log a simple message |
50 | | - Rails.logger.info "User signed in" |
51 | | - |
52 | | - # Log structured data |
53 | | - Rails.logger.info({ |
54 | | - src: "rails", |
55 | | - evt: "user_login", |
56 | | - user_id: user.id, |
57 | | - ip_address: request.remote_ip |
58 | | - }) |
59 | | - |
60 | | - # Log with tags |
61 | | - Rails.logger.tagged("Authentication") do |
62 | | - Rails.logger.info "User signed in" |
63 | | - Rails.logger.info(user_id: user.id, ip_address: request.remote_ip) |
64 | | - end |
65 | | - # ---------------------------------------------------------- |
66 | | - # END CODE EXAMPLE: getting_started_basic_logging |
67 | | - # ---------------------------------------------------------- |
68 | | - assert_equal 123, user.id # Stop minitest complaining |
69 | | - end |
70 | | - |
71 | | - def test_typed_logging |
72 | | - # ---------------------------------------------------------- |
73 | | - # BEGIN CODE EXAMPLE: typed_logging |
74 | | - # ---------------------------------------------------------- |
75 | | - # Create a typed log entry |
76 | | - log = LogStruct::Log::Plain.new( |
77 | | - source: LogStruct::Source::App, |
78 | | - message: "User signed in", |
79 | | - additional_data: { |
80 | | - user_id: 123, |
81 | | - ip_address: "192.168.1.1" |
82 | | - } |
83 | | - ) |
84 | | - |
85 | | - # Log the typed struct |
86 | | - LogStruct.info(log) |
87 | | - # ---------------------------------------------------------- |
88 | | - # END CODE EXAMPLE: typed_logging |
89 | | - # ---------------------------------------------------------- |
90 | | - |
91 | | - # Simple assertion to make the test pass |
92 | | - assert_instance_of LogStruct::Log::Plain, log |
93 | | - end |
94 | | - |
95 | 9 | def test_basic_configuration |
96 | 10 | # ---------------------------------------------------------- |
97 | 11 | # BEGIN CODE EXAMPLE: basic_configuration |
@@ -140,12 +54,17 @@ def test_integrations_configuration |
140 | 54 | config.integrations.enable_activestorage = true |
141 | 55 | config.integrations.enable_ahoy = true |
142 | 56 | config.integrations.enable_carrierwave = true |
| 57 | + config.integrations.enable_color_output = true |
| 58 | + config.integrations.enable_dotenv = true |
| 59 | + config.integrations.enable_goodjob = true |
143 | 60 | config.integrations.enable_host_authorization = true |
144 | 61 | config.integrations.enable_lograge = true |
145 | 62 | config.integrations.enable_rack_error_handler = true |
| 63 | + config.integrations.enable_semantic_logger = true |
146 | 64 | config.integrations.enable_shrine = true |
147 | 65 | config.integrations.enable_sidekiq = true |
148 | 66 | config.integrations.enable_sorbet_error_handlers = true |
| 67 | + config.integrations.enable_sql_logging = true |
149 | 68 |
|
150 | 69 | # Configure custom options for Lograge |
151 | 70 | config.integrations.lograge_custom_options = ->(event, _) { |
|
0 commit comments