diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/config/crd/bases/camel.apache.org_integrationplatforms.yaml index 9d882a46b3..f58df20782 100644 --- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml +++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml @@ -1405,6 +1405,13 @@ spec: logging: description: The configuration of Logging trait properties: + category: + additionalProperties: + type: string + description: 'Log Level category of the trait This can be + used to set log levels of specific packages CLI usage example: -t + "logging.category.''org.test''=DEBUG"' + type: object color: description: Colorize the log output type: boolean @@ -3276,6 +3283,13 @@ spec: logging: description: The configuration of Logging trait properties: + category: + additionalProperties: + type: string + description: 'Log Level category of the trait This can be + used to set log levels of specific packages CLI usage example: -t + "logging.category.''org.test''=DEBUG"' + type: object color: description: Colorize the log output type: boolean diff --git a/config/crd/bases/camel.apache.org_integrations.yaml b/config/crd/bases/camel.apache.org_integrations.yaml index 0a6699bf18..d01a880806 100644 --- a/config/crd/bases/camel.apache.org_integrations.yaml +++ b/config/crd/bases/camel.apache.org_integrations.yaml @@ -7324,6 +7324,13 @@ spec: logging: description: The configuration of Logging trait properties: + category: + additionalProperties: + type: string + description: 'Log Level category of the trait This can be + used to set log levels of specific packages CLI usage example: -t + "logging.category.''org.test''=DEBUG"' + type: object color: description: Colorize the log output type: boolean diff --git a/config/crd/bases/camel.apache.org_kameletbindings.yaml b/config/crd/bases/camel.apache.org_kameletbindings.yaml index f1b8fb6da5..33d23c2679 100644 --- a/config/crd/bases/camel.apache.org_kameletbindings.yaml +++ b/config/crd/bases/camel.apache.org_kameletbindings.yaml @@ -7619,6 +7619,13 @@ spec: logging: description: The configuration of Logging trait properties: + category: + additionalProperties: + type: string + description: 'Log Level category of the trait This can + be used to set log levels of specific packages CLI usage + example: -t "logging.category.''org.test''=DEBUG"' + type: object color: description: Colorize the log output type: boolean diff --git a/config/crd/bases/camel.apache.org_pipes.yaml b/config/crd/bases/camel.apache.org_pipes.yaml index 5dab843b65..716d370485 100644 --- a/config/crd/bases/camel.apache.org_pipes.yaml +++ b/config/crd/bases/camel.apache.org_pipes.yaml @@ -7617,6 +7617,13 @@ spec: logging: description: The configuration of Logging trait properties: + category: + additionalProperties: + type: string + description: 'Log Level category of the trait This can + be used to set log levels of specific packages CLI usage + example: -t "logging.category.''org.test''=DEBUG"' + type: object color: description: Colorize the log output type: boolean diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc index 87588e0874..cb8ab0929a 100644 --- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc +++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc @@ -7231,6 +7231,15 @@ The logging backend is provided by Quarkus, whose configuration is documented at +|`category` + +map[string]string +| + + +Log Level category of the trait +This can be used to set log levels of specific packages +CLI usage example: -t "logging.category.'org.test'=DEBUG" + |`color` + bool | diff --git a/docs/modules/traits/pages/logging.adoc b/docs/modules/traits/pages/logging.adoc index 72e504d8b3..633254dad6 100755 --- a/docs/modules/traits/pages/logging.adoc +++ b/docs/modules/traits/pages/logging.adoc @@ -26,6 +26,12 @@ The following configuration options are available: | bool | Can be used to enable or disable a trait. All traits share this common property. +| logging.category +| map[string]string +| Log Level category of the trait +This can be used to set log levels of specific packages +CLI usage example: -t "logging.category.'org.test'=DEBUG" + | logging.color | bool | Colorize the log output diff --git a/helm/camel-k/crds/crd-integration-platform.yaml b/helm/camel-k/crds/crd-integration-platform.yaml index 9d882a46b3..f58df20782 100644 --- a/helm/camel-k/crds/crd-integration-platform.yaml +++ b/helm/camel-k/crds/crd-integration-platform.yaml @@ -1405,6 +1405,13 @@ spec: logging: description: The configuration of Logging trait properties: + category: + additionalProperties: + type: string + description: 'Log Level category of the trait This can be + used to set log levels of specific packages CLI usage example: -t + "logging.category.''org.test''=DEBUG"' + type: object color: description: Colorize the log output type: boolean @@ -3276,6 +3283,13 @@ spec: logging: description: The configuration of Logging trait properties: + category: + additionalProperties: + type: string + description: 'Log Level category of the trait This can be + used to set log levels of specific packages CLI usage example: -t + "logging.category.''org.test''=DEBUG"' + type: object color: description: Colorize the log output type: boolean diff --git a/helm/camel-k/crds/crd-integration.yaml b/helm/camel-k/crds/crd-integration.yaml index 0a6699bf18..d01a880806 100644 --- a/helm/camel-k/crds/crd-integration.yaml +++ b/helm/camel-k/crds/crd-integration.yaml @@ -7324,6 +7324,13 @@ spec: logging: description: The configuration of Logging trait properties: + category: + additionalProperties: + type: string + description: 'Log Level category of the trait This can be + used to set log levels of specific packages CLI usage example: -t + "logging.category.''org.test''=DEBUG"' + type: object color: description: Colorize the log output type: boolean diff --git a/helm/camel-k/crds/crd-kamelet-binding.yaml b/helm/camel-k/crds/crd-kamelet-binding.yaml index f1b8fb6da5..33d23c2679 100644 --- a/helm/camel-k/crds/crd-kamelet-binding.yaml +++ b/helm/camel-k/crds/crd-kamelet-binding.yaml @@ -7619,6 +7619,13 @@ spec: logging: description: The configuration of Logging trait properties: + category: + additionalProperties: + type: string + description: 'Log Level category of the trait This can + be used to set log levels of specific packages CLI usage + example: -t "logging.category.''org.test''=DEBUG"' + type: object color: description: Colorize the log output type: boolean diff --git a/helm/camel-k/crds/crd-pipe.yaml b/helm/camel-k/crds/crd-pipe.yaml index 5dab843b65..716d370485 100644 --- a/helm/camel-k/crds/crd-pipe.yaml +++ b/helm/camel-k/crds/crd-pipe.yaml @@ -7617,6 +7617,13 @@ spec: logging: description: The configuration of Logging trait properties: + category: + additionalProperties: + type: string + description: 'Log Level category of the trait This can + be used to set log levels of specific packages CLI usage + example: -t "logging.category.''org.test''=DEBUG"' + type: object color: description: Colorize the log output type: boolean diff --git a/pkg/apis/camel/v1/trait/logging.go b/pkg/apis/camel/v1/trait/logging.go index 3da324651f..0d01ff83aa 100644 --- a/pkg/apis/camel/v1/trait/logging.go +++ b/pkg/apis/camel/v1/trait/logging.go @@ -23,6 +23,10 @@ package trait // +camel-k:trait=logging. type LoggingTrait struct { Trait `property:",squash" json:",inline"` + // Log Level category of the trait + // This can be used to set log levels of specific packages + // CLI usage example: -t "logging.category.'org.test'=DEBUG" + Category map[string]string `property:"category" json:"category,omitempty"` // Colorize the log output Color *bool `property:"color" json:"color,omitempty"` // Logs message format diff --git a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go index 5cfb029589..9e73bfc275 100644 --- a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go @@ -676,6 +676,13 @@ func (in *KnativeTrait) DeepCopy() *KnativeTrait { func (in *LoggingTrait) DeepCopyInto(out *LoggingTrait) { *out = *in in.Trait.DeepCopyInto(&out.Trait) + if in.Category != nil { + in, out := &in.Category, &out.Category + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } if in.Color != nil { in, out := &in.Color, &out.Color *out = new(bool) diff --git a/pkg/trait/logging.go b/pkg/trait/logging.go index dafd331a76..78636346ab 100644 --- a/pkg/trait/logging.go +++ b/pkg/trait/logging.go @@ -18,6 +18,8 @@ limitations under the License. package trait import ( + "strings" + "k8s.io/utils/pointer" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" @@ -28,6 +30,7 @@ const ( envVarQuarkusConsoleColor = "QUARKUS_CONSOLE_COLOR" envVarQuarkusLogLevel = "QUARKUS_LOG_LEVEL" envVarQuarkusLogConsoleFormat = "QUARKUS_LOG_CONSOLE_FORMAT" + envVarQuarkusLogCategory = "QUARKUS_LOG_CATEGORY" // nolint: gosec // no sensitive credentials envVarQuarkusLogConsoleJSON = "QUARKUS_LOG_CONSOLE_JSON" envVarQuarkusLogConsoleJSONPrettyPrint = "QUARKUS_LOG_CONSOLE_JSON_PRETTY_PRINT" @@ -43,7 +46,8 @@ func newLoggingTraitTrait() Trait { return &loggingTrait{ BaseTrait: NewBaseTrait("logging", 800), LoggingTrait: traitv1.LoggingTrait{ - Level: defaultLogLevel, + Level: defaultLogLevel, + Category: map[string]string{}, }, } } @@ -67,6 +71,15 @@ func (l loggingTrait) Apply(e *Environment) error { envvar.SetVal(&e.EnvVars, envVarQuarkusLogConsoleFormat, l.Format) } + if len(l.Category) > 0 { + for k, v := range l.Category { + envVarQuarkusPackage := strings.ReplaceAll(strings.ToUpper(k), ".", "_") + envVarQuarkusLogCategoryPackageFormat := envVarQuarkusLogCategory + "_" + envVarQuarkusPackage + "_LEVEL" + envVarQuarkusLogCatagoryValue := strings.ToUpper(v) + envvar.SetVal(&e.EnvVars, envVarQuarkusLogCategoryPackageFormat, envVarQuarkusLogCatagoryValue) + } + } + if pointer.BoolDeref(l.JSON, false) { envvar.SetVal(&e.EnvVars, envVarQuarkusLogConsoleJSON, True) if pointer.BoolDeref(l.JSONPrettyPrint, false) { diff --git a/pkg/trait/logging_test.go b/pkg/trait/logging_test.go index 6b2846e626..7f5ad0a26b 100644 --- a/pkg/trait/logging_test.go +++ b/pkg/trait/logging_test.go @@ -34,7 +34,7 @@ import ( "github.com/apache/camel-k/v2/pkg/util/test" ) -func createLoggingTestEnv(t *testing.T, color bool, json bool, jsonPrettyPrint bool, logLevel string, logFormat string) *Environment { +func createLoggingTestEnv(t *testing.T, color bool, json bool, jsonPrettyPrint bool, logLevel string, logFormat string, logCategory map[string]string) *Environment { t.Helper() client, _ := test.NewFakeClient() @@ -65,6 +65,7 @@ func createLoggingTestEnv(t *testing.T, color bool, json bool, jsonPrettyPrint b JSON: pointer.Bool(json), JSONPrettyPrint: pointer.Bool(jsonPrettyPrint), Level: logLevel, + Category: logCategory, }, }, }, @@ -101,7 +102,7 @@ func createLoggingTestEnv(t *testing.T, color bool, json bool, jsonPrettyPrint b func createDefaultLoggingTestEnv(t *testing.T) *Environment { t.Helper() - return createLoggingTestEnv(t, true, false, false, defaultLogLevel, "") + return createLoggingTestEnv(t, true, false, false, defaultLogLevel, "", map[string]string{}) } func NewLoggingTestCatalog() *Catalog { @@ -162,8 +163,9 @@ func TestEmptyLoggingTrait(t *testing.T) { func TestJsonLoggingTrait(t *testing.T) { // When running, this log should look like "09:07:00 INFO (main) Profile prod activated." - env := createLoggingTestEnv(t, true, true, false, "TRACE", "%d{HH:mm:ss} %-5p (%t) %s%e%n") - conditions, err := NewLoggingTestCatalog().apply(env) + env := createLoggingTestEnv(t, true, true, false, "TRACE", "%d{HH:mm:ss} %-5p (%t) %s%e%n", map[string]string{}) + err := NewLoggingTestCatalog().apply(env) + assert.Nil(t, err) assert.Empty(t, conditions) @@ -214,3 +216,38 @@ func TestJsonLoggingTrait(t *testing.T) { assert.True(t, logFormatIsNotDefault) assert.NotEmpty(t, env.ExecutedTraits) } + +func TestSingleLoggingCategory(t *testing.T) { + env := createLoggingTestEnv(t, true, true, false, "TRACE", "%d{HH:mm:ss} %-5p (%t) %s%e%n", map[string]string{}) + env.Integration.Spec.Traits = v1.Traits{ + Logging: &traitv1.LoggingTrait{ + Category: map[string]string{"org.test": "debug"}, + }, + } + err := NewLoggingTestCatalog().apply(env) + assert.Nil(t, err) + + testEnvVar := corev1.EnvVar{"QUARKUS_LOG_CATEGORY_ORG_TEST_LEVEL", "DEBUG", nil} + assert.Contains(t, env.EnvVars, testEnvVar) +} + +func TestLoggingCategories(t *testing.T) { + env := createLoggingTestEnv(t, true, true, false, "TRACE", "%d{HH:mm:ss} %-5p (%t) %s%e%n", map[string]string{}) + env.Integration.Spec.Traits = v1.Traits{ + Logging: &traitv1.LoggingTrait{ + Category: map[string]string{"org.test": "debug", "org.jboss.resteasy": "debug"}, + }, + } + err := NewLoggingTestCatalog().apply(env) + assert.Nil(t, err) + + testEnvVars := []corev1.EnvVar{ + corev1.EnvVar{"QUARKUS_LOG_CATEGORY_ORG_TEST_LEVEL", "DEBUG", nil}, + corev1.EnvVar{"QUARKUS_LOG_CATEGORY_ORG_JBOSS_RESTEASY_LEVEL", "DEBUG", nil}, + } + + for _, v := range testEnvVars { + assert.Contains(t, env.EnvVars, v) + } + +} diff --git a/resources/traits.yaml b/resources/traits.yaml index a4037d72b7..f9b7620254 100755 --- a/resources/traits.yaml +++ b/resources/traits.yaml @@ -1107,6 +1107,10 @@ traits: type: bool description: Can be used to enable or disable a trait. All traits share this common property. + - name: category + type: map[string]string + description: 'Log Level category of the trait This can be used to set log levels + of specific packages CLI usage example: -t "logging.category.''org.test''=DEBUG"' - name: color type: bool description: Colorize the log output