log.go 604 B

12345678910111213141516171819202122232425262728293031323334
  1. package rpc
  2. import (
  3. "io"
  4. "net"
  5. "fmt"
  6. )
  7. type ServerLogger struct {
  8. LocalAddr net.Addr
  9. RemoteAddr net.Addr
  10. Output io.Writer
  11. }
  12. func (l ServerLogger) LogError(err error) {
  13. if l.Output != nil {
  14. fmt.Fprintf(l.Output, "[RPC] [Server %s] client %s: Error: %s\n",
  15. l.LocalAddr, l.RemoteAddr, err.Error())
  16. }
  17. }
  18. type ClientLogger struct {
  19. LocalAddr net.Addr
  20. RemoteAddr net.Addr
  21. Output io.Writer
  22. }
  23. func (l ClientLogger) LogError(err error) {
  24. if l.Output != nil {
  25. fmt.Fprintf(l.Output, "[RPC] [Client %s] server %s: Error: %s\n",
  26. l.LocalAddr, l.RemoteAddr, err.Error())
  27. }
  28. }