@@ -220,5 +220,56 @@ class SemanticLoggerTest < ActiveSupport::TestCase
220220 ::SemanticLogger . flush # Flush to ensure output is written
221221 end
222222 end
223+
224+ test "FormatterProxy responds to call method for Logger compatibility" do
225+ formatter = LogStruct ::SemanticLogger ::FormatterProxy . new
226+
227+ # FormatterProxy must implement the standard Logger formatter interface
228+ assert_respond_to formatter , :call
229+ assert_respond_to formatter , :current_tags
230+
231+ # call method should accept standard Logger formatter arguments
232+ time = Time . now
233+ result = formatter . call ( "INFO" , time , "TestProgram" , "Test message" )
234+
235+ # Should return a string
236+ assert_kind_of String , result
237+ assert_includes result , "Test message"
238+ end
239+
240+ test "FormatterProxy works with standard Ruby Logger" do
241+ # This test ensures FormatterProxy can be used as a formatter for Ruby's Logger
242+ # which is important for Rails/ActiveSupport compatibility (logger 1.7.0+)
243+ io = StringIO . new
244+ stdlib_logger = ::Logger . new ( io )
245+
246+ # Assign FormatterProxy as the formatter (simulates what Rails might do)
247+ stdlib_logger . formatter = LogStruct ::SemanticLogger ::FormatterProxy . new
248+
249+ # Should not raise an error when logging
250+ assert_nothing_raised do
251+ stdlib_logger . info ( "Test message from stdlib logger" )
252+ end
253+
254+ # Output should contain the message
255+ output = io . string
256+
257+ assert_includes output , "Test message from stdlib logger"
258+ end
259+
260+ test "FormatterProxy call method handles nil and empty messages" do
261+ formatter = LogStruct ::SemanticLogger ::FormatterProxy . new
262+ time = Time . now
263+
264+ # Should handle nil message
265+ result = formatter . call ( "INFO" , time , nil , nil )
266+
267+ assert_kind_of String , result
268+
269+ # Should handle empty string message
270+ result = formatter . call ( "DEBUG" , time , "prog" , "" )
271+
272+ assert_kind_of String , result
273+ end
223274 end
224275end
0 commit comments