清理日志输出

Signed-off-by: Chenyang Gao <gps949@outlook.com>
This commit is contained in:
Chenyang Gao
2023-05-16 11:34:34 +08:00
parent ed6b62a1f9
commit 7e14829a0e
11 changed files with 18 additions and 54 deletions

View File

@@ -73,7 +73,7 @@ func (c *Cockpit) BuildLinuxClient() {
return
}
} else if strings.Contains(sysCfg.ClientVersion.Linux.BuildState, "成功") {
log.Info().Caller().Msg("已成功构建过同样Hash版本无需重复构建")
log.Info().Msg("已成功构建过同样Hash版本无需重复构建")
return
} else {
c.markLinuxInBuilding(sysCfg) //进入构建状态
@@ -114,7 +114,7 @@ func (c *Cockpit) BuildLinuxClient() {
}
lines := strings.Split(out.String(), "\n")
shortVersion := strings.Split(lines[len(lines)-3], "=")[1]
log.Info().Caller().Msg("Linux客户端构建成功! 版本号:" + shortVersion)
log.Info().Msg("Linux客户端构建成功! 版本号:" + shortVersion)
// 检查发布路径情况
_, err = os.Stat("download")

View File

@@ -192,7 +192,6 @@ func (h *Mirage) ConsoleAuth(next http.Handler) http.Handler {
controlCodeC, controcontrolCodeExpiration, ok := h.controlCodeCache.GetWithExpiration(controlCodeCookie.Value)
if !ok || controcontrolCodeExpiration.Compare(time.Now()) != 1 {
log.Debug().
Caller().
Msg("could not verifyIDTokenForOIDCCallback")
nextURL := r.URL.Path
newQuery := r.URL.Query()
@@ -205,7 +204,6 @@ func (h *Mirage) ConsoleAuth(next http.Handler) http.Handler {
user, err := h.GetUserByID(controlCodeItem.uid)
if err != nil {
log.Debug().
Caller().
Msg("could not verifyIDTokenForOIDCCallback")
nextURL := r.URL.Path
newQuery := r.URL.Query()
@@ -246,7 +244,6 @@ func (h *Mirage) APIAuth(next http.Handler) http.Handler {
controlCodeC, controcontrolCodeExpiration, ok := h.controlCodeCache.GetWithExpiration(controlCodeCookie.Value)
if !ok || controcontrolCodeExpiration.Compare(time.Now()) != 1 {
log.Debug().
Caller().
Msg("could not verifyIDTokenForOIDCCallback")
renderData := APICheckRes{
NeedReauth: true,
@@ -261,7 +258,6 @@ func (h *Mirage) APIAuth(next http.Handler) http.Handler {
user, err := h.GetUserByID(controlCodeItem.uid)
if err != nil {
log.Debug().
Caller().
Msg("could not verifyIDTokenForOIDCCallback")
renderData := APICheckRes{
NeedReauth: true,
@@ -274,7 +270,6 @@ func (h *Mirage) APIAuth(next http.Handler) http.Handler {
}
if user.Role != RoleOwner {
log.Debug().
Caller().
Msg("非管理员用户访问API")
renderData := APICheckRes{
NeedReauth: true,
@@ -297,7 +292,6 @@ func (h *Mirage) deviceRegPortal(
aCode, ok := vars["aCode"]
log.Debug().
Caller().
Str("ACode", aCode).
Bool("ok", ok).
Msg("Received oidc register call")
@@ -391,7 +385,6 @@ func (h *Mirage) deviceReg(
aCode, ok := vars["aCode"]
log.Debug().
Caller().
Str("ACode", aCode).
Bool("ok", ok).
Msg("Received connect device call")
@@ -834,7 +827,6 @@ func (h *Mirage) registerMachineFromConsole(
if oldmachine != nil {
log.Trace().
Caller().
Str("machine", oldmachine.Hostname).
Msg("machine already registered, reauthenticating")
oldmachine.Hostname = aCodeItem.regReq.Hostinfo.Hostname

View File

@@ -199,7 +199,6 @@ func getFilteredByACLPeers(
machine *Machine,
) (Machines, []tailcfg.NodeID) {
log.Trace().
Caller().
Str("machine", machine.Hostname).
Msg("Finding peers filtered by ACLs")
@@ -271,7 +270,6 @@ func getFilteredByACLPeers(
)
log.Trace().
Caller().
Str("machine", machine.Hostname).
Msgf("Found some machines: %v", machines)
@@ -280,7 +278,6 @@ func getFilteredByACLPeers(
func (h *Mirage) ListPeers(machine *Machine) (Machines, error) {
log.Trace().
Caller().
Str("machine", machine.Hostname).
Msg("Finding direct peers")
@@ -313,7 +310,6 @@ func (h *Mirage) ListPeers(machine *Machine) (Machines, error) {
sort.Slice(machines, func(i, j int) bool { return machines[i].ID < machines[j].ID })
log.Trace().
Caller().
Str("machine", machine.Hostname).
Msgf("Found peers: %s", machines.String())
@@ -358,7 +354,6 @@ func (h *Mirage) getPeers(machine *Machine) (Machines, []tailcfg.NodeID, error)
sort.Slice(peers, func(i, j int) bool { return peers[i].ID < peers[j].ID })
log.Trace().
Caller().
Str("machine", machine.Hostname).
Msgf("Found total peers: %s", peers.String())
@@ -858,7 +853,6 @@ func (h *Mirage) isOutdated(machine *Machine) bool {
lastUpdate = *machine.LastSuccessfulUpdate
}
log.Trace().
Caller().
Str("machine", machine.Hostname).
Time("last_successful_update", lastChange).
Time("last_state_change", lastUpdate).
@@ -922,7 +916,6 @@ func (h *Mirage) toNode(
err := nodeKey.UnmarshalText([]byte(NodePublicKeyEnsurePrefix(machine.NodeKey)))
if err != nil {
log.Trace().
Caller().
Str("node_key", machine.NodeKey).
Msgf("Failed to parse node public key from hex")
@@ -1121,7 +1114,6 @@ func (h *Mirage) RegisterMachine(machine Machine,
}
log.Trace().
Caller().
Str("machine", machine.Hostname).
Str("machine_key", machine.MachineKey).
Str("node_key", machine.NodeKey).
@@ -1152,7 +1144,6 @@ func (h *Mirage) RegisterMachine(machine Machine,
}
log.Trace().
Caller().
Str("machine", machine.Hostname).
Str("ip", strings.Join(ips.ToStringSlice(), ",")).
Msg("Machine registered with the database")

View File

@@ -50,7 +50,7 @@ func (h *Mirage) NoiseUpgradeHandler(
writer http.ResponseWriter,
req *http.Request,
) {
log.Trace().Caller().Msgf("Noise upgrade handler for client %s", req.RemoteAddr)
log.Trace().Msgf("Noise upgrade handler for client %s", req.RemoteAddr)
upgrade := req.Header.Get("Upgrade")
if upgrade == "" {
@@ -123,14 +123,12 @@ func (h *Mirage) NoiseUpgradeHandler(
func (ns *noiseServer) earlyNoise(protocolVersion int, writer io.Writer) error {
log.Trace().
Caller().
Int("protocol_version", protocolVersion).
Str("challenge", ns.challenge.Public().String()).
Msg("earlyNoise called")
if protocolVersion < earlyNoiseCapabilityVersion {
log.Trace().
Caller().
Msgf("protocol version %d does not support early noise", protocolVersion)
return nil

View File

@@ -42,8 +42,8 @@ func (h *Mirage) initOIDC() error {
if err != nil {
log.Error().
Err(err).
Caller().
Err(err).
Msgf("Could not retrieve OIDC Config: %s", err.Error())
return err
@@ -101,8 +101,8 @@ func (h *Mirage) getIDTokenForOIDCCallback(
oauth2Token, err := h.oauth2Config.Exchange(ctx, code)
if err != nil {
log.Error().
Err(err).
Caller().
Err(err).
Msg("Could not exchange code for token")
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
writer.WriteHeader(http.StatusBadRequest)
@@ -118,7 +118,6 @@ func (h *Mirage) getIDTokenForOIDCCallback(
}
log.Trace().
Caller().
Str("code", code).
Str("state", state).
Msg("Got oidc callback")
@@ -150,8 +149,8 @@ func (h *Mirage) verifyIDTokenForOIDCCallback(
idToken, err := verifier.Verify(ctx, rawIDToken)
if err != nil {
log.Error().
Err(err).
Caller().
Err(err).
Msg("failed to verify id token")
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
writer.WriteHeader(http.StatusBadRequest)
@@ -176,8 +175,8 @@ func extractIDTokenClaims(
var claims IDTokenClaims
if err := idToken.Claims(&claims); err != nil {
log.Error().
Err(err).
Caller().
Err(err).
Msg("Failed to decode id token claims")
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
writer.WriteHeader(http.StatusBadRequest)

View File

@@ -117,7 +117,6 @@ func (h *Mirage) handleRegisterCommon(
aCode := registerRequest.Followup[len(registerRequest.Followup)-12:]
if _, ok := h.aCodeCache.Get(aCode); ok {
log.Debug().
Caller().
Str("machine", registerRequest.Hostinfo.Hostname).
Str("machine_key", machineKey.ShortString()).
Str("node_key", registerRequest.NodeKey.ShortString()).
@@ -141,8 +140,7 @@ func (h *Mirage) handleRegisterCommon(
}
}
log.Info().
Caller().
log.Debug().
Str("machine", registerRequest.Hostinfo.Hostname).
Str("machine_key", machineKey.ShortString()).
Str("node_key", registerRequest.NodeKey.ShortString()).
@@ -156,7 +154,7 @@ func (h *Mirage) handleRegisterCommon(
// 创建aCode缓存用来后续注册使用
// 因为过期时间取决于用户的过期设置,故此处不必记录!
// TODO: 创建ACode时是否要记录MachineKey
log.Debug().Caller().Str("machine", registerRequest.Hostinfo.Hostname).Msg("The node seems to be new, sending auth url")
log.Debug().Str("machine", registerRequest.Hostinfo.Hostname).Msg("The node seems to be new, sending auth url")
aCode := h.GenACode()
stateCode := h.GenStateCode()
h.aCodeCache.Set(
@@ -245,7 +243,7 @@ func (h *Mirage) sendLoginSuccess(
log.Error().Caller().Err(err).Msg("Failed to write response")
}
log.Info().Caller().Msg("Successfully Empty authURL")
log.Trace().Msg("Successfully Empty authURL")
}
// cgao6: 替代handleNewMachineCommon处理新设备注册变更了返回值
@@ -277,7 +275,7 @@ func (h *Mirage) SendACode(
log.Error().Caller().Err(err).Msg("Failed to write response")
}
log.Debug().Caller().Str("AuthURL", resp.AuthURL).Str("machine", registerRequest.Hostinfo.Hostname).Msg("Successfully sent auth url")
log.Debug().Str("AuthURL", resp.AuthURL).Str("machine", registerRequest.Hostinfo.Hostname).Msg("Successfully sent auth url")
}
// handleAuthKeyCommon contains the logic to manage auth key client registration
@@ -352,7 +350,6 @@ func (h *Mirage) handleAuthKeyCommon(
machine, _ := h.GetUserMachineByMachineKey(machineKey, pak.User.toTailscaleUser().ID)
if machine != nil {
log.Trace().
Caller().
Str("machine", machine.Hostname).
Msg("machine was already registered before, refreshing with new auth key")
@@ -541,7 +538,6 @@ func (h *Mirage) handleMachineLogOutCommon(
h.NotifyNaviOrgNodesChange(machine.User.OrganizationID, "", machine.NodeKey)
log.Info().
Caller().
Str("machine", machine.Hostname).
Msg("Successfully logged out")
}
@@ -555,7 +551,6 @@ func (h *Mirage) handleMachineValidRegistrationCommon(
// The machine registration is valid, respond with redirect to /map
log.Debug().
Caller().
Str("machine", machine.Hostname).
Msg("Client is registered and we have the current NodeKey. All clear to /map")
@@ -586,7 +581,6 @@ func (h *Mirage) handleMachineValidRegistrationCommon(
}
log.Info().
Caller().
Str("machine", machine.Hostname).
Msg("Machine successfully authorized")
}

View File

@@ -148,7 +148,6 @@ func (h *Mirage) handlePollCommon(
// Only create update channel if it has not been created
log.Trace().
Caller().
Str("machine", machine.Hostname).
Msg("Loading or creating update channel")

View File

@@ -16,7 +16,7 @@ func (t *noiseServer) NoiseRegistrationHandler(
writer http.ResponseWriter,
req *http.Request,
) {
log.Trace().Caller().Msgf("Noise registration handler for client %s", req.RemoteAddr)
log.Trace().Msgf("Noise registration handler for client %s", req.RemoteAddr)
if req.Method != http.MethodPost {
http.Error(writer, "Wrong method", http.StatusMethodNotAllowed)
@@ -60,7 +60,7 @@ func (m *Mirage) handleRegisterNavi(
registerRequest tailcfg.RegisterRequest,
naviKey key.MachinePublic,
) {
log.Trace().Caller().Msgf("Noise registration handler for Navi %s", req.RemoteAddr)
log.Trace().Msgf("Noise registration handler for Navi %s", req.RemoteAddr)
node := m.GetNaviNode(registerRequest.Auth.LoginName)
if node == nil {
@@ -76,7 +76,7 @@ func (m *Mirage) handleRegisterNavi(
http.Error(writer, "Internal error", http.StatusInternalServerError)
return
}
log.Trace().Caller().Msgf("Navi node %s registered", node.ID)
log.Trace().Msgf("Navi node %s registered", node.ID)
trustNodesKeys, err := m.getOrgNodesKey(node.NaviRegion.OrgID)
if err != nil {
@@ -145,7 +145,7 @@ func (t *noiseServer) NoiseNaviPollNodesListHandler(
writer http.ResponseWriter,
req *http.Request,
) {
log.Trace().Caller().Msgf("Noise NodesListPoll handler for Navi %s", req.RemoteAddr)
log.Trace().Msgf("Noise NodesListPoll handler for Navi %s", req.RemoteAddr)
if req.Method != http.MethodPost {
http.Error(writer, "Wrong method", http.StatusMethodNotAllowed)

2
go.mod
View File

@@ -25,7 +25,6 @@ require (
github.com/robfig/cron/v3 v3.0.1
github.com/rs/zerolog v1.29.1
github.com/samber/lo v1.38.1
github.com/sirupsen/logrus v1.9.0
github.com/spf13/viper v1.15.0
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a
go4.org/netipx v0.0.0-20230303233057-f1b76eb4bb35
@@ -138,7 +137,6 @@ require (
require (
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 // indirect
github.com/bwmarrin/snowflake v0.3.0
github.com/efekarakus/termcolor v1.0.1
github.com/elastic/go-elasticsearch/v8 v8.7.1
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/glebarez/sqlite v1.8.0

7
go.sum
View File

@@ -168,8 +168,6 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/efekarakus/termcolor v1.0.1 h1:YAKFO3bnLrqZGTWyNLcYoSIAQFKVOmbqmDnwsU/znzg=
github.com/efekarakus/termcolor v1.0.1/go.mod h1:AitrZNrE4nPO538fRsqf+p0WgLdAsGN5pUNrHEPsEMM=
github.com/elastic/elastic-transport-go/v8 v8.2.0 h1:hkK5IIs/15mpSXzd5THWVlWTKJyMw6cbCWM3T/B2S5E=
github.com/elastic/elastic-transport-go/v8 v8.2.0/go.mod h1:87Tcz8IVNe6rVSLdBux1o/PEItLtyabHU3naC7IoqKI=
github.com/elastic/go-elasticsearch/v8 v8.7.1 h1:UxK46XnlVANUjEAR8WdPSZwk5KacFTtO0xt2CGa+H6Y=
@@ -410,7 +408,6 @@ github.com/mattermost/xml-roundtrip-validator v0.1.0/go.mod h1:qccnGMcpgwcNaBnxq
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
@@ -515,7 +512,6 @@ github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFR
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.1.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
@@ -755,8 +751,6 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -789,7 +783,6 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

View File

@@ -21,7 +21,7 @@ func main() {
}
zerolog.TimeFieldFormat = MirageDateTimeFormat
logger := zerolog.New(zerolog.MultiLevelWriter(os.Stdout)).With().Caller().Timestamp().Logger()
logger := zerolog.New(zerolog.MultiLevelWriter(os.Stdout)).With().Timestamp().Logger()
logger = logger.Level(zerolog.DebugLevel)
log.Logger = logger
@@ -44,7 +44,7 @@ func main() {
go cockpit.Run()
log.Info().Caller().Msg("Cockpit is ready on " + sysAddr + "")
log.Info().Msg("Cockpit is ready on " + sysAddr + "")
/*
err = controller.LoadConfig()
@@ -60,7 +60,7 @@ func main() {
for {
select {
case cockpitMsg := <-ctrlChn:
log.Trace().Caller().Msgf("Cockpit message received: %s", cockpitMsg.Msg)
log.Trace().Msgf("Cockpit message received: %s", cockpitMsg.Msg)
switch cockpitMsg.Msg {
case "start":
err = datapool.InitMirageDB()