Skip to content

Commit 7e615ab

Browse files
authored
✨ Follow full jdtls log with logLevel>6 (#1039)
When logLevel is over default 5, follow full jdtls log in order to provide full exhaustive java logging for possible debugging (which is filtered by default since it could be ~100MBs). Follow-up to #1038 Related to #1032 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Features** * Added a log level setting for the Java external provider to adjust verbosity and enable full log following at higher levels. * **Improvements** * Log tailing now uses workspace-relative log paths for more reliable discovery. * When full log following is enabled, the provider emits an informational message and logs all JDTLS lines; otherwise it filters for designated markers. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Marek Aufart <maufart@redhat.com> Signed-off-by: Marek Aufart <aufi.cz@gmail.com>
1 parent 629352f commit 7e615ab

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

external-providers/java-external-provider/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,19 @@ func main() {
3838
log := logrusr.New(logrusLog)
3939
log = log.WithName("java-provider")
4040

41+
// Get log level value
42+
logLevelValue := 5
43+
if logLevel != nil {
44+
logLevelValue = *logLevel
45+
}
46+
4147
// must use lspServerName for use of multiple grpc providers
42-
client := java.NewJavaProvider(log, *lspServerName, *contextLines, provider.Config{})
48+
client := java.NewJavaProvider(log, *lspServerName, *contextLines, logLevelValue, provider.Config{})
49+
50+
if logLevel != nil && *logLevel != 5 {
51+
logrusLog.SetLevel(logrus.Level(*logLevel))
52+
}
53+
4354
if (socket == nil || *socket == "") && (port == nil || *port == 0) {
4455
log.Error(fmt.Errorf("no serving location"), "port or socket must be set.")
4556
panic(1)

external-providers/java-external-provider/pkg/java_external_provider/provider.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ type javaProvider struct {
122122
depsLocationCache map[string]int
123123

124124
logFollow sync.Once
125+
logLevel int
125126
}
126127

127128
var _ provider.BaseClient = &javaProvider{}
@@ -151,7 +152,7 @@ type element struct {
151152
Value string `yaml:"value" json:"value"` // can be a (java) regex pattern
152153
}
153154

154-
func NewJavaProvider(log logr.Logger, lspServerName string, contextLines int, config provider.Config) *javaProvider {
155+
func NewJavaProvider(log logr.Logger, lspServerName string, contextLines int, logLevel int, config provider.Config) *javaProvider {
155156

156157
_, mvnBinaryError := exec.LookPath("mvn")
157158

@@ -165,6 +166,7 @@ func NewJavaProvider(log logr.Logger, lspServerName string, contextLines int, co
165166
contextLines: contextLines,
166167
encoding: "",
167168
logFollow: sync.Once{},
169+
logLevel: logLevel,
168170
}
169171
}
170172

@@ -565,7 +567,10 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
565567
// When running for long period of time.
566568
p.logFollow.Do(func() {
567569
go func() {
568-
t, err := tail.TailFile(".metadata/.log", tail.Config{
570+
// Determine the log file path relative to workspace
571+
logFilePath := filepath.Join(workspace, ".metadata", ".log")
572+
573+
t, err := tail.TailFile(logFilePath, tail.Config{
569574
ReOpen: true,
570575
MustExist: false,
571576
Follow: true,
@@ -576,8 +581,17 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
576581
return
577582
}
578583

584+
// If logLevel > 6, follow all JDTLS logs
585+
// Otherwise, only follow KONVEYOR_LOG tagged lines
586+
followAll := p.logLevel > 6
587+
if followAll {
588+
log.Info("following full JDTLS log", "path", logFilePath, "logLevel", p.logLevel)
589+
}
590+
579591
for line := range t.Lines {
580-
if strings.Contains(line.Text, "KONVEYOR_LOG") {
592+
if followAll {
593+
log.Info("language server log", "line", line.Text)
594+
} else if strings.Contains(line.Text, "KONVEYOR_LOG") {
581595
log.Info("language server log", "line", line.Text)
582596
}
583597
}

0 commit comments

Comments
 (0)