Skip to content

Switched capture strategy directly adding spy appender#3

Merged
andsel merged 3 commits intofeature/string_setting_to_javafrom
dbg/log_appender_spy
Nov 12, 2024
Merged

Switched capture strategy directly adding spy appender#3
andsel merged 3 commits intofeature/string_setting_to_javafrom
dbg/log_appender_spy

Conversation

@andsel
Copy link
Copy Markdown
Owner

@andsel andsel commented Nov 8, 2024

Reworked log capture in setting_with_deprecated_alias_spec to use Logger's addAppender and a spy appender implementation.
This leverages the idea to don't reconfigure the Log4J with a custom build configuration, but simply adding an appender that could spy the appended lines to a logger, like described in https://github.com/andsel/log4j2_log_spy?tab=readme-ov-file#idea-2---add-a-customer-appender-to-the-logger-to-collect-the-messages.

The idea is use a list as a message accumulator, but the strange thing is that a message just added disappear and re-appear without an apparent motivation.

org.logstash.RSpecTests > rspecTests[core tests] STANDARD_OUT
    Run options: exclude {:integration=>true, :redis=>true, :socket=>true, :performance=>true, :couchdb=>true, :elasticsearch=>true, :elasticsearch_secure=>true, :export_cypher=>true, :windows=>true}

    Randomized with seed 64075

    LogStash::Setting::SettingWithDeprecatedAlias
      Settings#get on deprecated alias
    DNADBG>> before - before calling log.info, events: ["12345"]
    DNADBG>> CustomAppender.append invoked log_event: Logger=org.logstash.settings.DeprecatedAlias Level=INFO Message=Test ping message
    DNADBG>> CustomAppender.append invoked list content: ["12345", "Test ping message"]
    DNADBG>> before - just after called log.info, events: ["12345"]
    DNADBG>> inside the test
    DNADBG>> CustomAppender.append invoked log_event: Logger=org.logstash.settings.DeprecatedAlias Level=WARN Message=The value of setting `canonical.setting` has been queried by its deprecated alias `legacy.setting`. Code should be updated to query `canonical.setting` instead
    DNADBG>> CustomAppender.append invoked list content: ["12345", "Test ping message", "The value of setting `canonical.setting` has been queried by its deprecated alias `legacy.setting`. Code should be updated to query `canonical.setting` instead"]
    DNADBG>> inside the test - after exercise
        produces a WARN-level message to the logger (FAILED - 1)

    Failures:

      1) LogStash::Setting::SettingWithDeprecatedAlias Settings#get on deprecated alias produces a WARN-level message to the logger
         Failure/Error: expect(events[0].message.formatted_message).to include("setting `#{canonical_setting_name}` has been queried by its deprecated alias `#{deprecated_setting_name}`")

         NoMethodError:
           undefined method `message' for nil:NilClass
         # ./logstash-core/spec/logstash/settings/setting_with_deprecated_alias_spec.rb:199:in `block in <main>'
         # ./spec/spec_helper.rb:84:in `block in <main>'
         # ./logstash-core/lib/logstash/util.rb:43:in `set_thread_name'
         # ./spec/spec_helper.rb:83:in `block in <main>'
         # ./spec/spec_helper.rb:76:in `block in <main>'
         # ./vendor/bundle/jruby/3.1.0/gems/logstash-devutils-2.6.2-java/lib/logstash/devutils/rspec/spec_helper.rb:47:in `block in <main>'
         # ./lib/bootstrap/rspec.rb:36:in `<main>'

    Finished in 0.01929 seconds (files took 0.03019 seconds to load)
    1 example, 1 failure

@andsel andsel changed the title [DEBUG DBG] Switched capture strategy directly adding spy appender Switched capture strategy directly adding spy appender Nov 12, 2024
@andsel andsel marked this pull request as ready for review November 12, 2024 09:04
@andsel andsel merged commit f5380e7 into feature/string_setting_to_java Nov 12, 2024
andsel added a commit that referenced this pull request Nov 12, 2024
Reworked log capture in setting_with_deprecated_alias_spec to use Logger's addAppender and a spy appender implementation.
This leverages the idea to don't reconfigure the Log4J with a custom build configuration, but simply adding an appender that could spy the appended lines to a logger.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant