-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User can now get agent logs inside the project with the agent logs command Signed-off-by: Toma Puljak <[email protected]>
- Loading branch information
Showing
10 changed files
with
160 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2024 Daytona Platforms Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package agent | ||
|
||
import ( | ||
"io" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type logFormatter struct { | ||
textFormatter *log.TextFormatter | ||
agentLogWriter io.Writer | ||
} | ||
|
||
func (f *logFormatter) Format(entry *log.Entry) ([]byte, error) { | ||
formatted, err := f.textFormatter.Format(entry) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if f.agentLogWriter != nil { | ||
_, err = f.agentLogWriter.Write(formatted) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
// Return the original message without log decoration | ||
// We don't want decoration to show up in the workspace creation logs | ||
return []byte(entry.Message), nil | ||
} | ||
|
||
func (s *Agent) initLogs() { | ||
logFormatter := &logFormatter{ | ||
textFormatter: &log.TextFormatter{ | ||
ForceColors: true, | ||
}, | ||
agentLogWriter: s.LogWriter, | ||
} | ||
|
||
log.SetFormatter(logFormatter) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2024 Daytona Platforms Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package agent | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/daytonaio/daytona/internal/util" | ||
"github.com/daytonaio/daytona/pkg/agent/config" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var followFlag bool | ||
|
||
var logsCmd = &cobra.Command{ | ||
Use: "logs", | ||
Short: "Output Daytona Agent logs", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
logFilePath := config.GetLogFilePath() | ||
|
||
if logFilePath == nil { | ||
log.Fatal("Log file path not set") | ||
} | ||
|
||
file, err := os.Open(*logFilePath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer file.Close() | ||
|
||
msgChan := make(chan []byte) | ||
errChan := make(chan error) | ||
|
||
go util.ReadLog(context.Background(), file, followFlag, msgChan, errChan) | ||
|
||
for { | ||
select { | ||
case <-context.Background().Done(): | ||
return | ||
case err := <-errChan: | ||
if err != nil { | ||
if err != io.EOF { | ||
log.Fatal(err) | ||
} | ||
return | ||
} | ||
case msg := <-msgChan: | ||
fmt.Println(string(msg)) | ||
} | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
logsCmd.Flags().BoolVarP(&followFlag, "follow", "f", false, "Follow logs") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters