X-Git-Url: https://ruderich.org/simon/gitweb/?p=safcm%2Fsafcm.git;a=blobdiff_plain;f=cmd%2Fsafcm%2Fsync.go;h=65745af55a68367d1fd4a2625f44cf3901bdb6b2;hp=2f297c8dc69288aa4017f57d4e741562740784d9;hb=99d753741e5b6dc86b032882541c9b8f45a51bd4;hpb=cd7436284aa538d6a8a83811a33b3a3cc32d87a3 diff --git a/cmd/safcm/sync.go b/cmd/safcm/sync.go index 2f297c8..65745af 100644 --- a/cmd/safcm/sync.go +++ b/cmd/safcm/sync.go @@ -105,7 +105,7 @@ func MainSync(args []string) error { loop := &frontend.Loop{ DebugConn: cfg.LogLevel >= safcm.LogDebug3, LogEventFunc: func(x frontend.Event, failed *bool) { - logEvent(x, cfg.LogLevel, isTTY, failed) + frontend.LogEvent(x, cfg.LogLevel, isTTY, failed) }, SyncHostFunc: func(conn *rpc.Conn, host frontend.Host) error { return host.(*Sync).Host(conn) @@ -213,66 +213,6 @@ are only available after the hosts were contacted. return res, nil } -func logEvent(x frontend.Event, level safcm.LogLevel, isTTY bool, failed *bool) { - // We have multiple event sources so this is somewhat ugly. - var prefix, data string - var color frontend.Color - if x.Error != nil { - prefix = "[error]" - data = x.Error.Error() - color = frontend.ColorRed - // We logged an error, tell the caller - *failed = true - } else if x.Log.Level != 0 { - if level < x.Log.Level { - return - } - // LogError and LogDebug3 should not occur here - switch x.Log.Level { - case safcm.LogInfo: - prefix = "[info]" - case safcm.LogVerbose: - prefix = "[verbose]" - case safcm.LogDebug: - prefix = "[debug]" - case safcm.LogDebug2: - prefix = "[debug2]" - default: - prefix = fmt.Sprintf("[INVALID=%d]", x.Log.Level) - color = frontend.ColorRed - } - data = x.Log.Text - } else { - switch x.ConnEvent.Type { - case rpc.ConnEventStderr: - prefix = "[stderr]" - case rpc.ConnEventDebug: - prefix = "[debug3]" - case rpc.ConnEventUpload: - if level < safcm.LogInfo { - return - } - prefix = "[info]" - x.ConnEvent.Data = "remote helper upload in progress" - default: - prefix = fmt.Sprintf("[INVALID=%d]", x.ConnEvent.Type) - color = frontend.ColorRed - } - data = x.ConnEvent.Data - } - - host := x.Host.Name() - if color != 0 { - host = frontend.ColorString(isTTY, color, host) - } - // Make sure to escape control characters to prevent terminal - // injection attacks - if !x.Escaped { - data = frontend.EscapeControlCharacters(isTTY, data) - } - log.Printf("%-9s [%s] %s", prefix, host, data) -} - func (s *Sync) Name() string { return s.host.Name }