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

fix: Unrecognized configuration from quarkus-logging-json #2454

Merged
merged 2 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 13 additions & 18 deletions pkg/trait/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ limitations under the License.
package trait

import (
"strconv"

v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/util"
"github.com/apache/camel-k/pkg/util/envvar"
Expand All @@ -31,8 +29,7 @@ const (
envVarQuarkusLogConsoleFormat = "QUARKUS_LOG_CONSOLE_FORMAT"
envVarQuarkusLogConsoleJson = "QUARKUS_LOG_CONSOLE_JSON"
envVarQuarkusLogConsoleJsonPrettyPrint = "QUARKUS_LOG_CONSOLE_JSON_PRETTY_PRINT"
depQuarkusLoggingJson = "quarkus-logging-json"
defaultLogFormat = ""
depQuarkusLoggingJson = "mvn:io.quarkus:quarkus-logging-json"
defaultLogLevel = "INFO"
)

Expand All @@ -56,17 +53,13 @@ type loggingTrait struct {

func newLoggingTraitTrait() Trait {
return &loggingTrait{
BaseTrait: NewBaseTrait("logging", 800),
Color: util.BoolP(true),
Format: defaultLogFormat,
Level: defaultLogLevel,
Json: util.BoolP(false),
JsonPrettyPrint: util.BoolP(false),
BaseTrait: NewBaseTrait("logging", 800),
Level: defaultLogLevel,
}
}

func (l loggingTrait) Configure(environment *Environment) (bool, error) {
if l.Enabled != nil && !*l.Enabled {
if util.IsFalse(l.Enabled) {
return false, nil
}

Expand All @@ -76,7 +69,7 @@ func (l loggingTrait) Configure(environment *Environment) (bool, error) {

func (l loggingTrait) Apply(environment *Environment) error {
if environment.IntegrationInPhase(v1.IntegrationPhaseInitialization) {
if *l.Json {
if util.IsTrue(l.Json) {
if environment.Integration.Status.Dependencies == nil {
environment.Integration.Status.Dependencies = make([]string, 0)
}
Expand All @@ -88,15 +81,17 @@ func (l loggingTrait) Apply(environment *Environment) error {

envvar.SetVal(&environment.EnvVars, envVarQuarkusLogLevel, l.Level)

if l.Format != defaultLogFormat {
if l.Format != "" {
envvar.SetVal(&environment.EnvVars, envVarQuarkusLogConsoleFormat, l.Format)
}

envvar.SetVal(&environment.EnvVars, envVarQuarkusLogConsoleJson, strconv.FormatBool(*l.Json))
envvar.SetVal(&environment.EnvVars, envVarQuarkusLogConsoleJsonPrettyPrint, strconv.FormatBool(*l.JsonPrettyPrint))

if !*l.Json {
envvar.SetVal(&environment.EnvVars, envVarQuarkusLogConsoleColor, strconv.FormatBool(*l.Color))
if util.IsTrue(l.Json) {
envvar.SetVal(&environment.EnvVars, envVarQuarkusLogConsoleJson, True)
if util.IsTrue(l.JsonPrettyPrint) {
envvar.SetVal(&environment.EnvVars, envVarQuarkusLogConsoleJsonPrettyPrint, True)
}
} else if util.IsNilOrTrue(l.Color) {
envvar.SetVal(&environment.EnvVars, envVarQuarkusLogConsoleColor, True)
}

return nil
Expand Down
13 changes: 8 additions & 5 deletions pkg/trait/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ package trait

import (
"context"
"testing"

"github.com/stretchr/testify/assert"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/util/camel"
"github.com/apache/camel-k/pkg/util/kubernetes"
"github.com/apache/camel-k/pkg/util/test"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"testing"
)

func createLoggingTestEnv(t *testing.T, color bool, json bool, jsonPrettyPrint bool, logLevel string, logFormat string) *Environment {
Expand Down Expand Up @@ -82,7 +85,7 @@ func createLoggingTestEnv(t *testing.T, color bool, json bool, jsonPrettyPrint b
}

func createDefaultLoggingTestEnv(t *testing.T) *Environment {
return createLoggingTestEnv(t, true, false, false, defaultLogLevel, defaultLogFormat)
return createLoggingTestEnv(t, true, false, false, defaultLogLevel, "")
}

func NewLoggingTestCatalog() *Catalog {
Expand Down