Skip to content
Snippets Groups Projects
Commit 9e2b2d61 authored by Malte Bauch's avatar Malte Bauch
Browse files

logging in tview working

parent 30364212
No related branches found
No related tags found
3 merge requests!90Develop,!69Resolve "Stream logger-output to goSDN-tview via gRPC",!53V.0.1.0 Codename Threadbare
Pipeline #53087 passed
......@@ -32,7 +32,7 @@ var CommandList = []command{
//Connect creates a new connection to the gRPC server
func Connect() (*grpc.ClientConn, error) {
address := "localhost:55055"
address := "141.100.70.170:55066"
return grpc.Dial(address, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second), grpc.WithBlock())
}
......
......@@ -8,9 +8,10 @@ package nucleus
import (
"context"
"io"
"net"
"os"
"sync"
"time"
pb "code.fbi.h-da.de/cocsn/gosdn/api/proto"
"code.fbi.h-da.de/cocsn/gosdn/log"
......@@ -33,6 +34,17 @@ type server struct {
logConnections []*LogConnection
}
var srv *server
type buf []byte
func (b *buf) Write(p []byte) (n int, err error) {
reply := pb.LogReply{Log: string(p)}
srv.BroadcastLog(&reply)
return len(p), nil
}
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
log.Info("Received: ", in.GetName())
return &pb.HelloReply{Message: "Hello " + in.GetName(), GoSDNInfo: "goSDN in version: DEVELOP"}, nil
......@@ -88,6 +100,8 @@ func (s *server) Shutdown(ctx context.Context, in *pb.ShutdownRequest) (*pb.Shut
func getCLIGoing(core *Core) {
var logConnections []*LogConnection
var logBuffer buf
log.Info("Starting: GetCLIGoing")
// Boot-up the control interface for the cli
cliControlListener, err := net.Listen("tcp", core.config.CliSocket)
......@@ -96,18 +110,13 @@ func getCLIGoing(core *Core) {
}
cliControlServer := grpc.NewServer()
server := &server{core: core, logConnections: logConnections}
srv = &server{core: core, logConnections: logConnections}
pb.RegisterGrpcCliServer(cliControlServer, server)
//TODO: move?
wrt := io.MultiWriter(os.Stdout, &logBuffer)
log.Output(wrt)
//TODO: remove!
go func() {
ticker := time.NewTicker(5 * time.Second)
for t := range ticker.C {
reply := pb.LogReply{Log: t.String()}
server.BroadcastLog(&reply)
}
}()
pb.RegisterGrpcCliServer(cliControlServer, srv)
if err := cliControlServer.Serve(cliControlListener); err != nil {
log.Fatal(err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment