Skip to content

Commit

Permalink
fix: JVM logging
Browse files Browse the repository at this point in the history
fixes: #4718
  • Loading branch information
stuartwdouglas committed Mar 5, 2025
1 parent 707422e commit dcbdbee
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
4 changes: 4 additions & 0 deletions jvm-runtime/ftl-runtime/common/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jackson-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-logging-json-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health-deployment</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions jvm-runtime/ftl-runtime/common/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-logging-json</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-jdbc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class FTLConfigSource implements ConfigSource {

final static String FTL_BIND = "FTL_BIND";
private static final String OTEL_ENV_VAR = "OTEL_EXPORTER_OTLP_ENDPOINT";
public static final String QUARKUS_LOG_LEVEL = "quarkus.log.level";

final FTLController controller;

Expand All @@ -41,7 +42,7 @@ public class FTLConfigSource implements ConfigSource {

public FTLConfigSource(FTLController controller) {
this.controller = controller;
this.propertyNames = new HashSet<>(List.of(SEPARATE_SERVER, PORT, HOST));
this.propertyNames = new HashSet<>(List.of(SEPARATE_SERVER, PORT, HOST, QUARKUS_LOG_LEVEL));
try (var in = Thread.currentThread().getContextClassLoader().getResourceAsStream(DATASOURCE_NAMES)) {
String s = new String(in.readAllBytes(), StandardCharsets.UTF_8);
for (String name : s.split("\n")) {
Expand Down Expand Up @@ -71,6 +72,9 @@ public int getOrdinal() {
@Override
public String getValue(String s) {
switch (s) {
case QUARKUS_LOG_LEVEL -> {
return "DEBUG";
}
case OTEL_METRICS_DISABLED -> {
var v = System.getenv(OTEL_ENV_VAR);
return Boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package common

import (
"encoding/json"
"io"
"strings"
"time"

"github.com/alecthomas/atomic"

Expand Down Expand Up @@ -49,6 +51,13 @@ func (o *errorDetector) Write(p []byte) (n int, err error) {
o.logger.Tracef("%s", cleanLine)
} else if cleanLine, ok := strings.CutPrefix(line, "FINE "); ok {
o.logger.Tracef("%s", cleanLine)
} else if line[0] == '{' {
record := JvmLogRecord{}
if err := json.Unmarshal([]byte(line), &record); err == nil {
o.logger.Log(record.ToEntry())
} else {
o.logger.Infof("Log Parse Failure: %s", line)

Check failure on line 59 in jvm-runtime/plugin/common/jvm_logging.go

View workflow job for this annotation

GitHub Actions / Lint

use of `o.logger.Infof` forbidden because "Infof should only be used for user-facing messages, use //nolint to suppress" (forbidigo)
}
} else {
o.logger.Infof("%s", line)
}
Expand Down Expand Up @@ -95,3 +104,46 @@ func (o *errorDetector) FinalizeCapture() []builderrors.Error {
}
return errs
}

type JvmLogRecord struct {
Timestamp time.Time `json:"timestamp"`
Sequence int `json:"sequence"`
LoggerClassName string `json:"loggerClassName"`
LoggerName string `json:"loggerName"`
Level string `json:"level"`
Message string `json:"message"`
ThreadName string `json:"threadName"`
ThreadId int `json:"threadId"`

Check warning on line 116 in jvm-runtime/plugin/common/jvm_logging.go

View workflow job for this annotation

GitHub Actions / Lint

var-naming: struct field ThreadId should be ThreadID (revive)
Mdc any `json:"mdc"`
Ndc string `json:"ndc"`
HostName string `json:"hostName"`
ProcessName string `json:"processName"`
ProcessId int `json:"processId"`

Check warning on line 121 in jvm-runtime/plugin/common/jvm_logging.go

View workflow job for this annotation

GitHub Actions / Lint

var-naming: struct field ProcessId should be ProcessID (revive)
}

func (r *JvmLogRecord) ToEntry() log.Entry {
level := log.Info
switch r.Level {
case "DEBUG":
level = log.Debug
case "INFO":
level = log.Info
case "WARN", "WARNING":
level = log.Warn
case "ERROR", "SEVERE":
level = log.Error
case "FINE", "FINER":
level = log.Debug
case "FINEST", "TRACE":
level = log.Trace
default:
r.Message = r.Level + ": " + r.Message
}

ret := log.Entry{
Time: r.Timestamp,
Level: level,
Message: r.Message,
}
return ret
}
2 changes: 1 addition & 1 deletion jvm-runtime/plugin/common/jvmcommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ func (s *Service) ModuleConfigDefaults(ctx context.Context, req *connect.Request
defaults.DeployDir = "target"
} else if fileExists(buildGradle) || fileExists(buildGradleKts) {
defaults.LanguageConfig.Fields["build-tool"] = structpb.NewStringValue(JavaBuildToolGradle)
defaults.DevModeBuild = ptr("gradle clean quarkusDev")
defaults.DevModeBuild = ptr("gradle clean quarkusDev -Dquarkus.console.enabled=false")
defaults.Build = ptr("gradle clean build")
defaults.DeployDir = "build"
} else {
Expand Down

0 comments on commit dcbdbee

Please sign in to comment.