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 #4844

Closed
Closed
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
25e0808
feat: set package log level with logging trait
Oct 23, 2023
d089fea
Merge branch 'apache:main' into feat/logging_trait_pkg_log_level
realMartinez Oct 23, 2023
d462365
feat: set package log level with logging trait
Oct 23, 2023
3cd573f
doc: generated documentation
Oct 23, 2023
cdf5dcd
doc: generated documentation
Oct 23, 2023
64e59a3
chore: changelog automatic update
github-actions[bot] Oct 17, 2023
147ca6b
chore: nightly SBOM update
github-actions[bot] Oct 17, 2023
5d52be4
chore(deps): bump knative.dev/serving from 0.38.1 to 0.38.2
dependabot[bot] Oct 18, 2023
0aed1ee
fix: removed unnecessary defaul value
Oct 17, 2023
33d1900
feat(api): Kamelet as static resource
squakez Oct 6, 2023
44a7264
chore(api): leave .status.phase=Ready as default
squakez Oct 17, 2023
c90765a
chore(deps): bump knative.dev/eventing from 0.38.4 to 0.38.5
dependabot[bot] Oct 18, 2023
d5135db
chore: changelog automatic update
github-actions[bot] Oct 18, 2023
bcf1135
chore: autogenerated project resource update
github-actions[bot] Oct 18, 2023
8fbac22
chore: nightly SBOM update
github-actions[bot] Oct 18, 2023
c23f801
chore(deps): bump github.com/prometheus/common from 0.44.0 to 0.45.0
dependabot[bot] Oct 18, 2023
49619fb
chore: changelog automatic update
github-actions[bot] Oct 19, 2023
5196b75
chore: nightly SBOM update
github-actions[bot] Oct 19, 2023
662708c
feat(build): add root image info
squakez Oct 19, 2023
3350183
fix(ci): latest azure/setup-kubectl action not working
squakez Oct 20, 2023
0cc0db8
chore: improved e2e tests documentation.
valdar Oct 20, 2023
c37f660
chore: changelog automatic update
github-actions[bot] Oct 20, 2023
96852d5
chore: autogenerated project resource update
github-actions[bot] Oct 20, 2023
ab89d9b
chore: nightly SBOM update
github-actions[bot] Oct 20, 2023
b4d3890
chore: nightly SBOM update
github-actions[bot] Oct 21, 2023
f49dc0d
chore: changelog automatic update
github-actions[bot] Oct 22, 2023
6fef0f5
chore: nightly SBOM update
github-actions[bot] Oct 22, 2023
0bc1a44
feat: set package log level with logging trait
Oct 23, 2023
4e9063c
doc: generated documentation
Oct 23, 2023
cf2aa74
doc: generated documentation
Oct 23, 2023
6847f9c
Merge remote-tracking branch 'refs/remotes/origin/feat/logging_trait_…
Nov 13, 2023
75fb9a5
Merge branch 'main' into feat/logging_trait_pkg_log_level
realMartinez Nov 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions config/crd/bases/camel.apache.org_integrationplatforms.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions config/crd/bases/camel.apache.org_integrations.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions config/crd/bases/camel.apache.org_kameletbindings.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions config/crd/bases/camel.apache.org_pipes.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
@@ -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
|
6 changes: 6 additions & 0 deletions docs/modules/traits/pages/logging.adoc
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions helm/camel-k/crds/crd-integration-platform.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions helm/camel-k/crds/crd-integration.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions helm/camel-k/crds/crd-kamelet-binding.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions helm/camel-k/crds/crd-pipe.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions pkg/apis/camel/v1/trait/logging.go
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions pkg/apis/camel/v1/trait/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion pkg/trait/logging.go
Original file line number Diff line number Diff line change
@@ -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) {
45 changes: 41 additions & 4 deletions pkg/trait/logging_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

}
4 changes: 4 additions & 0 deletions resources/traits.yaml
Original file line number Diff line number Diff line change
@@ -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