Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Set log level of a specific package using logging trait #5183

Closed
wants to merge 1 commit into from

Conversation

realMartinez
Copy link
Contributor

  • added capability to the logging trait to set log level of user specified package
  • added unit test

Usage:
-t "logging.category.'org.test'=DEBUG"

Release Note

feat: Set log level of a specific package using logging trait

@realMartinez
Copy link
Contributor Author

logTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "logging", "category")
Expect(logTrait).ToNot(BeNil())
Expect(len(logTrait)).To(Equal(1))
Expect(logTrait["org.apache.camel.impl"]).To(Equal("DEBUG"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is more suitable of a unit test, like it already exists. E2E test should check that the configuration is applied correctly, ie, checking Pod's env variables and above all, checking the log traces exposed have that DEBUG level.
As an example, see how we check for content in this test:

Eventually(IntegrationLogs(ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))

@realMartinez realMartinez force-pushed the logging_category_test branch 6 times, most recently from 4765983 to 629f0d8 Compare February 29, 2024 10:59
Copy link
Contributor

github-actions bot commented Mar 4, 2024

⚠️ Unit test coverage report - coverage decreased from 36.8% to 36.4% (-0.4%)

@claudio4j
Copy link
Contributor

I tried to run as ./kamel run --name javava e2e/common/traits/files/Java.java -t "logging.category.'org.apache.camel.impl'=DEBUG"

But it fails in the camel-k-operator, the log says "logger":"KubeAPIWarningLogger","msg":"unknown field \"status.traits.logging.category\""}

Then the integration status keeps changing from Initialization to Building Kit and back to initialization.

This is because the Integration CRD is missing the new category field, to fix it you should run make generate and amend the change to the commit.

@claudio4j
Copy link
Contributor

Also, trying the -t "logging.category.'org.apache.camel.impl'=DEBUG", there were no DEBUG level log in the integration pod.
The quarkus logging documentation about categories, when used with environment variables, the category name should be surround by two underscores, example: QUARKUS_LOG_CATEGORY__ORG_APACHE_CAMEL__LEVEL=DEBUG

That's why there is no DEBUG level log messages in the integration log.

quarkus logging shorts the log category name, the org.apache.camel. can be shortened to org.apa.cam., see an example:

DEBUG [org.apa.cam.sup.LRUCacheFactory] (main) Creating DefaultLRUCacheFactory

The test should monitor for this type of log content. The same for the org.jboss category.

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.

3 participants