Skip to content

Commit

Permalink
[TT-792] Makes 'file' Default Log Target (smartcontractkit#813)
Browse files Browse the repository at this point in the history
* Makes 'file' Default Log Target

* Better flow
  • Loading branch information
kalverra authored Jan 17, 2024
1 parent 27a179e commit 001c253
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions logstream/logstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (m *LogStream) ConnectContainer(ctx context.Context, container LogProducing
return err
}

m.log.Info().
m.log.Trace().
Str("Prefix", prefix).
Str("Name", name).
Str("Timeout", m.logProducerTimeout.String()).
Expand All @@ -227,7 +227,7 @@ func (m *LogStream) ConnectContainer(ctx context.Context, container LogProducing
err = container.StartLogProducer(ctx, m.logProducerTimeout)

go func(done chan struct{}, timeout time.Duration, retryLimit int) {
defer m.log.Info().Str("Container name", name).Msg("Disconnected container logs")
defer m.log.Trace().Str("Container name", name).Msg("Disconnected container logs")
currentAttempt := 1

var shouldRetry = func() bool {
Expand Down Expand Up @@ -437,7 +437,7 @@ func (m *LogStream) DisconnectContainer(container LogProducingContainer) error {
var err error

if container.IsRunning() {
m.log.Info().Str("container", container.GetContainerID()).Msg("Disconnecting container")
m.log.Trace().Str("container", container.GetContainerID()).Msg("Disconnecting container")
err = container.StopLogProducer()
}

Expand Down Expand Up @@ -564,10 +564,10 @@ func (m *LogStream) GetAllLogsAndConsume(preExecuteFn ConsumerConsumingFn, consu
break LOG_LOOP
}
} else if errors.Is(decodeErr, io.EOF) {
m.log.Info().
m.log.Debug().
Int("Log count", counter).
Str("Container", consumer.name).
Msg("Finished getting logs")
Msg("Finished collecting logs")
break
} else {
m.log.Error().
Expand Down Expand Up @@ -653,10 +653,10 @@ func (m *LogStream) FlushLogsToTargets() error {

flushErr := m.GetAllLogsAndConsume(preExecuteFn, flushLogsFn, postExecuteFn)
if flushErr == nil {
m.log.Info().
m.log.Debug().
Msg("Finished flushing logs")
} else {
m.log.Info().
m.log.Error().
Err(flushErr).
Msg("Failed to flush logs")
}
Expand Down Expand Up @@ -841,23 +841,22 @@ func (g *ContainerLogConsumer) hasLogTarget(logTarget LogTarget) bool {
// getLogTargetsFromEnv gets log targets from LOGSTREAM_LOG_TARGETS env var
func getLogTargetsFromEnv() ([]LogTarget, error) {
envLogTargetsValue := os.Getenv("LOGSTREAM_LOG_TARGETS")
if envLogTargetsValue != "" {
envLogTargets := make([]LogTarget, 0)
for _, target := range strings.Split(envLogTargetsValue, ",") {
switch strings.TrimSpace(strings.ToLower(target)) {
case "loki":
envLogTargets = append(envLogTargets, Loki)
case "file":
envLogTargets = append(envLogTargets, File)
case "in-memory":
envLogTargets = append(envLogTargets, InMemory)
default:
return []LogTarget{}, errors.Errorf("unknown log target: %s", target)
}
if envLogTargetsValue == "" {
// default log target is file
return []LogTarget{"file"}, nil
}
envLogTargets := make([]LogTarget, 0)
for _, target := range strings.Split(envLogTargetsValue, ",") {
switch strings.TrimSpace(strings.ToLower(target)) {
case "loki":
envLogTargets = append(envLogTargets, Loki)
case "file":
envLogTargets = append(envLogTargets, File)
case "in-memory":
envLogTargets = append(envLogTargets, InMemory)
default:
return []LogTarget{}, errors.Errorf("unknown log target: %s", target)
}

return envLogTargets, nil
}

return []LogTarget{}, nil
return envLogTargets, nil
}

0 comments on commit 001c253

Please sign in to comment.