Skip to content

Commit

Permalink
Update auto generated go snappi
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Mar 13, 2024
1 parent e2a692f commit 921b48e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 99 deletions.
25 changes: 0 additions & 25 deletions gosnappi/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/Masterminds/semver/v3"
"github.com/rs/zerolog"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -141,12 +140,6 @@ type api interface {
deprecated(message string)
under_review(message string)
addWarnings(message string)
SetLogger(logger zerolog.Logger)
SetLogLevel(loglevel zerolog.Level)
// By default choice is false which outputs the log to Console.
// To set output to file assign choice to true
// and to reset back to console set choice to false
SetLogOutputToFile(choice bool)
}

// NewGrpcTransport sets the underlying transport of the Api as grpc
Expand Down Expand Up @@ -203,24 +196,6 @@ func (api *apiSt) under_review(message string) {
logs.Warn().Msg(message)
}

func (api *apiSt) SetLogger(logger zerolog.Logger) {
SetUserLogger(logger)
}

func (api *apiSt) SetLogOutputToFile(choice bool) {
logs = SetUserLogOutputToFile(choice)
if choice {
logs.Info().Str("Logging to", "file - openapiartlog.log").Msg("")
} else {
logs.Info().Str("Logging to", "console").Msg("")
}
}

func (api *apiSt) SetLogLevel(logLevel zerolog.Level) {
SetUserLogLevel(logLevel)
logs.Info().Str("Log Level set to", logLevel.String()).Msg("")
}

// Returns instance of telemetry operations
func (api *apiSt) Telemetry() Telemetry {
return api.tracer
Expand Down
26 changes: 13 additions & 13 deletions gosnappi/gosnappi.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func NewApi() Api {
api := gosnappiApi{}
api.tracer = &telemetry{transport: "HTTP", serviceName: "go-snappi"}
api.versionMeta = &versionMeta{checkVersion: false}
logs = GetLogger("otg")
logs = getLogger("otg")
logs.Debug().Str("Logger Initialized", "log").Msg("")
return &api
}
Expand Down Expand Up @@ -401955,14 +401955,14 @@ type BgpAttributesCommunity interface {
Choice() BgpAttributesCommunityChoiceEnum
// setChoice assigns BgpAttributesCommunityChoiceEnum provided by user to BgpAttributesCommunity
setChoice(value BgpAttributesCommunityChoiceEnum) BgpAttributesCommunity
// getter for NoExportSubconfed to set choice.
NoExportSubconfed()
// getter for NoAdvertised to set choice.
NoAdvertised()
// getter for NoLlgr to set choice.
NoLlgr()
// getter for NoAdvertised to set choice.
NoAdvertised()
// getter for NoExport to set choice.
NoExport()
// getter for NoExportSubconfed to set choice.
NoExportSubconfed()
// getter for LlgrStale to set choice.
LlgrStale()
// CustomCommunity returns BgpAttributesCustomCommunity, set in BgpAttributesCommunity.
Expand Down Expand Up @@ -401999,26 +401999,26 @@ func (obj *bgpAttributesCommunity) Choice() BgpAttributesCommunityChoiceEnum {
return BgpAttributesCommunityChoiceEnum(obj.obj.Choice.Enum().String())
}

// getter for NoExportSubconfed to set choice
func (obj *bgpAttributesCommunity) NoExportSubconfed() {
obj.setChoice(BgpAttributesCommunityChoice.NO_EXPORT_SUBCONFED)
// getter for NoLlgr to set choice
func (obj *bgpAttributesCommunity) NoLlgr() {
obj.setChoice(BgpAttributesCommunityChoice.NO_LLGR)
}

// getter for NoAdvertised to set choice
func (obj *bgpAttributesCommunity) NoAdvertised() {
obj.setChoice(BgpAttributesCommunityChoice.NO_ADVERTISED)
}

// getter for NoLlgr to set choice
func (obj *bgpAttributesCommunity) NoLlgr() {
obj.setChoice(BgpAttributesCommunityChoice.NO_LLGR)
}

// getter for NoExport to set choice
func (obj *bgpAttributesCommunity) NoExport() {
obj.setChoice(BgpAttributesCommunityChoice.NO_EXPORT)
}

// getter for NoExportSubconfed to set choice
func (obj *bgpAttributesCommunity) NoExportSubconfed() {
obj.setChoice(BgpAttributesCommunityChoice.NO_EXPORT_SUBCONFED)
}

// getter for LlgrStale to set choice
func (obj *bgpAttributesCommunity) LlgrStale() {
obj.setChoice(BgpAttributesCommunityChoice.LLGR_STALE)
Expand Down
110 changes: 57 additions & 53 deletions gosnappi/loggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,113 +11,117 @@ import (
"gopkg.in/natefinch/lumberjack.v2"
)

type openapiartlog struct {
RootDir *string
LogDir *string
Debug *bool
DisableStdOutLogging *bool
MaxLogSizeMB *int
MaxLogBackups *int
type logInfo struct {
rootDir *string
logDir *string
maxLogSizeMB *int
maxLogBackups *int
}

var (
Openapiartlog *openapiartlog
GlobalLogger *zerolog.Logger
GlobalLogLevel zerolog.Level = zerolog.InfoLevel
LoggerFile bool = false
LogFileName string
GlobalCtx string
logSt *logInfo
Logger *zerolog.Logger
logLevel zerolog.Level = zerolog.InfoLevel
logToFile bool = false
logFileName string
ModuleName string
)

func initOpenapiartlog() error {
Openapiartlog = &openapiartlog{
RootDir: new(string),
LogDir: new(string),
MaxLogSizeMB: new(int),
MaxLogBackups: new(int),
func initlog() error {
logSt = &logInfo{
rootDir: new(string),
logDir: new(string),
maxLogSizeMB: new(int),
maxLogBackups: new(int),
}
*Openapiartlog.MaxLogSizeMB = 25
*Openapiartlog.MaxLogBackups = 5
if *Openapiartlog.RootDir = os.Getenv("SRC_ROOT"); *Openapiartlog.RootDir == "" {
*Openapiartlog.RootDir = "."
*logSt.maxLogSizeMB = 25
*logSt.maxLogBackups = 5
if *logSt.rootDir = os.Getenv("SRC_ROOT"); *logSt.rootDir == "" {
*logSt.rootDir = "."
}
*Openapiartlog.LogDir = path.Join(*Openapiartlog.RootDir, "logs")
GlobalLogger = nil
GlobalCtx = ""
*logSt.logDir = path.Join(*logSt.rootDir, "logs")
Logger = nil
ModuleName = ""
return nil
}

func SetUserLogger(logger zerolog.Logger) {
GlobalLogger = &logger
func SetLogger(usrDefinedLogger zerolog.Logger) {
Logger = &usrDefinedLogger
}

func SetUserLogOutputToFile(choice bool) zerolog.Logger {
LoggerFile = choice
return GetLogger(GlobalCtx)
func SetLogOutputToFile(choice bool) zerolog.Logger {
logToFile = choice
return getLogger(ModuleName)
}

func SetUserLogLevel(logLevel zerolog.Level) {
GlobalLogLevel = logLevel
RefreshLogLevel(GlobalLogLevel)
func SetLogLevel(level zerolog.Level) {
logLevel = level
refreshLogLevel(logLevel)
}

func GetLogger(ctx string) zerolog.Logger {
if GlobalCtx == "" {
if err := initOpenapiartlog(); err != nil {
func SetLogFileName(fileName string) {
logFileName = fileName
}

func getLogger(name string) zerolog.Logger {
if ModuleName == "" {
if err := initlog(); err != nil {
panic(fmt.Errorf("Logger helper set failed: %v", err))
}
}
GlobalCtx = ctx
LogFileName = ctx
ModuleName = name
if logFileName == "" {
logFileName = name
}
var localLogger zerolog.Logger
if !LoggerFile {
if !logToFile {
zerolog.TimestampFunc = func() time.Time {
return time.Now().In(time.Local)
}
zerolog.TimeFieldFormat = time.RFC3339Nano
consoleWriter := zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: "2006-1-02T15:04:05.000Z"}
localLogger = zerolog.New(consoleWriter).Level(GlobalLogLevel).With().Timestamp().Str("Module", ctx).Logger()
localLogger = zerolog.New(consoleWriter).Level(logLevel).With().Timestamp().Str("Module", name).Logger()

} else {
if err := initFileLogger(); err != nil {
panic(fmt.Errorf("Logger init failed: %v", err))
}
localLogger = log.With().Str("Module", ctx).Logger()
localLogger = log.With().Str("Module", name).Logger()
}
GlobalLogger = &localLogger
return *GlobalLogger
Logger = &localLogger
return *Logger
}

func initLogger() (err error) {
writer := lumberjack.Logger{
Filename: path.Join(*Openapiartlog.LogDir, fmt.Sprintf("%s.log", LogFileName)),
MaxSize: *Openapiartlog.MaxLogSizeMB,
MaxBackups: *Openapiartlog.MaxLogBackups,
Filename: path.Join(*logSt.logDir, fmt.Sprintf("%s.log", logFileName)),
MaxSize: *logSt.maxLogSizeMB,
MaxBackups: *logSt.maxLogBackups,
}
zerolog.TimestampFieldName = "ts"
zerolog.MessageFieldName = "msg"
zerolog.TimeFieldFormat = time.RFC3339Nano
log.Logger = zerolog.New(&writer).Level(GlobalLogLevel).With().Timestamp().Logger()
log.Logger = zerolog.New(&writer).Level(logLevel).With().Timestamp().Logger()
return err
}

func RefreshLogLevel(logLevel zerolog.Level) {
if !LoggerFile {
func refreshLogLevel(logLevel zerolog.Level) {
if !logToFile {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).Level(logLevel)
} else {
log.Logger = log.Level(logLevel)
}
}

func initFileLogger() (err error) {
if err = os.RemoveAll(*Openapiartlog.LogDir); err != nil {
if err = os.RemoveAll(*logSt.logDir); err != nil {

return err
}
if err = os.MkdirAll(*Openapiartlog.LogDir, os.ModePerm); err != nil {
if err = os.MkdirAll(*logSt.logDir, os.ModePerm); err != nil {
return err
}
if err := os.Chmod(*Openapiartlog.LogDir, 0771); err != nil {
if err := os.Chmod(*logSt.logDir, 0771); err != nil {
return err
}
return initLogger()
Expand Down
4 changes: 2 additions & 2 deletions gosnappi/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ func (t *telemetry) Start() (Telemetry, error) {
func (t *telemetry) Stop() {
if t.isOTLPEnabled() {
if err := t.traceProvider.Shutdown(context.Background()); err != nil {
GlobalLogger.Error().Msg("Failed shutting down trace provider")
logs.Error().Msg("Failed shutting down trace provider")
}
GlobalLogger.Info().Msg("Stopping tracing")
logs.Info().Msg("Stopping tracing")
}
}

Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--prefer-binary
protobuf~=3.15.0 ; python_version <= '3.6'
protobuf~=4.23.3 ; python_version > '3.6'
grpcio-tools~=1.54.2 ; python_version > '3.6'
grpcio~=1.35.0 ; python_version <= '3.6'
requests
grpcio~=1.54.2 ; python_version > '3.6'
grpcio~=1.35.0 ; python_version <= '3.6'
grpcio-tools~=1.54.2 ; python_version > '3.6'
grpcio-tools~=1.35.0 ; python_version <= '3.6'
PyYAML
requests
semantic_version
protobuf~=4.23.3 ; python_version > '3.6'
protobuf~=3.15.0 ; python_version <= '3.6'
urllib3
semantic_version

0 comments on commit 921b48e

Please sign in to comment.