forked from networkservicemesh/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Console logging update (networkservicemesh#567)
* Update to console loggin + A Bit more compact and clear Signed-off-by: Andrey Sobolev <haiodo@gmail.com> * A complet log reduction A complet log reduction Signed-off-by: Andrey Sobolev <haiodo@gmail.com> * Review and bug fixing Review and bug fixing Signed-off-by: Andrey Sobolev <haiodo@gmail.com> * Network service registry set log options Network service registry set log options Signed-off-by: Andrey Sobolev <haiodo@gmail.com> Signed-off-by: Sergey Ershov <sergey.ershov@xored.com>
- Loading branch information
Showing
14 changed files
with
412 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2020 Doc.ai and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package setlogoption - allow to overide some of logging capabilities. | ||
package setlogoption | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/golang/protobuf/ptypes/empty" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/tools/log" | ||
) | ||
|
||
type setLogOptionServer struct { | ||
options map[string]string | ||
server networkservice.NetworkServiceServer | ||
} | ||
|
||
// NewServer - construct a new set log option server to override some logging capabilities for context. | ||
func NewServer(options map[string]string, server networkservice.NetworkServiceServer) networkservice.NetworkServiceServer { | ||
return &setLogOptionServer{ | ||
options: options, | ||
server: server, | ||
} | ||
} | ||
|
||
func (s *setLogOptionServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { | ||
ctx = s.withFields(ctx) | ||
return s.server.Request(ctx, request) | ||
} | ||
|
||
func (s *setLogOptionServer) withFields(ctx context.Context) context.Context { | ||
fields := make(logrus.Fields) | ||
for k, v := range s.options { | ||
fields[k] = v | ||
} | ||
if len(fields) > 0 { | ||
ctx = log.WithFields(ctx, fields) | ||
} | ||
return ctx | ||
} | ||
|
||
func (s *setLogOptionServer) Close(ctx context.Context, connection *networkservice.Connection) (*empty.Empty, error) { | ||
ctx = s.withFields(ctx) | ||
return s.server.Close(ctx, connection) | ||
} |
Oops, something went wrong.