github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/service/log.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package service
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"golang.org/x/net/context"
    10  
    11  	"github.com/keybase/client/go/libkb"
    12  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    13  	"github.com/keybase/go-framed-msgpack-rpc/rpc"
    14  )
    15  
    16  // LogHandler is the RPC handler for the log interface.
    17  type LogHandler struct {
    18  	*BaseHandler
    19  	logReg *logRegister
    20  	libkb.Contextified
    21  }
    22  
    23  // NewLogHandler creates a LogHandler for the xp transport.
    24  func NewLogHandler(xp rpc.Transporter, logReg *logRegister, g *libkb.GlobalContext) *LogHandler {
    25  	return &LogHandler{
    26  		BaseHandler:  NewBaseHandler(g, xp),
    27  		logReg:       logReg,
    28  		Contextified: libkb.NewContextified(g),
    29  	}
    30  }
    31  
    32  func (h *LogHandler) RegisterLogger(_ context.Context, arg keybase1.RegisterLoggerArg) (err error) {
    33  	defer h.G().Trace(fmt.Sprintf("LogHandler::RegisterLogger %+v", arg), &err)()
    34  
    35  	if h.logReg == nil {
    36  		// if not a daemon, h.logReg will be nil
    37  		h.G().Log.Debug("- logRegister is nil, ignoring RegisterLogger request")
    38  		return nil
    39  	}
    40  
    41  	ui := &LogUI{sessionID: arg.SessionID, cli: h.getLogUICli()}
    42  	err = h.logReg.RegisterLogger(arg, ui)
    43  	return err
    44  }
    45  
    46  func (h *LogHandler) PerfLogPoint(ctx context.Context, arg keybase1.PerfLogPointArg) (err error) {
    47  	defer h.G().Trace("LogHandler::PerfLogPoint", &err)()
    48  	h.G().PerfLog.CDebugf(ctx, arg.Msg)
    49  	return nil
    50  }