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

logging in tview working

parent 30364212
Branches
Tags
3 merge requests!90Develop,!69Resolve "Stream logger-output to goSDN-tview via gRPC",!53V.0.1.0 Codename Threadbare
Pipeline #53087 passed
This commit is part of merge request !53. Comments created here will be created in the context of that merge request.
...@@ -32,7 +32,7 @@ var CommandList = []command{ ...@@ -32,7 +32,7 @@ var CommandList = []command{
//Connect creates a new connection to the gRPC server //Connect creates a new connection to the gRPC server
func Connect() (*grpc.ClientConn, error) { 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()) return grpc.Dial(address, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second), grpc.WithBlock())
} }
......
...@@ -8,9 +8,10 @@ package nucleus ...@@ -8,9 +8,10 @@ package nucleus
import ( import (
"context" "context"
"io"
"net" "net"
"os"
"sync" "sync"
"time"
pb "code.fbi.h-da.de/cocsn/gosdn/api/proto" pb "code.fbi.h-da.de/cocsn/gosdn/api/proto"
"code.fbi.h-da.de/cocsn/gosdn/log" "code.fbi.h-da.de/cocsn/gosdn/log"
...@@ -33,6 +34,17 @@ type server struct { ...@@ -33,6 +34,17 @@ type server struct {
logConnections []*LogConnection 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) { func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
log.Info("Received: ", in.GetName()) log.Info("Received: ", in.GetName())
return &pb.HelloReply{Message: "Hello " + in.GetName(), GoSDNInfo: "goSDN in version: DEVELOP"}, nil 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 ...@@ -88,6 +100,8 @@ func (s *server) Shutdown(ctx context.Context, in *pb.ShutdownRequest) (*pb.Shut
func getCLIGoing(core *Core) { func getCLIGoing(core *Core) {
var logConnections []*LogConnection var logConnections []*LogConnection
var logBuffer buf
log.Info("Starting: GetCLIGoing") log.Info("Starting: GetCLIGoing")
// Boot-up the control interface for the cli // Boot-up the control interface for the cli
cliControlListener, err := net.Listen("tcp", core.config.CliSocket) cliControlListener, err := net.Listen("tcp", core.config.CliSocket)
...@@ -96,18 +110,13 @@ func getCLIGoing(core *Core) { ...@@ -96,18 +110,13 @@ func getCLIGoing(core *Core) {
} }
cliControlServer := grpc.NewServer() 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! pb.RegisterGrpcCliServer(cliControlServer, srv)
go func() {
ticker := time.NewTicker(5 * time.Second)
for t := range ticker.C {
reply := pb.LogReply{Log: t.String()}
server.BroadcastLog(&reply)
}
}()
if err := cliControlServer.Serve(cliControlListener); err != nil { if err := cliControlServer.Serve(cliControlListener); err != nil {
log.Fatal(err) log.Fatal(err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment