X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/522d7fd117285e4e4ce3ea5ec9b5a1722521b681..88581c0765be50dcabcc2913c38ae6786c426a3a:/daemon.go diff --git a/daemon.go b/daemon.go index 5ec220e..ef73896 100644 --- 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() -}