Skip to content

Commit

Permalink
refactor: Generalize LoggingClient interface
Browse files Browse the repository at this point in the history
closes #976

Signed-off-by: Jack Chen <[email protected]>
  • Loading branch information
jackchenjc committed Feb 10, 2025
1 parent ed67b12 commit 618face
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions clients/logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*******************************************************************************
* Copyright 2019 Dell Inc.
* Copyright (C) 2025 IOTech Ltd
*
* 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
Expand All @@ -25,7 +26,6 @@ import (
stdLog "log"
"os"

"github.com/edgexfoundry/go-mod-core-contracts/v4/errors"
"github.com/edgexfoundry/go-mod-core-contracts/v4/models"

"github.com/go-kit/log"
Expand All @@ -35,7 +35,7 @@ import (
type LoggingClient interface {
// SetLogLevel sets minimum severity log level. If a logging method is called with a lower level of severity than
// what is set, it will result in no output.
SetLogLevel(logLevel string) errors.EdgeX
SetLogLevel(logLevel string) error
// LogLevel returns the current log level setting
LogLevel() string
// Debug logs a message at the DEBUG severity level
Expand Down Expand Up @@ -151,14 +151,14 @@ func (lc edgeXLogger) log(logLevel string, formatted bool, msg string, args ...i

}

func (lc edgeXLogger) SetLogLevel(logLevel string) errors.EdgeX {
func (lc edgeXLogger) SetLogLevel(logLevel string) error {
if isValidLogLevel(logLevel) {
*lc.logLevel = logLevel

return nil
}

return errors.NewCommonEdgeX(errors.KindContractInvalid, fmt.Sprintf("invalid log level `%s`", logLevel), nil)
return fmt.Errorf("invalid log level `%s`", logLevel)
}

func (lc edgeXLogger) LogLevel() string {
Expand Down
5 changes: 2 additions & 3 deletions clients/logger/mock-logger.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*******************************************************************************
* Copyright 2019 Dell Inc.
* Copyright (C) 2025 IOTech Ltd
*
* 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
Expand All @@ -14,8 +15,6 @@

package logger

import "github.com/edgexfoundry/go-mod-core-contracts/v4/errors"

// MockLogger is a type that can be used for mocking the LoggingClient interface during unit tests
type MockLogger struct {
}
Expand All @@ -26,7 +25,7 @@ func NewMockClient() LoggingClient {
}

// SetLogLevel simulates setting a log severity level
func (lc MockLogger) SetLogLevel(_ string) errors.EdgeX {
func (lc MockLogger) SetLogLevel(_ string) error {
return nil
}

Expand Down
37 changes: 19 additions & 18 deletions clients/logger/mocks/LoggingClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 618face

Please sign in to comment.