Skip to content

Commit

Permalink
Merge pull request #27 from backguynn/main
Browse files Browse the repository at this point in the history
add log verbose
  • Loading branch information
TrekkieCoder authored Aug 2, 2023
2 parents 831fa8f + 0a0fae9 commit a6056c2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/loxilb-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func newAgentCommand() *cobra.Command {
Long: "The loxilb agent runs on each node.",
Run: func(cmd *cobra.Command, args []string) {
log.InitLogFileLimits(cmd.Flags())
log.InitLogLevel(cmd.Flags())
if err := opts.complete(args); err != nil {
klog.Errorf("Failed to options complete. err: %v", err)
os.Exit(255)
Expand Down
42 changes: 42 additions & 0 deletions pkg/log/logLevel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2023 Netlox Authors
//
// 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 log

import (
"github.com/spf13/pflag"

"k8s.io/klog/v2"
)

const logVerbosityFlag = "v"

// GetCurrentLogLevel returns the current log verbosity level.
func GetCurrentLogLevel(fs *pflag.FlagSet) string {
return fs.Lookup(logVerbosityFlag).Value.String()
}

// InitLogLevel sets the log verbosity level when init time
func InitLogLevel(fs *pflag.FlagSet) error {
level := GetCurrentLogLevel(fs)

var l klog.Level
err := l.Set(level)
if err != nil {
return err
}

klog.Infof("Set log level to %s", level)
return nil
}

0 comments on commit a6056c2

Please sign in to comment.