forked from theupdateframework/go-tuf
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: logger rework (theupdateframework#58)
* feat(log): add global default logger Signed-off-by: Marvin Drees <[email protected]> * feat(log): exchange logger in library code Signed-off-by: Marvin Drees <[email protected]> * feat(log): remove logrus from testutil Signed-off-by: Marvin Drees <[email protected]> * feat(log): replace logrus in example code Signed-off-by: Marvin Drees <[email protected]> * chore(log): run go mod tidy for new logger Signed-off-by: Marvin Drees <[email protected]> * test: add tests for logger set/get functions Signed-off-by: Marvin Drees <[email protected]> --------- Signed-off-by: Marvin Drees <[email protected]>
- Loading branch information
Showing
17 changed files
with
240 additions
and
134 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 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
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
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,24 @@ | ||
// Copyright 2023 VMware, Inc. | ||
// | ||
// This product is licensed to you under the BSD-2 license (the "License"). | ||
// You may not use this product except in compliance with the BSD-2 License. | ||
// This product may include a number of subcomponents with separate copyright | ||
// notices and license terms. Your use of these subcomponents is subject to | ||
// the terms and conditions of the subcomponent's license, as noted in the | ||
// LICENSE file. | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
|
||
package metadata | ||
|
||
import "github.com/go-logr/logr" | ||
|
||
var log logr.Logger = logr.Discard() | ||
|
||
func SetLogger(logger logr.Logger) { | ||
log = logger | ||
} | ||
|
||
func GetLogger() logr.Logger { | ||
return log | ||
} |
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,34 @@ | ||
// Copyright 2023 VMware, Inc. | ||
// | ||
// This product is licensed to you under the BSD-2 license (the "License"). | ||
// You may not use this product except in compliance with the BSD-2 License. | ||
// This product may include a number of subcomponents with separate copyright | ||
// notices and license terms. Your use of these subcomponents is subject to | ||
// the terms and conditions of the subcomponent's license, as noted in the | ||
// LICENSE file. | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
|
||
package metadata | ||
|
||
import ( | ||
stdlog "log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/go-logr/stdr" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSetLogger(t *testing.T) { | ||
// This function is just a simple setter, no need for testing table | ||
testLogger := stdr.New(stdlog.New(os.Stdout, "test", stdlog.LstdFlags)) | ||
SetLogger(testLogger) | ||
assert.Equal(t, testLogger, log, "setting package global logger was unsuccessful") | ||
} | ||
|
||
func TestGetLogger(t *testing.T) { | ||
// This function is just a simple getter, no need for testing table | ||
testLogger := GetLogger() | ||
assert.Equal(t, log, testLogger, "function did not return current logger") | ||
} |
Oops, something went wrong.