mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
logs: stream corrosion logs with 'uc machine logs corrosion' from container instead of journal (fixes #392)
This commit is contained in:
@@ -10,31 +10,11 @@ import (
|
||||
"github.com/psviderski/uncloud/pkg/api"
|
||||
)
|
||||
|
||||
const (
|
||||
UnitUncloud = "uncloud"
|
||||
UnitDocker = "docker"
|
||||
UnitCorrosion = "uncloud-corrosion"
|
||||
)
|
||||
|
||||
func ValidUnit(unit string) bool {
|
||||
switch unit {
|
||||
case UnitUncloud:
|
||||
case UnitDocker:
|
||||
case UnitCorrosion:
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
const journalctl = "journalctl"
|
||||
|
||||
var commandContext = exec.CommandContext // allow override for test
|
||||
|
||||
func logs(ctx context.Context, unit string, opts api.ServiceLogsOptions) (io.ReadCloser, func() error, error) {
|
||||
if !ValidUnit(unit) {
|
||||
return nil, nil, fmt.Errorf("journal logs: invalid unit: %s", unit)
|
||||
}
|
||||
args := []string{"-u", unit, "--no-hostname"}
|
||||
args = append(args, "-n")
|
||||
if opts.Tail > -1 {
|
||||
|
||||
@@ -3,7 +3,6 @@ package journal
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -13,10 +12,6 @@ import (
|
||||
|
||||
// Logs streams logs from a service and returns entries via a channel.
|
||||
func Logs(ctx context.Context, unit string, opts api.ServiceLogsOptions) (<-chan api.LogEntry, error) {
|
||||
if !ValidUnit(unit) {
|
||||
return nil, fmt.Errorf("journal logs: invalid unit: %s", unit)
|
||||
}
|
||||
|
||||
reader, wait, err := logs(ctx, unit, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user