Skip to content

Commit 76d9f3b

Browse files
fix: JVM logging (#4781)
fixes: #4718
1 parent 047af6d commit 76d9f3b

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

jvm-runtime/ftl-runtime/common/deployment/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<groupId>io.quarkus</groupId>
2424
<artifactId>quarkus-rest-jackson-deployment</artifactId>
2525
</dependency>
26+
<dependency>
27+
<groupId>io.quarkus</groupId>
28+
<artifactId>quarkus-logging-json-deployment</artifactId>
29+
</dependency>
2630
<dependency>
2731
<groupId>io.quarkus</groupId>
2832
<artifactId>quarkus-smallrye-health-deployment</artifactId>

jvm-runtime/ftl-runtime/common/runtime/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
<groupId>io.quarkus</groupId>
4141
<artifactId>quarkus-opentelemetry</artifactId>
4242
</dependency>
43+
<dependency>
44+
<groupId>io.quarkus</groupId>
45+
<artifactId>quarkus-logging-json</artifactId>
46+
</dependency>
4347
<dependency>
4448
<groupId>io.opentelemetry.instrumentation</groupId>
4549
<artifactId>opentelemetry-jdbc</artifactId>

jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/runtime/config/FTLConfigSource.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class FTLConfigSource implements ConfigSource {
2626

2727
final static String FTL_BIND = "FTL_BIND";
2828
private static final String OTEL_ENV_VAR = "OTEL_EXPORTER_OTLP_ENDPOINT";
29+
public static final String QUARKUS_LOG_LEVEL = "quarkus.log.level";
2930

3031
final FTLController controller;
3132

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

4243
public FTLConfigSource(FTLController controller) {
4344
this.controller = controller;
44-
this.propertyNames = new HashSet<>(List.of(SEPARATE_SERVER, PORT, HOST));
45+
this.propertyNames = new HashSet<>(List.of(SEPARATE_SERVER, PORT, HOST, QUARKUS_LOG_LEVEL));
4546
try (var in = Thread.currentThread().getContextClassLoader().getResourceAsStream(DATASOURCE_NAMES)) {
4647
String s = new String(in.readAllBytes(), StandardCharsets.UTF_8);
4748
for (String name : s.split("\n")) {
@@ -71,6 +72,9 @@ public int getOrdinal() {
7172
@Override
7273
public String getValue(String s) {
7374
switch (s) {
75+
case QUARKUS_LOG_LEVEL -> {
76+
return "DEBUG";
77+
}
7478
case OTEL_METRICS_DISABLED -> {
7579
var v = System.getenv(OTEL_ENV_VAR);
7680
return Boolean

jvm-runtime/plugin/common/error_detector.go jvm-runtime/plugin/common/jvm_logging.go

+53-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package common
22

33
import (
4+
"encoding/json"
45
"io"
56
"strings"
7+
"time"
68

79
"github.com/alecthomas/atomic"
810

@@ -49,8 +51,15 @@ func (o *errorDetector) Write(p []byte) (n int, err error) {
4951
o.logger.Tracef("%s", cleanLine)
5052
} else if cleanLine, ok := strings.CutPrefix(line, "FINE "); ok {
5153
o.logger.Tracef("%s", cleanLine)
54+
} else if line[0] == '{' {
55+
record := JvmLogRecord{}
56+
if err := json.Unmarshal([]byte(line), &record); err == nil {
57+
o.logger.Log(record.ToEntry())
58+
} else {
59+
o.logger.Infof("Log Parse Failure: %s", line) //nolint
60+
}
5261
} else {
53-
o.logger.Infof("%s", line)
62+
o.logger.Infof("%s", line) //nolint
5463
}
5564
}
5665
if !o.ended.Load() {
@@ -95,3 +104,46 @@ func (o *errorDetector) FinalizeCapture() []builderrors.Error {
95104
}
96105
return errs
97106
}
107+
108+
type JvmLogRecord struct {
109+
Timestamp time.Time `json:"timestamp"`
110+
Sequence int `json:"sequence"`
111+
LoggerClassName string `json:"loggerClassName"`
112+
LoggerName string `json:"loggerName"`
113+
Level string `json:"level"`
114+
Message string `json:"message"`
115+
ThreadName string `json:"threadName"`
116+
ThreadID int `json:"threadId"`
117+
Mdc any `json:"mdc"`
118+
Ndc string `json:"ndc"`
119+
HostName string `json:"hostName"`
120+
ProcessName string `json:"processName"`
121+
ProcessID int `json:"processId"`
122+
}
123+
124+
func (r *JvmLogRecord) ToEntry() log.Entry {
125+
level := log.Info
126+
switch r.Level {
127+
case "DEBUG":
128+
level = log.Debug
129+
case "INFO":
130+
level = log.Info
131+
case "WARN", "WARNING":
132+
level = log.Warn
133+
case "ERROR", "SEVERE":
134+
level = log.Error
135+
case "FINE", "FINER":
136+
level = log.Debug
137+
case "FINEST", "TRACE":
138+
level = log.Trace
139+
default:
140+
r.Message = r.Level + ": " + r.Message
141+
}
142+
143+
ret := log.Entry{
144+
Time: r.Timestamp,
145+
Level: level,
146+
Message: r.Message,
147+
}
148+
return ret
149+
}

jvm-runtime/plugin/common/jvmcommon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ func (s *Service) ModuleConfigDefaults(ctx context.Context, req *connect.Request
824824
defaults.DeployDir = "target"
825825
} else if fileExists(buildGradle) || fileExists(buildGradleKts) {
826826
defaults.LanguageConfig.Fields["build-tool"] = structpb.NewStringValue(JavaBuildToolGradle)
827-
defaults.DevModeBuild = ptr("gradle clean quarkusDev")
827+
defaults.DevModeBuild = ptr("gradle clean quarkusDev -Dquarkus.console.enabled=false")
828828
defaults.Build = ptr("gradle clean build")
829829
defaults.DeployDir = "build"
830830
} else {

0 commit comments

Comments
 (0)