]> git.giacomolli.uk - onechat/blobdiff - daemon.go
Render Markdown with plain terminal styles
[onechat] / daemon.go
index 5ec220ed6d3f144db0805b2f3beb8a06da22ac96..ef738965898575d8b55b9113ae02ba8b08bb862d 100644 (file)
--- a/daemon.go
+++ b/daemon.go
@@ -7,7 +7,6 @@ import (
        "errors"
        "fmt"
        "io"
-       "log"
        "net"
        "os"
        "path/filepath"
@@ -111,19 +110,19 @@ func daemon(ctx context.Context, out io.Writer) (err error) {
                return err
        }
 
-       linked := "WhatsApp not linked"
+       linked := "not linked"
        if whatsapp.isLinked() {
-               linked = "WhatsApp linked"
+               linked = "linked"
        }
 
-       logger.Printf("ready: socket %s, model %s (%s), workdir %s, %s, %d schedules", listener.Addr(), agent.config.Model, agent.config.Effort, agent.config.Workdir, linked, schedules.Len())
+       logger.Info("ready", "socket", listener.Addr(), "model", agent.config.Model, "effort", agent.config.Effort, "workdir", agent.config.Workdir, "whatsapp", linked, "schedules", schedules.Len())
 
        var telegram *TelegramBot
 
        if hasBot {
                telegram = newTelegramBot(newTelegramAPI(telegramAPIURL, botSettings.Token), botSettings.Owner, filepath.Join(agent.dir, telegramOffsetFileName), daemonLogger(out, "telegram: "))
 
-               logger.Print("Telegram bot started")
+               logger.Info("Telegram bot started")
        }
 
        return daemonServe(ctx, listener, telegram, whatsapp, schedules, func(notify func(Event)) (*TurnLoop, error) {
@@ -443,25 +442,3 @@ func daemonRunRequest(l *TurnLoop, whatsapp *WhatsApp, request SocketRequest, an
                return fmt.Errorf("unknown request %q", request.Type)
        }
 }
-
-// daemonLogger returns the logger of the part of the daemon with prefix, such
-// as "telegram: ", on out. The journal adds the time to each line and sets
-// JOURNAL_STREAM for a service, so then the lines have no time stamp. Otherwise
-// each line has the standard time stamp.
-func daemonLogger(out io.Writer, prefix string) *log.Logger {
-       if os.Getenv("JOURNAL_STREAM") != "" {
-               return log.New(out, prefix, 0)
-       }
-
-       return log.New(out, prefix, log.LstdFlags)
-}
-
-// durationText returns d for a log line: rounded to the second, or to the
-// millisecond when it is shorter than a second.
-func durationText(d time.Duration) string {
-       if d < time.Second {
-               return d.Round(time.Millisecond).String()
-       }
-
-       return d.Round(time.Second).String()
-}