This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create helper for logs and add documentation
Signed-off-by: Luis Enriquez <[email protected]>
- Loading branch information
Showing
31 changed files
with
3,201 additions
and
170 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package service | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/hashicorp/go-hclog" | ||
) | ||
|
||
type GranularityLevel string | ||
|
||
const ( | ||
Trace GranularityLevel = "[TRACE] " | ||
Debug GranularityLevel = "[DEBUG] " | ||
Info GranularityLevel = "[INFO] " | ||
Warn GranularityLevel = "[WARN] " | ||
Error GranularityLevel = "[ERROR] " | ||
) | ||
|
||
// Since go-plugin handle logs as is described on https://github.com/hashicorp/go-plugin#features under (Built-in Logging) | ||
// is necessary to send the logs as JSON format or with a prefix as is show here | ||
// https://github.com/hashicorp/go-plugin/blob/master/client.go#L1007 | ||
|
||
// NewLoggerHelper Create a Logger with JSON format allowing user to have a more granular support for example | ||
// NewLoggerHelper().Info("octant-sample-plugin is starting") | ||
func NewLoggerHelper() hclog.Logger { | ||
return hclog.New(&hclog.LoggerOptions{ | ||
Output: os.Stderr, | ||
JSONFormat: true, | ||
}) | ||
} | ||
|
||
// SetupPluginLogger Set prefix so go-plugin recognize the level of granularity and applied to the host process | ||
// Unfortunately logs go through hclog and the through Zap, for this reason it looks like this | ||
// "2021-08-23T11:35:02.714-0500 INFO octant-sample-plugin plugin/logger.go:43 [INFO] 2021/08/23 11:35:02 ..." | ||
func SetupPluginLogger(g GranularityLevel) { | ||
log.SetPrefix(string(g)) | ||
} |
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,26 @@ | ||
package service | ||
|
||
import ( | ||
"log" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewLoggerHelper(t *testing.T) { | ||
logger := NewLoggerHelper() | ||
assert.NotNil(t, logger) | ||
} | ||
|
||
func TestSetupPluginLogger(t *testing.T) { | ||
SetupPluginLogger(Trace) | ||
assert.Equal(t, log.Prefix(), string(Trace)) | ||
SetupPluginLogger(Debug) | ||
assert.Equal(t, log.Prefix(), string(Debug)) | ||
SetupPluginLogger(Info) | ||
assert.Equal(t, log.Prefix(), string(Info)) | ||
SetupPluginLogger(Warn) | ||
assert.Equal(t, log.Prefix(), string(Warn)) | ||
SetupPluginLogger(Error) | ||
assert.Equal(t, log.Prefix(), string(Error)) | ||
} |
200 changes: 200 additions & 0 deletions
200
vendor/github.com/golang/protobuf/protoc-gen-go/descriptor/descriptor.pb.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.