Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

fix: create a logger instance per class instead of per instance #792

Merged
merged 1 commit into from
Jul 19, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
)
public class OpenApiToRestDslResource {

private Logger log = Logger.getLogger(OpenApiToRestDslResource.class);
private static final Logger LOG = Logger.getLogger(OpenApiToRestDslResource.class);

@Inject
private CamelRuntime camelRuntime;
Expand All @@ -69,7 +69,7 @@ private JsonNode readOpenApiSpec(final String input) {
try {
return mapper.readTree(input);
} catch (Exception e) {
log.debug("Failed to parse input as JSON, trying YAML", e);
LOG.debug("Failed to parse input as JSON, trying YAML", e);
Yaml loader = new Yaml(new SafeConstructor(new LoaderOptions()));
Map map = loader.load(input);
return mapper.convertValue(map, JsonNode.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.kaoto.backend.api.resource.v1;

import io.kaoto.backend.api.resource.v1.model.Capabilities;
import io.kaoto.backend.api.service.language.LanguageService;
import io.kaoto.backend.deployment.ClusterService;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;

import io.kaoto.backend.api.resource.v1.model.Capabilities;
import io.kaoto.backend.api.service.language.LanguageService;
import io.kaoto.backend.deployment.ClusterService;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
Expand Down Expand Up @@ -37,7 +37,7 @@ public class CapabilitiesResource {
@ConfigProperty(name = "quarkus.application.version")
private String version;

private Logger log = Logger.getLogger(CapabilitiesResource.class);
private static final Logger LOG = Logger.getLogger(CapabilitiesResource.class);

private LanguageService languageService;

Expand Down Expand Up @@ -100,7 +100,7 @@ public String getValidationSchema(

@ServerExceptionMapper
public Response mapException(final Exception x) {
log.error("Error getting capabilities.", x);
LOG.error("Error getting capabilities.", x);

return Response.status(Response.Status.BAD_REQUEST)
.entity("Error parsing capabilities.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
package io.kaoto.backend.api.resource.v1;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.fabric8.kubernetes.client.CustomResource;
import io.kaoto.backend.api.service.deployment.generator.DeploymentGeneratorService;
import io.kaoto.backend.camel.service.deployment.generator.kamelet.KameletRepresenter;
import io.kaoto.backend.deployment.ClusterService;
import io.kaoto.backend.model.deployment.Deployment;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Multi;
import java.util.List;

import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody;
Expand All @@ -20,6 +12,17 @@
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import io.fabric8.kubernetes.client.CustomResource;
import io.kaoto.backend.api.service.deployment.generator.DeploymentGeneratorService;
import io.kaoto.backend.camel.service.deployment.generator.kamelet.KameletRepresenter;
import io.kaoto.backend.deployment.ClusterService;
import io.kaoto.backend.model.deployment.Deployment;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Multi;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
Expand All @@ -35,7 +38,6 @@
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.List;

/**
* 🐱class DeploymentsResource
Expand All @@ -47,7 +49,7 @@
@ApplicationScoped
public class DeploymentsResource {

private Logger log = Logger.getLogger(DeploymentsResource.class);
private static final Logger LOG = Logger.getLogger(DeploymentsResource.class);
private ClusterService clusterService;
private Instance<DeploymentGeneratorService> parsers;

Expand Down Expand Up @@ -123,7 +125,7 @@ private String securityCheck(final String crd) {
yamlMapper.readValue(crd, c);
valid = true;
} catch (Exception e) {
log.trace("We tried to parse with " + c.getName() + " and"
LOG.trace("We tried to parse with " + c.getName() + " and"
+ " it didn't work.");
}
}
Expand Down Expand Up @@ -172,7 +174,7 @@ public String resource(
new KameletRepresenter());
return yaml.dumpAsMap(cr);
} catch (Exception e) {
log.trace("We tried to parse with " + c.getName() + " and"
LOG.trace("We tried to parse with " + c.getName() + " and"
+ " it didn't work.");
}
}
Expand Down Expand Up @@ -237,7 +239,7 @@ public Multi<String> logs(

@ServerExceptionMapper
public Response mapException(final Exception x) {
log.error("Error processing deployment.", x);
LOG.error("Error processing deployment.", x);

return Response.status(Response.Status.BAD_REQUEST)
.entity("Error processing deployment: " + x.getMessage())
Expand All @@ -247,7 +249,7 @@ public Response mapException(final Exception x) {

@ServerExceptionMapper
public Response mapException(final NotFoundException x) {
log.error("Error processing deployment.", x);
LOG.error("Error processing deployment.", x);

return Response.status(Response.Status.NOT_FOUND)
.entity("Error processing deployment: " + x.getMessage())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package io.kaoto.backend.api.resource.v1;

import io.kaoto.backend.api.resource.v1.model.Integration;
import io.kaoto.backend.api.service.deployment.DeploymentService;
import io.kaoto.backend.api.service.dsl.DSLSpecification;
import io.kaoto.backend.api.service.language.LanguageService;
import io.kaoto.backend.model.step.Step;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody;
import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;

import io.kaoto.backend.api.resource.v1.model.Integration;
import io.kaoto.backend.api.service.deployment.DeploymentService;
import io.kaoto.backend.api.service.dsl.DSLSpecification;
import io.kaoto.backend.api.service.language.LanguageService;
import io.kaoto.backend.model.step.Step;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
Expand All @@ -21,8 +24,6 @@
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;

/**
* 🐱class IntegrationsResource
Expand All @@ -36,7 +37,7 @@
@ApplicationScoped
public class IntegrationsResource {

private Logger log = Logger.getLogger(IntegrationsResource.class);
private static final Logger LOG = Logger.getLogger(IntegrationsResource.class);
private DeploymentService deploymentService;
private Instance<DSLSpecification> dslSpecifications;
private LanguageService languageService;
Expand Down Expand Up @@ -114,7 +115,7 @@ public Integration integration(
break;
}
} catch (Exception e) {
log.warn("Parser " + stepParserService.getClass() + "threw an unexpected error.", e);
LOG.warn("Parser " + stepParserService.getClass() + "threw an unexpected error.", e);
}
}

Expand All @@ -127,12 +128,12 @@ public Integration integration(
integration.setMetadata(parsed.getMetadata());
integration.setParameters(parsed.getParameters());
integration.setDsl(stepParserService.identifier());
log.warn("Gurl, the DSL you gave me is so wrong. This is a " + stepParserService.identifier()
LOG.warn("Gurl, the DSL you gave me is so wrong. This is a " + stepParserService.identifier()
+ " not a " + dsl);
break;
}
} catch (Exception e) {
log.warn("Parser " + stepParserService.getClass()
LOG.warn("Parser " + stepParserService.getClass()
+ "threw an unexpected error.", e);
}
}
Expand Down Expand Up @@ -178,7 +179,7 @@ public List<String> compatibleDSL(final @RequestBody List<Step> steps) {

@ServerExceptionMapper
public Response mapException(final Exception x) {
log.error("Error processing deployment.", x);
LOG.error("Error processing deployment.", x);

return Response.status(Response.Status.BAD_REQUEST)
.entity("Error processing deployment: " + x.getMessage())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.kaoto.backend.api.resource.v1;

import io.kaoto.backend.api.service.viewdefinition.ViewDefinitionService;
import io.kaoto.backend.model.step.Step;
import io.kaoto.backend.model.view.ViewDefinition;
import java.util.List;

import org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.info.Contact;
Expand All @@ -12,6 +11,9 @@
import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;

import io.kaoto.backend.api.service.viewdefinition.ViewDefinitionService;
import io.kaoto.backend.model.step.Step;
import io.kaoto.backend.model.view.ViewDefinition;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
Expand All @@ -20,7 +22,6 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.List;

/**
* 🐱class ViewDefinitionResource
Expand All @@ -47,7 +48,7 @@
)
public class ViewDefinitionResource {

private Logger log = Logger.getLogger(ViewDefinitionResource.class);
private static final Logger LOG = Logger.getLogger(ViewDefinitionResource.class);

@Inject
public void setViewDefinitionService(
Expand Down Expand Up @@ -77,7 +78,7 @@ public List<ViewDefinition> viewsPerStepList(

@ServerExceptionMapper
public Response mapException(final Exception x) {
log.error("Error processing views definitions.", x);
LOG.error("Error processing views definitions.", x);

return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Error processing views definitions: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
@ApplicationScoped
public class IntegrationsResource {

private final Logger LOG = Logger.getLogger(IntegrationsResource.class);
private static final Logger LOG = Logger.getLogger(IntegrationsResource.class);
private final SecureRandom random = new SecureRandom();
private DeploymentService deploymentService;
private Instance<DSLSpecification> dslSpecifications;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@ApplicationScoped
public class DeploymentService {

private Logger log = Logger.getLogger(DeploymentService.class);
private static final Logger LOG = Logger.getLogger(DeploymentService.class);

@Inject
private Instance<DSLSpecification> parsers;
Expand Down Expand Up @@ -62,7 +62,7 @@ public List<Map<String, String>> crd(final String name,
res.add(strings);
}
} catch (Exception e) {
log.warn("Parser " + parser.getClass() + "threw an unexpected error. ", e);
LOG.warn("Parser " + parser.getClass() + "threw an unexpected error. ", e);
}
}

Expand All @@ -88,7 +88,7 @@ public String crd(final Integration i, final String dsl) {
.parse(i.getSteps(), i.getMetadata(), i.getParameters());
}
} catch (Exception e) {
log.warn("Parser " + parser.getClass() + "threw an unexpected error. ", e);
LOG.warn("Parser " + parser.getClass() + "threw an unexpected error. ", e);
}
}

Expand All @@ -100,7 +100,7 @@ public String crd(final Integration i, final String dsl) {
.parse(i.getSteps(), i.getMetadata(), i.getParameters());
}
} catch (Exception e) {
log.warn("Parser " + parser.getClass() + "threw an unexpected error. ", e);
LOG.warn("Parser " + parser.getClass() + "threw an unexpected error. ", e);
}
}

Expand Down Expand Up @@ -128,7 +128,7 @@ public String crds(final List<Integration> integrationList, final Map<String, Ob
integrations.add(parseResult);
if (integration.getDsl() != null) {
if (dsl != null && !integration.getDsl().equalsIgnoreCase(dsl)) {
log.error("We were sent a mix of DSL in the same list of flows!");
LOG.error("We were sent a mix of DSL in the same list of flows!");
}
dsl = integration.getDsl();
}
Expand All @@ -148,7 +148,7 @@ public String crds(final List<Integration> integrationList, final Map<String, Ob
return parser.getDeploymentGeneratorService().parse(integrations);
}
} catch (Exception e) {
log.warn("Parser " + parser.getClass() + "threw an unexpected error. ", e);
LOG.warn("Parser " + parser.getClass() + "threw an unexpected error. ", e);
break;
}
}
Expand All @@ -161,7 +161,7 @@ public String crds(final List<Integration> integrationList, final Map<String, Ob
return parser.getDeploymentGeneratorService().parse(integrations);
}
} catch (Exception e) {
log.warn("Parser " + parser.getClass() + "threw an unexpected error. ", e);
LOG.warn("Parser " + parser.getClass() + "threw an unexpected error. ", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package io.kaoto.backend.api.service.viewdefinition;

import java.util.ArrayList;
import java.util.List;

import org.jboss.logging.Logger;

import io.kaoto.backend.api.service.viewdefinition.parser.ViewDefinitionParserService;
import io.kaoto.backend.model.step.Step;
import io.kaoto.backend.model.view.ViewDefinition;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import org.jboss.logging.Logger;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import java.util.ArrayList;
import java.util.List;

/**
*
Expand All @@ -26,7 +27,7 @@ public class ViewDefinitionService {

private Instance<ViewDefinitionParserService<ViewDefinition>> viewParsers;

private Logger log = Logger.getLogger(ViewDefinitionService.class);
private static final Logger LOG = Logger.getLogger(ViewDefinitionService.class);

/*
* 🐱method viewsPerStepList: List[ViewDefinition]
Expand All @@ -39,7 +40,7 @@ public class ViewDefinitionService {
public List<ViewDefinition> viewsPerStepList(final List<Step> steps) {
List<ViewDefinition> viewDefinitions = new ArrayList<>();
for (var viewParser : getViewParsers()) {
log.trace("Using " + viewParser.getClass());
LOG.trace("Using " + viewParser.getClass());
viewDefinitions.addAll(viewParser.parse(steps));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class CamelRestDSLParseCatalog implements StepCatalogParser {
public static final String REST_DSL = "REST DSL";
protected static final String[] KINDS = {CAMEL_REST_DSL, CAMEL_REST_VERB, CAMEL_REST_ENDPOINT};
private static String ICON = null;
private Logger log = Logger.getLogger(CamelRestDSLParseCatalog.class);
private static final Logger LOG = Logger.getLogger(CamelRestDSLParseCatalog.class);

@NotNull
private static Step getRestParentStep() {
Expand Down Expand Up @@ -158,7 +158,7 @@ public CompletableFuture<List<Step>> parse() {
try {
ICON = new String(this.getClass().getResourceAsStream("base64icon.txt").readAllBytes());
} catch (IOException e) {
log.error("Couldn't load the icon file for REST DSL steps.");
LOG.error("Couldn't load the icon file for REST DSL steps.");
}
}

Expand Down
Loading