grim/convey

Port from logrus to log/slog
default tip
5 months ago, Elliott Sales de Andrade
c588f9b3f559
Port from logrus to log/slog

This doesn't really take much advantage of structured logging beyond what is already done (`id` and `idColor`), and consequently the log handler does not try to do any handling of anything more than that (i.e., grouping, or arbitrary attributes beyond those defined).

One should maybe have a `Context` available to pass in, but there isn't one, and anyway, the log handler doesn't use it, so I've passed in a `TODO` instead.

Everything else is just normal import/rename changes.

Testing Done:
Ran `go run . run`

Reviewed at https://reviews.imfreedom.org/r/2871/
package environment
import (
"fmt"
"log/slog"
"os"
)
func (e Environment) expandMapper(name string) string {
// We might have something like $(pwd), in which case we don't want
// to wrap the name in `{}`, which would cause it to be ${}(pwd) and
// cannot be evaluated by a run task.
if name == "" {
return "$"
}
if val, found := e[name]; found {
if val != "" {
return val
}
return os.Getenv(name)
}
return ""
}
// Expand looks for the given key and returns the value if one is found
// recursing if the value contains another variable.
func (e Environment) Expand(key string) string {
last := os.Expand(key, e.expandMapper)
tries := 10
for i := 0; i < tries; i++ {
next := os.Expand(last, e.expandMapper)
if next == last {
return next
}
last = next
}
slog.Warn(fmt.Sprintf("failed to fully expand %q after %d recursions", key, tries))
return ""
}
func (e Environment) Expandv(items []string) []string {
expanded := make([]string, len(items))
for idx, item := range items {
expanded[idx] = e.Expand(item)
}
return expanded
}