github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/service/log_ui.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  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    12  	"github.com/keybase/go-framed-msgpack-rpc/rpc"
    13  )
    14  
    15  type LogUI struct {
    16  	sessionID int
    17  	cli       *keybase1.LogUiClient
    18  }
    19  
    20  func NewLogUI(sessionID int, c *rpc.Client) *LogUI {
    21  	return &LogUI{
    22  		sessionID: sessionID,
    23  		cli:       &keybase1.LogUiClient{Cli: c},
    24  	}
    25  }
    26  
    27  func (l *LogUI) Log(level keybase1.LogLevel, format string, args []interface{}) {
    28  	msg := fmt.Sprintf(format, args...)
    29  	_ = l.cli.Log(context.TODO(), keybase1.LogArg{
    30  		SessionID: l.sessionID,
    31  		Level:     level,
    32  		Text: keybase1.Text{
    33  			Markup: false,
    34  			Data:   msg,
    35  		},
    36  	})
    37  }
    38  
    39  func (l *LogUI) Debug(format string, args ...interface{}) {
    40  	l.Log(keybase1.LogLevel_DEBUG, format, args)
    41  }
    42  func (l *LogUI) Info(format string, args ...interface{}) {
    43  	l.Log(keybase1.LogLevel_INFO, format, args)
    44  }
    45  func (l *LogUI) Critical(format string, args ...interface{}) {
    46  	l.Log(keybase1.LogLevel_CRITICAL, format, args)
    47  }
    48  func (l *LogUI) Warning(format string, args ...interface{}) {
    49  	l.Log(keybase1.LogLevel_WARN, format, args)
    50  }
    51  func (l *LogUI) Errorf(format string, args ...interface{}) {
    52  	l.Log(keybase1.LogLevel_ERROR, format, args)
    53  }
    54  func (l *LogUI) Notice(format string, args ...interface{}) {
    55  	l.Log(keybase1.LogLevel_NOTICE, format, args)
    56  }